mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15:28:30 +00:00
Clean up more code
- Found some bugs in LLVM compiler-rt library - The useless LIBC_STUBS package is now deleted - Improve the overflow checking story even further - Get chibicc tests working in MODE=dbg mode again - The libc/isystem/ headers now have correctly named guards
This commit is contained in:
parent
afc58a8b41
commit
d7c79f43ef
294 changed files with 912 additions and 1208 deletions
|
@ -20,7 +20,6 @@ TOOL_ARGS_A_DIRECTDEPS = \
|
|||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/elf/elf.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
@ -247,8 +248,9 @@ int main(int argc, char *argv[]) {
|
|||
CHECK_NE(MAP_FAILED,
|
||||
(elf = mmap(0, st->st_size, PROT_READ, MAP_PRIVATE, fd, 0)));
|
||||
CHECK(IsElf64Binary(elf, st->st_size), "%s", arg);
|
||||
CHECK_NOTNULL((strs = GetElfStringTable(elf, st->st_size)));
|
||||
CHECK_NOTNULL((syms = GetElfSymbolTable(elf, st->st_size, &symcount)));
|
||||
CHECK_NOTNULL((strs = GetElfStringTable(elf, st->st_size, ".strtab")));
|
||||
CHECK_NOTNULL(
|
||||
(syms = GetElfSymbolTable(elf, st->st_size, SHT_SYMTAB, &symcount)));
|
||||
for (j = 0; j < symcount; ++j) {
|
||||
if (syms[j].st_shndx == SHN_UNDEF) continue;
|
||||
if (syms[j].st_other == STV_INTERNAL) continue;
|
||||
|
|
|
@ -53,7 +53,6 @@ TOOL_BUILD_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_THREAD \
|
||||
|
|
|
@ -350,13 +350,13 @@ static void FixupObject(void) {
|
|||
if (!IsElf64Binary(elf, esize)) {
|
||||
Die("not an elf64 binary");
|
||||
}
|
||||
if (!(syms = GetElfSymbolTable(elf, esize, &symcount))) {
|
||||
if (!(syms = GetElfSymbolTable(elf, esize, SHT_SYMTAB, &symcount))) {
|
||||
Die("missing elf symbol table");
|
||||
}
|
||||
if (!(secstrs = GetElfSectionNameStringTable(elf, esize))) {
|
||||
Die("missing elf section string table");
|
||||
}
|
||||
if (!(symstrs = GetElfStringTable(elf, esize))) {
|
||||
if (!(symstrs = GetElfStringTable(elf, esize, ".strtab"))) {
|
||||
Die("missing elf symbol string table");
|
||||
}
|
||||
CheckPrivilegedCrossReferences();
|
||||
|
|
|
@ -16,16 +16,15 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/buffer.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/tpenc.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/arraylist2.internal.h"
|
||||
#include "libc/mem/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/build/lib/buffer.h"
|
||||
|
||||
/* TODO(jart): replace with new append*() library */
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ TOOL_BUILD_LIB_A_OBJS = \
|
|||
|
||||
TOOL_BUILD_LIB_A_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_ELF \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
|
@ -43,7 +42,6 @@ TOOL_BUILD_LIB_A_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
|
@ -109,6 +107,8 @@ TOOL_BUILD_LIB_CHECKS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_CHECKS))
|
|||
TOOL_BUILD_LIB_OBJS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_OBJS))
|
||||
TOOL_BUILD_LIB_TESTS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_TESTS))
|
||||
|
||||
$(TOOL_BUILD_LIB_OBJS): tool/build/lib/buildlib.mk
|
||||
|
||||
.PHONY: o/$(MODE)/tool/build/lib
|
||||
o/$(MODE)/tool/build/lib: \
|
||||
$(TOOL_BUILD_LIB_COMS) \
|
||||
|
|
|
@ -526,10 +526,11 @@ static void OpenObject(struct Package *pkg, struct Object *obj, int oid) {
|
|||
if (!IsElf64Binary(obj->elf, obj->size)) {
|
||||
Die(path, "not an elf64 binary");
|
||||
}
|
||||
if (!(obj->strs = GetElfStringTable(obj->elf, obj->size))) {
|
||||
if (!(obj->strs = GetElfStringTable(obj->elf, obj->size, ".strtab"))) {
|
||||
Die(path, "missing elf string table");
|
||||
}
|
||||
if (!(obj->syms = GetElfSymbolTable(obj->elf, obj->size, &obj->symcount))) {
|
||||
if (!(obj->syms = GetElfSymbolTable(obj->elf, obj->size, SHT_SYMTAB,
|
||||
&obj->symcount))) {
|
||||
Die(path, "missing elf symbol table");
|
||||
}
|
||||
IndexSections(pkg, obj);
|
||||
|
|
|
@ -24,7 +24,6 @@ TOOL_CURL_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_TIME \
|
||||
LIBC_X \
|
||||
|
|
|
@ -31,7 +31,6 @@ TOOL_DECODE_DIRECTDEPS = \
|
|||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
|
|
|
@ -104,9 +104,9 @@ static void printelfehdr(void) {
|
|||
}
|
||||
|
||||
static void printelfsegmentheader(int i) {
|
||||
Elf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, i);
|
||||
Elf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, i);
|
||||
if (!phdr) return;
|
||||
printf("/\tElf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, "
|
||||
printf("/\tElf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, "
|
||||
"%d)\n",
|
||||
i);
|
||||
printf(".Lph%d:", i);
|
||||
|
@ -272,9 +272,10 @@ static void printelfsymbol(Elf64_Sym *sym, char *strtab, char *shstrtab) {
|
|||
|
||||
static void printelfsymboltable(void) {
|
||||
size_t i, symcount = 0;
|
||||
Elf64_Sym *symtab = GetElfSymbolTable(elf, st->st_size, &symcount);
|
||||
Elf64_Sym *symtab =
|
||||
GetElfSymbolTable(elf, st->st_size, SHT_SYMTAB, &symcount);
|
||||
if (!symtab) return;
|
||||
char *strtab = GetElfStringTable(elf, st->st_size);
|
||||
char *strtab = GetElfStringTable(elf, st->st_size, ".strtab");
|
||||
char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
|
||||
printf("\n\n");
|
||||
printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf);
|
||||
|
@ -288,9 +289,10 @@ static void printelfsymboltable(void) {
|
|||
|
||||
static void printelfdynsymboltable(void) {
|
||||
size_t i, symcount = 0;
|
||||
Elf64_Sym *symtab = GetElfDynSymbolTable(elf, st->st_size, &symcount);
|
||||
Elf64_Sym *symtab =
|
||||
GetElfSymbolTable(elf, st->st_size, SHT_DYNSYM, &symcount);
|
||||
if (!symtab) return;
|
||||
char *strtab = GetElfDynStringTable(elf, st->st_size);
|
||||
char *strtab = GetElfStringTable(elf, st->st_size, ".dynstr");
|
||||
char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
|
||||
printf("\n\n");
|
||||
printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf);
|
||||
|
@ -326,7 +328,7 @@ static void printelfrelocations(void) {
|
|||
const Elf64_Rela *rela;
|
||||
char *strtab, *shstrtab, *symbolname;
|
||||
const Elf64_Shdr *shdr, *shdr2, *symtab;
|
||||
strtab = GetElfStringTable(elf, st->st_size);
|
||||
strtab = GetElfStringTable(elf, st->st_size, ".strtab");
|
||||
shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
|
||||
for (i = 0; i < elf->e_shnum; ++i) {
|
||||
if ((shdr = GetElfSectionHeaderAddress(elf, st->st_size, i)) &&
|
||||
|
|
|
@ -28,7 +28,6 @@ TOOL_DECODE_LIB_A_DIRECTDEPS = \
|
|||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV
|
||||
|
||||
TOOL_DECODE_LIB_A_DEPS := \
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/*-*- 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 2020 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/fmt/conv.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* @fileoverview CRC Lookup Table Generator
|
||||
* @see http://reveng.sourceforge.net/crc-catalogue/17plus.htm
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s POLYNOMIAL\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
static uint32_t tab[256];
|
||||
crc32init(tab, strtol(argv[1], NULL, 0));
|
||||
for (unsigned i = 0; i < ARRAYLEN(tab); ++i) {
|
||||
if (i > 0) {
|
||||
printf(",");
|
||||
if (i % 6 == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("0x%08x", tab[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
PKGS += TOOL_HASH
|
||||
|
||||
TOOL_HASH_SRCS := $(wildcard tool/hash/*.c)
|
||||
|
||||
TOOL_HASH_OBJS = \
|
||||
$(TOOL_HASH_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
TOOL_HASH_COMS = \
|
||||
$(TOOL_HASH_SRCS:%.c=o/$(MODE)/%.com)
|
||||
|
||||
TOOL_HASH_BINS = \
|
||||
$(TOOL_HASH_COMS) \
|
||||
$(TOOL_HASH_COMS:%=%.dbg)
|
||||
|
||||
TOOL_HASH_DIRECTDEPS = \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_MEM \
|
||||
LIBC_STUBS
|
||||
|
||||
TOOL_HASH_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_HASH_DIRECTDEPS),$($(x))))
|
||||
|
||||
o/$(MODE)/tool/hash/hash.pkg: \
|
||||
$(TOOL_HASH_OBJS) \
|
||||
$(foreach x,$(TOOL_HASH_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/tool/hash/%.com.dbg: \
|
||||
$(TOOL_HASH_DEPS) \
|
||||
o/$(MODE)/tool/hash/%.o \
|
||||
o/$(MODE)/tool/hash/hash.pkg \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TOOL_HASH_OBJS): \
|
||||
$(BUILD_FILES) \
|
||||
tool/hash/hash.mk
|
||||
|
||||
.PHONY: o/$(MODE)/tool/hash
|
||||
o/$(MODE)/tool/hash: $(TOOL_HASH_BINS) $(TOOL_HASH_CHECKS)
|
|
@ -14,8 +14,7 @@ TOOL_HELLO_DIRECTDEPS = \
|
|||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_STUBS
|
||||
LIBC_SYSV
|
||||
|
||||
TOOL_HELLO_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_HELLO_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -16,20 +16,19 @@ TOOL_LAMBDA_BINS = \
|
|||
$(TOOL_LAMBDA_COMS:%=%.dbg)
|
||||
|
||||
TOOL_LAMBDA_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_CALLS \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_FMT \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_STDIO \
|
||||
LIBC_X \
|
||||
LIBC_STUBS \
|
||||
LIBC_NEXGEN32E \
|
||||
TOOL_LAMBDA_LIB \
|
||||
THIRD_PARTY_GETOPT
|
||||
THIRD_PARTY_GETOPT \
|
||||
TOOL_LAMBDA_LIB
|
||||
|
||||
TOOL_LAMBDA_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_LAMBDA_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -25,16 +25,15 @@ TOOL_LAMBDA_LIB_A_OBJS = \
|
|||
|
||||
TOOL_LAMBDA_LIB_A_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_MEM \
|
||||
LIBC_FMT \
|
||||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_GETOPT
|
||||
|
|
|
@ -42,7 +42,6 @@ TOOL_NET_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
|
|
|
@ -36,7 +36,6 @@ TOOL_PLINKO_LIB_A_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
|
|
|
@ -26,7 +26,6 @@ TOOL_PLINKO_DIRECTDEPS = \
|
|||
LIBC_SYSV \
|
||||
LIBC_STDIO \
|
||||
LIBC_X \
|
||||
LIBC_STUBS \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_ZIPOS \
|
||||
TOOL_PLINKO_LIB
|
||||
|
|
|
@ -102,11 +102,13 @@ fi
|
|||
|
||||
# auto-install some shell libraries
|
||||
if [ ! -d "$COSMOS/lib" ]; then
|
||||
mkdir "$COSMOS/lib"
|
||||
for lib in c dl gcc_s m pthread resolv rt z stdc++; do
|
||||
printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a"
|
||||
done
|
||||
mkdir -p "$COSMOS/lib"
|
||||
fi
|
||||
for lib in c dl gcc_s m pthread resolv rt dl z stdc++; do
|
||||
if [ ! -f "$COSMOS/lib/lib$lib.a" ]; then
|
||||
printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a"
|
||||
fi
|
||||
done
|
||||
|
||||
OPT=
|
||||
FIRST=1
|
||||
|
|
|
@ -102,11 +102,13 @@ fi
|
|||
|
||||
# auto-install some shell libraries
|
||||
if [ ! -d "$COSMOS/lib" ]; then
|
||||
mkdir "$COSMOS/lib"
|
||||
for lib in c dl gcc_s m pthread resolv rt z stdc++; do
|
||||
printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a"
|
||||
done
|
||||
mkdir -p "$COSMOS/lib"
|
||||
fi
|
||||
for lib in c dl gcc_s m pthread resolv rt dl z stdc++; do
|
||||
if [ ! -f "$COSMOS/lib/lib$lib.a" ]; then
|
||||
printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a"
|
||||
fi
|
||||
done
|
||||
|
||||
OPT=
|
||||
FIRST=1
|
||||
|
|
|
@ -7,7 +7,6 @@ o/$(MODE)/tool: \
|
|||
o/$(MODE)/tool/build \
|
||||
o/$(MODE)/tool/curl \
|
||||
o/$(MODE)/tool/decode \
|
||||
o/$(MODE)/tool/hash \
|
||||
o/$(MODE)/tool/hello \
|
||||
o/$(MODE)/tool/lambda \
|
||||
o/$(MODE)/tool/net \
|
||||
|
|
|
@ -36,7 +36,6 @@ TOOL_VIZ_LIB_A_DIRECTDEPS = \
|
|||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_TIME \
|
||||
|
|
|
@ -35,7 +35,6 @@ TOOL_VIZ_DIRECTDEPS = \
|
|||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue