mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Fix bugs in cosmocc toolchain
This change integrates e58abc1110b335a3341e8ad5821ad8e3880d9bb2 from https://github.com/ahgamut/musl-cross-make/ which fixes the issues we were having with our C language extension for symbolic constants. This change also performs some code cleanup and bug fixes to getaddrinfo(). It's now possible to compile projects like ncurses, readline and python without needing to patch anything upstream, except maybe a line or two. Pretty soon it should be possible to build a Linux distro on Cosmo.
This commit is contained in:
parent
22f81a8d50
commit
23e235b7a5
272 changed files with 3491 additions and 4350 deletions
|
@ -383,7 +383,7 @@ static int GetXmmTypeCellCount(int r) {
|
|||
case kXmmDouble:
|
||||
return 2;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -849,7 +849,7 @@ static int GetRegHexWidth(void) {
|
|||
return 4;
|
||||
}
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -866,7 +866,7 @@ static int GetAddrHexWidth(void) {
|
|||
return 6;
|
||||
}
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ static void DrawXmm(struct Panel *p, long i, long r) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
buf[cellwidth] = '\0';
|
||||
AppendPanel(p, i, buf);
|
||||
|
@ -1532,7 +1532,7 @@ static int GetPreferredStackAlignmentMask(void) {
|
|||
case XED_MODE_REAL:
|
||||
return 3;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1961,7 +1961,7 @@ static int OnPtyFdPoll(struct pollfd *fds, size_t nfds, int ms) {
|
|||
++t;
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
* strace -vff bash -c '_PLEDGE=4194303,0 LD_PRELOAD=$HOME/sandbox.so ls'
|
||||
*/
|
||||
|
||||
_Hide uint8_t __privileged_start[1];
|
||||
_Hide uint8_t __privileged_end[1];
|
||||
|
||||
__attribute__((__constructor__)) void init(void) {
|
||||
int c, i, j;
|
||||
const char *s;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/xed/x86.h"
|
||||
#include "tool/build/lib/address.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
@ -44,7 +44,7 @@ uint8_t *GetSegment(struct Machine *m, uint32_t rde, int s) {
|
|||
case 7:
|
||||
OpUd(m, rde);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ uint64_t AddressSi(struct Machine *m, uint32_t rde) {
|
|||
case XED_MODE_LEGACY:
|
||||
return DataSegment(m, rde, Read32(m->si));
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,6 @@ uint64_t AddressDi(struct Machine *m, uint32_t rde) {
|
|||
case XED_MODE_LEGACY:
|
||||
return i + Read32(m->di);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ struct Asmdown *ParseAsmdown(const char *code, size_t size) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
return ad;
|
||||
|
|
|
@ -280,7 +280,7 @@ static char *DisBis(struct Dis *d, uint32_t rde, char *p) {
|
|||
base = "bx";
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
if (base || index) {
|
||||
|
|
|
@ -862,7 +862,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
|
|||
case 3:
|
||||
return "movsldup %Vq Wq";
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
break;
|
||||
case 0x13:
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
#include "tool/build/lib/address.h"
|
||||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/machine.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ struct AddrSeg LoadEffectiveAddress(const struct Machine *m, uint32_t rde) {
|
|||
i += Read16(m->bx);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
i &= 0xffff;
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
if (x > p[i].right) {
|
||||
break;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/pty.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include "libc/str/unicode.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "tool/build/lib/pty.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Pseudoteletypewriter
|
||||
|
@ -1158,7 +1158,7 @@ ssize_t PtyWrite(struct Pty *pty, const void *data, size_t n) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/ssemov.h"
|
||||
#include "libc/intrin/pmovmskb.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/build/lib/address.h"
|
||||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/ssemov.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
static void MovdquVdqWdq(struct Machine *m, uint32_t rde) {
|
||||
|
@ -314,7 +314,7 @@ void OpMovWpsVps(struct Machine *m, uint32_t rde) {
|
|||
MovssWpsVps(m, rde);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ void OpMov0f10(struct Machine *m, uint32_t rde) {
|
|||
MovssVpsWps(m, rde);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ void OpMov0f12(struct Machine *m, uint32_t rde) {
|
|||
MovsldupVqWq(m, rde);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/stack.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/stack.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
static const uint8_t kStackOsz[2][3] = {
|
||||
|
@ -76,7 +76,7 @@ static void PushN(struct Machine *m, uint32_t rde, uint64_t x, unsigned osz) {
|
|||
Write64(m->sp, v);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
WriteStackWord(AccessRam(m, v, osz, p, b, false), rde, osz, x);
|
||||
EndStore(m, v, osz, p, b);
|
||||
|
@ -113,7 +113,7 @@ static uint64_t PopN(struct Machine *m, uint32_t rde, uint16_t extra,
|
|||
v += Read64(m->ss);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
return ReadStackWord(AccessRam(m, v, osz, p, b, true), osz);
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ void OpPopZvq(struct Machine *m, uint32_t rde) {
|
|||
Write16(RegRexbSrm(m, rde), x);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ void OpLeave(struct Machine *m, uint32_t rde) {
|
|||
Write16(m->bp, Pop(m, rde, 0));
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ relegated void OpPusha(struct Machine *m, uint32_t rde) {
|
|||
case XED_MODE_LONG:
|
||||
OpUd(m, rde);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ relegated void OpPopa(struct Machine *m, uint32_t rde) {
|
|||
case XED_MODE_LONG:
|
||||
OpUd(m, rde);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/string.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
@ -29,7 +30,6 @@
|
|||
#include "tool/build/lib/machine.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/string.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
static uint64_t ReadInt(uint8_t p[8], unsigned long w) {
|
||||
|
@ -43,7 +43,7 @@ static uint64_t ReadInt(uint8_t p[8], unsigned long w) {
|
|||
case 3:
|
||||
return Read64(p);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ static void WriteInt(uint8_t p[8], uint64_t x, unsigned long w) {
|
|||
Write64(p, x);
|
||||
break;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ static void AddDi(struct Machine *m, uint32_t rde, uint64_t x) {
|
|||
Write16(m->di, Read16(m->di) + x);
|
||||
return;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ static void AddSi(struct Machine *m, uint32_t rde, uint64_t x) {
|
|||
Write16(m->si, Read16(m->si) + x);
|
||||
return;
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ static uint64_t ReadCx(struct Machine *m, uint32_t rde) {
|
|||
case XED_MODE_REAL:
|
||||
return Read16(m->cx);
|
||||
default:
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,14 +128,14 @@ wontreturn void ShowUsage(FILE *f, int rc) {
|
|||
fprintf(f, "Usage: %s RUNITD PROGRAM HOSTNAME[:RUNITDPORT[:SSHPORT]]...\n",
|
||||
program_invocation_name);
|
||||
exit(rc);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void CheckExists(const char *path) {
|
||||
if (!isregularfile(path)) {
|
||||
fprintf(stderr, "error: %s: not found or irregular\n", path);
|
||||
ShowUsage(stderr, EX_USAGE);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,14 +147,14 @@ void Connect(void) {
|
|||
if ((rc = getaddrinfo(g_hostname, _gc(xasprintf("%hu", g_runitdport)),
|
||||
&kResolvHints, &ai)) != 0) {
|
||||
FATALF("%s:%hu: EAI_%s %m", g_hostname, g_runitdport, gai_strerror(rc));
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
ip4 = (const char *)&ai->ai_addr4->sin_addr;
|
||||
if (ispublicip(ai->ai_family, &ai->ai_addr4->sin_addr)) {
|
||||
FATALF("%s points to %hhu.%hhu.%hhu.%hhu"
|
||||
" which isn't part of a local/private/testing subnet",
|
||||
g_hostname, ip4[0], ip4[1], ip4[2], ip4[3]);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
DEBUGF("connecting to %d.%d.%d.%d port %d", ip4[0], ip4[1], ip4[2], ip4[3],
|
||||
ntohs(ai->ai_addr4->sin_port));
|
||||
|
@ -180,7 +180,7 @@ TryAgain:
|
|||
if (t2 > t1 + MAX_WAIT_CONNECT_SECONDS) {
|
||||
FATALF("timeout connecting to %s (%hhu.%hhu.%hhu.%hhu:%d)", g_hostname,
|
||||
ip4[0], ip4[1], ip4[2], ip4[3], ntohs(ai->ai_addr4->sin_port));
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
goto TryAgain;
|
||||
}
|
||||
|
@ -463,11 +463,11 @@ int main(int argc, char *argv[]) {
|
|||
if (argc > 1 &&
|
||||
(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
|
||||
ShowUsage(stdout, 0);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
if (argc < 3) {
|
||||
ShowUsage(stderr, EX_USAGE);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
CheckExists((g_runitd = argv[1]));
|
||||
CheckExists((g_prog = argv[2]));
|
||||
|
|
|
@ -184,10 +184,10 @@ void GetOpts(int argc, char *argv[]) {
|
|||
break;
|
||||
case 'h':
|
||||
ShowUsage(stdout, EXIT_SUCCESS);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
default:
|
||||
ShowUsage(stderr, EX_USAGE);
|
||||
unreachable;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1200
tool/build/strace.c
1200
tool/build/strace.c
File diff suppressed because it is too large
Load diff
|
@ -42,6 +42,7 @@ int main(int argc, char *argv[]) {
|
|||
uint8_t *m;
|
||||
CHECK_NE(MAP_FAILED, (m = mmap(0, n, PROT_READ, MAP_PRIVATE, fd, 0)));
|
||||
|
||||
int err;
|
||||
uint8_t *b, *d, *p;
|
||||
if ((p = FindEmbeddedApe(m, n))) {
|
||||
b = p;
|
||||
|
@ -49,8 +50,9 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
b = m;
|
||||
}
|
||||
if (!(d = GetZipCdir(b, n))) {
|
||||
fprintf(stderr, "%s: couldn't locate central directory\n", argv[1]);
|
||||
if (!(d = GetZipEocd(b, n, &err))) {
|
||||
fprintf(stderr, "%s: couldn't locate central directory [zip error %d]\n",
|
||||
argv[1], err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -58,8 +60,8 @@ int main(int argc, char *argv[]) {
|
|||
uint8_t *zmap = m;
|
||||
uint8_t *zbase = b;
|
||||
uint8_t *zcdir = d;
|
||||
DCHECK(IsZipCdir32(zbase, zsize, zcdir - zbase) ||
|
||||
IsZipCdir64(zbase, zsize, zcdir - zbase));
|
||||
DCHECK(IsZipEocd32(zbase, zsize, zcdir - zbase) == kZipOk ||
|
||||
IsZipEocd64(zbase, zsize, zcdir - zbase) == kZipOk);
|
||||
|
||||
uint64_t cf;
|
||||
uint64_t lf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue