mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-22 10:30:29 +00:00
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:
parent
f6407d5f7c
commit
8ff48201ca
125 changed files with 1056 additions and 928 deletions
|
@ -41,6 +41,7 @@
|
|||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
|
@ -594,8 +595,7 @@ bool __asan_is_valid_strlist(char *const *p) {
|
|||
bool __asan_is_valid_iov(const struct iovec *iov, int iovlen) {
|
||||
int i;
|
||||
size_t size;
|
||||
if (iovlen >= 0 &&
|
||||
!__builtin_mul_overflow(iovlen, sizeof(struct iovec), &size) &&
|
||||
if (iovlen >= 0 && !ckd_mul(&size, iovlen, sizeof(struct iovec)) &&
|
||||
__asan_is_valid(iov, size)) {
|
||||
for (i = 0; i < iovlen; ++i) {
|
||||
if (!__asan_is_valid(iov[i].iov_base, iov[i].iov_len)) {
|
||||
|
@ -1067,7 +1067,7 @@ static struct AsanExtra *__asan_get_extra(const void *p, size_t *c) {
|
|||
struct AsanExtra *e;
|
||||
f = (intptr_t)p >> 16;
|
||||
if (!kisdangerous(p) && (n = _weaken(dlmalloc_usable_size)(p)) > sizeof(*e) &&
|
||||
!__builtin_add_overflow((intptr_t)p, n, &x) && x <= 0x800000000000 &&
|
||||
!ckd_add(&x, (intptr_t)p, n) && x <= 0x800000000000 &&
|
||||
(LIKELY(f == (int)((x - 1) >> 16)) || !kisdangerous((void *)(x - 1))) &&
|
||||
(LIKELY(f == (int)((x = x - sizeof(*e)) >> 16)) ||
|
||||
__asan_is_mapped(x >> 16)) &&
|
||||
|
@ -1237,7 +1237,7 @@ void *__asan_calloc(size_t n, size_t m) {
|
|||
char *p;
|
||||
struct AsanTrace bt;
|
||||
__asan_trace(&bt, RBP);
|
||||
if (__builtin_mul_overflow(n, m, &n)) n = -1;
|
||||
if (ckd_mul(&n, n, m)) n = -1;
|
||||
return __asan_allocate(16, n, &bt, kAsanHeapUnderrun, kAsanHeapOverrun, 0x00);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
|
||||
/**
|
||||
* Returns -𝑥, aborting on overflow.
|
||||
|
@ -66,7 +67,7 @@ int128_t __negvti2(int128_t x) {
|
|||
*/
|
||||
int __addvsi3(int x, int y) {
|
||||
int z;
|
||||
if (__builtin_add_overflow(x, y, &z)) {
|
||||
if (ckd_add(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -80,7 +81,7 @@ int __addvsi3(int x, int y) {
|
|||
*/
|
||||
long __addvdi3(long x, long y) {
|
||||
long z;
|
||||
if (__builtin_add_overflow(x, y, &z)) {
|
||||
if (ckd_add(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -94,7 +95,7 @@ long __addvdi3(long x, long y) {
|
|||
*/
|
||||
int128_t __addvti3(int128_t x, int128_t y) {
|
||||
int128_t z;
|
||||
if (__builtin_add_overflow(x, y, &z)) {
|
||||
if (ckd_add(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -108,7 +109,7 @@ int128_t __addvti3(int128_t x, int128_t y) {
|
|||
*/
|
||||
int __subvsi3(int x, int y) {
|
||||
int z;
|
||||
if (__builtin_sub_overflow(x, y, &z)) {
|
||||
if (ckd_sub(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -122,7 +123,7 @@ int __subvsi3(int x, int y) {
|
|||
*/
|
||||
long __subvdi3(long x, long y) {
|
||||
long z;
|
||||
if (__builtin_sub_overflow(x, y, &z)) {
|
||||
if (ckd_sub(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -136,7 +137,7 @@ long __subvdi3(long x, long y) {
|
|||
*/
|
||||
int128_t __subvti3(int128_t x, int128_t y) {
|
||||
int128_t z;
|
||||
if (__builtin_sub_overflow(x, y, &z)) {
|
||||
if (ckd_sub(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -150,7 +151,7 @@ int128_t __subvti3(int128_t x, int128_t y) {
|
|||
*/
|
||||
int __mulvsi3(int x, int y) {
|
||||
int z;
|
||||
if (__builtin_mul_overflow(x, y, &z)) {
|
||||
if (ckd_mul(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -164,7 +165,7 @@ int __mulvsi3(int x, int y) {
|
|||
*/
|
||||
long __mulvdi3(long x, long y) {
|
||||
long z;
|
||||
if (__builtin_mul_overflow(x, y, &z)) {
|
||||
if (ckd_mul(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
@ -178,7 +179,7 @@ long __mulvdi3(long x, long y) {
|
|||
*/
|
||||
int128_t __mulvti3(int128_t x, int128_t y) {
|
||||
int128_t z;
|
||||
if (__builtin_mul_overflow(x, y, &z)) {
|
||||
if (ckd_mul(&z, x, y)) {
|
||||
__on_arithmetic_overflow();
|
||||
}
|
||||
return z;
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
#include "libc/str/utf16.h"
|
||||
|
@ -108,7 +109,7 @@ extern _Hide struct SymbolTable *__symtab;
|
|||
|
||||
privileged static inline char *kadvance(char *p, char *e, long n) {
|
||||
intptr_t t = (intptr_t)p;
|
||||
if (__builtin_add_overflow(t, n, &t)) t = (intptr_t)e;
|
||||
if (ckd_add(&t, t, n)) t = (intptr_t)e;
|
||||
return (char *)t;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,8 @@ noasan static inline const unsigned char *memchr_sse(const unsigned char *s,
|
|||
void *memchr(const void *s, int c, size_t n) {
|
||||
#ifdef __x86_64__
|
||||
const void *r;
|
||||
if (!IsTiny() && X86_HAVE(SSE)) {
|
||||
if (IsAsan()) __asan_verify(s, n);
|
||||
r = memchr_sse(s, c, n);
|
||||
} else {
|
||||
r = memchr_pure(s, c, n);
|
||||
}
|
||||
if (IsAsan()) __asan_verify(s, n);
|
||||
r = memchr_sse(s, c, n);
|
||||
return (void *)r;
|
||||
#else
|
||||
return memchr_pure(s, c, n);
|
||||
|
|
|
@ -71,12 +71,8 @@ noasan static inline const unsigned char *memrchr_sse(const unsigned char *s,
|
|||
void *memrchr(const void *s, int c, size_t n) {
|
||||
#ifdef __x86_64__
|
||||
const void *r;
|
||||
if (!IsTiny() && X86_HAVE(SSE)) {
|
||||
if (IsAsan()) __asan_verify(s, n);
|
||||
r = memrchr_sse(s, c, n);
|
||||
} else {
|
||||
r = memrchr_pure(s, c, n);
|
||||
}
|
||||
if (IsAsan()) __asan_verify(s, n);
|
||||
r = memrchr_sse(s, c, n);
|
||||
return (void *)r;
|
||||
#else
|
||||
return memrchr_pure(s, c, n);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue