Rewrite .zip.o file linker

This change takes an entirely new approach to the incremental linking of
pkzip executables. The assets created by zipobj.com are now treated like
debug data. After a .com.dbg is compiled, fixupobj.com should be run, so
it can apply fixups to the offsets and move the zip directory to the end
of the file. Since debug data doesn't get objcopy'd, a new tool has been
introduced called zipcopy.com which should be run after objcopy whenever
a .com file is created. This is all automated by the `cosmocc` toolchain
which is rapidly becoming the new recommended approach.

This change also introduces the new C23 checked arithmetic macros.
This commit is contained in:
Justine Tunney 2023-06-10 09:15:19 -07:00
parent f6407d5f7c
commit 8ff48201ca
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
125 changed files with 1056 additions and 928 deletions

View file

@ -20,6 +20,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"
#include "libc/stdckdint.h"
void djbsort_avx2(int32_t *, long);
@ -29,7 +30,7 @@ void djbsort_avx2(int32_t *, long);
void djbsort(int32_t *a, size_t n) {
size_t m;
if (IsAsan()) {
if (__builtin_mul_overflow(n, 4, &m)) m = -1;
if (ckd_mul(&m, n, 4)) m = -1;
__asan_verify(a, m);
}
if (n > 1) {

View file

@ -32,16 +32,18 @@ typedef long long v2di __attribute__((__vector_size__(16), __aligned__(1)));
* caller needs to check the first four bytes of the returned value to
* determine whether to use ZIP_CDIR_xxx() or ZIP_CDIR64_xxx() macros.
*
* @param p points to file memory
* @param f points to file memory
* @param n is byte size of file
* @param e may receive error code when null is returned
* @return pointer to EOCD64 or EOCD, otherwise null
*/
void *GetZipEocd(const uint8_t *p, size_t n, int *e) {
void *GetZipEocd(const void *f, size_t n, int *e) {
v2di x;
int err;
size_t i, j;
uint32_t magic;
const uint8_t *p;
p = f;
i = n - 4;
err = kZipErrorEocdNotFound;
do {

View file

@ -16,10 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdckdint.h"
#include "libc/str/str.h"
wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) {
size_t bytes;
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1;
return memcpy(dest, src, bytes);
}

View file

@ -16,10 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdckdint.h"
#include "libc/str/str.h"
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count) {
size_t bytes;
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1;
return memmove(dest, src, bytes);
}

View file

@ -16,10 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdckdint.h"
#include "libc/str/str.h"
wchar_t *wmempcpy(wchar_t *dest, const wchar_t *src, size_t count) {
size_t bytes;
if (__builtin_mul_overflow(count, sizeof(wchar_t), &bytes)) bytes = -1;
if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1;
return mempcpy(dest, src, bytes);
}

View file

@ -19,6 +19,7 @@
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
typedef wchar_t xmm_t __attribute__((__vector_size__(16), __aligned__(4)));
@ -70,15 +71,11 @@ void *wmemrchr(const wchar_t *s, wchar_t c, size_t n) {
#ifdef __x86_64__
size_t bytes;
const void *r;
if (!IsTiny() && X86_HAVE(SSE)) {
if (IsAsan()) {
if (__builtin_mul_overflow(n, sizeof(wchar_t), &bytes)) bytes = -1;
__asan_verify(s, bytes);
}
r = wmemrchr_sse(s, c, n);
} else {
r = wmemrchr_pure(s, c, n);
if (IsAsan()) {
if (ckd_mul(&bytes, n, sizeof(wchar_t))) bytes = -1;
__asan_verify(s, bytes);
}
r = wmemrchr_sse(s, c, n);
return (void *)r;
#else
return wmemrchr_pure(s, c, n);