mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Make minor improvements
This commit is contained in:
parent
04caf6f9ad
commit
95b142e4e5
95 changed files with 3818 additions and 2760 deletions
|
@ -48,7 +48,6 @@ TOOL_BUILD_DIRECTDEPS = \
|
|||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
|
|
|
@ -190,7 +190,10 @@ void elfwriter_close(struct ElfWriter *elf) {
|
|||
freeinterner(elf->strtab);
|
||||
free(elf->shdrs->p);
|
||||
free(elf->relas->p);
|
||||
for (i = 0; i < ARRAYLEN(elf->syms); ++i) free(elf->syms[i]->p);
|
||||
free(elf->path);
|
||||
for (i = 0; i < ARRAYLEN(elf->syms); ++i) {
|
||||
free(elf->syms[i]->p);
|
||||
}
|
||||
free(elf);
|
||||
}
|
||||
|
||||
|
@ -237,6 +240,14 @@ void elfwriter_finishsection(struct ElfWriter *elf) {
|
|||
if (elf->relas->j < elf->relas->i) MakeRelaSection(elf, section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends symbol.
|
||||
*
|
||||
* This function should be called between elfwriter_startsection() and
|
||||
* elfwriter_finishsection(). If that's not possible, then this can be
|
||||
* called after elfwriter_open() and then elfwriter_setsection() can be
|
||||
* called later to fix-up the section id.
|
||||
*/
|
||||
struct ElfWriterSymRef elfwriter_appendsym(struct ElfWriter *elf,
|
||||
const char *name, int st_info,
|
||||
int st_other, size_t st_value,
|
||||
|
@ -247,6 +258,11 @@ struct ElfWriterSymRef elfwriter_appendsym(struct ElfWriter *elf,
|
|||
: kElfWriterSymGlobal);
|
||||
}
|
||||
|
||||
void elfwriter_setsection(struct ElfWriter *elf, struct ElfWriterSymRef sym,
|
||||
uint16_t st_shndx) {
|
||||
elf->syms[sym.slg]->p[sym.sym].st_shndx = st_shndx;
|
||||
}
|
||||
|
||||
struct ElfWriterSymRef elfwriter_linksym(struct ElfWriter *elf,
|
||||
const char *name, int st_info,
|
||||
int st_other) {
|
||||
|
|
|
@ -61,6 +61,7 @@ struct ElfWriterSymRef elfwriter_linksym(struct ElfWriter *, const char *, int,
|
|||
struct ElfWriterSymRef elfwriter_appendsym(struct ElfWriter *, const char *,
|
||||
int, int, size_t, size_t);
|
||||
void elfwriter_yoink(struct ElfWriter *, const char *);
|
||||
void elfwriter_setsection(struct ElfWriter *, struct ElfWriterSymRef, uint16_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -47,7 +47,7 @@ static void rehash(struct InternerObject *it) {
|
|||
if (!p[i].hash) continue;
|
||||
step = 0;
|
||||
do {
|
||||
j = (p[i].hash + step * (step + 1) / 2) & (it->n - 1);
|
||||
j = (p[i].hash + step * ((step + 1) >> 1)) & (it->n - 1);
|
||||
step++;
|
||||
} while (it->p[j].hash);
|
||||
memcpy(&it->p[j], &p[i], sizeof(p[i]));
|
||||
|
@ -103,7 +103,7 @@ size_t internobj(struct Interner *t, const void *data, size_t size) {
|
|||
hash = max(1, KnuthMultiplicativeHash32(data, size));
|
||||
do {
|
||||
/* it is written that triangle probe halts iff i<n/2 && popcnt(n)==1 */
|
||||
i = (hash + step * (step + 1) / 2) & (it->n - 1);
|
||||
i = (hash + step * ((step + 1) >> 1)) & (it->n - 1);
|
||||
if (it->p[i].hash == hash && it->p[i].index + size <= it->pool.n &&
|
||||
memcmp(item, &it->pool.p[it->p[i].index], size) == 0) {
|
||||
return it->p[i].index;
|
||||
|
@ -114,7 +114,7 @@ size_t internobj(struct Interner *t, const void *data, size_t size) {
|
|||
rehash(it);
|
||||
step = 0;
|
||||
do {
|
||||
i = (hash + step * (step + 1) / 2) & (it->n - 1);
|
||||
i = (hash + step * ((step + 1) >> 1)) & (it->n - 1);
|
||||
step++;
|
||||
} while (it->p[i].hash);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ int AppendIovs(struct Iovs *ib, void *base, size_t len) {
|
|||
if (i && (intptr_t)base == (intptr_t)p[i - 1].iov_base + p[i - 1].iov_len) {
|
||||
p[i - 1].iov_len += len;
|
||||
} else {
|
||||
if (unlikely(i == n)) {
|
||||
if (__builtin_expect(i == n, 0)) {
|
||||
n += n >> 1;
|
||||
if (p == ib->init) {
|
||||
if (!(p = malloc(sizeof(struct iovec) * n))) return -1;
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
* Only the first 64kb of each source file is considered.
|
||||
*/
|
||||
|
||||
alignas(16) const char kIncludePrefix[] = "include \"";
|
||||
_Alignas(16) const char kIncludePrefix[] = "include \"";
|
||||
|
||||
const char kSourceExts[][5] = {".s", ".S", ".c", ".cc", ".cpp"};
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "tool/decode/lib/asmcodegen.h"
|
||||
#include "tool/decode/lib/elfidnames.h"
|
||||
#include "tool/decode/lib/flagger.h"
|
||||
|
@ -249,10 +250,10 @@ static char *getelfsymbolname(const Elf64_Ehdr *elf, size_t mapsize,
|
|||
|
||||
static void printelfrelocations(void) {
|
||||
int sym;
|
||||
size_t i, j;
|
||||
size_t i, j, count;
|
||||
const Elf64_Sym *syms;
|
||||
const Elf64_Rela *rela;
|
||||
const Elf64_Shdr *shdr, *boop;
|
||||
const Elf64_Shdr *shdr, *symtab;
|
||||
char *strtab, *shstrtab, *symbolname;
|
||||
strtab = GetElfStringTable(elf, st->st_size);
|
||||
shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
|
||||
|
@ -266,11 +267,16 @@ static void printelfrelocations(void) {
|
|||
min((uintptr_t)elf + st->st_size,
|
||||
(uintptr_t)elf + shdr->sh_offset + shdr->sh_size));
|
||||
++rela, ++j) {
|
||||
boop = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link);
|
||||
syms = GetElfSectionAddress(elf, st->st_size, boop);
|
||||
symtab = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link);
|
||||
count = symtab->sh_size / symtab->sh_entsize;
|
||||
syms = GetElfSectionAddress(elf, st->st_size, symtab);
|
||||
sym = ELF64_R_SYM(rela->r_info);
|
||||
symbolname =
|
||||
getelfsymbolname(elf, st->st_size, strtab, shstrtab, &syms[sym]);
|
||||
if (0 <= sym && sym < count) {
|
||||
symbolname =
|
||||
getelfsymbolname(elf, st->st_size, strtab, shstrtab, syms + sym);
|
||||
} else {
|
||||
symbolname = xasprintf("bad-sym-%d", sym);
|
||||
}
|
||||
printf("/\t%s+%#lx → %s%c%#lx\n",
|
||||
GetElfString(
|
||||
elf, st->st_size, shstrtab,
|
||||
|
@ -297,7 +303,7 @@ static void printelfrelocations(void) {
|
|||
int main(int argc, char *argv[]) {
|
||||
showcrashreports();
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %`s FILE: %s\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s FILE\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
path = argv[1];
|
||||
|
|
|
@ -1665,7 +1665,6 @@ Keywords={
|
|||
"COSMOPOLITAN_C_END_",
|
||||
"MACHINE_CODE_ANALYSIS_BEGIN_",
|
||||
"MACHINE_CODE_ANALYSIS_END_",
|
||||
"typescompatible",
|
||||
"DebugBreak",
|
||||
"VEIL",
|
||||
"CONCEAL",
|
||||
|
@ -1674,8 +1673,6 @@ Keywords={
|
|||
"STATIC_YOINK",
|
||||
"STATIC_YOINK_SOURCE",
|
||||
"STRINGIFY",
|
||||
"isconstant",
|
||||
"chooseexpr",
|
||||
"likely",
|
||||
"unlikely",
|
||||
"assume",
|
||||
|
|
|
@ -1280,8 +1280,7 @@
|
|||
"MACHINE_CODE_ANALYSIS_END_"))
|
||||
|
||||
(cosmopolitan-builtin-functions
|
||||
'("typescompatible"
|
||||
"DebugBreak"
|
||||
'("DebugBreak"
|
||||
"VEIL"
|
||||
"CONCEAL"
|
||||
"EXPROPRIATE"
|
||||
|
@ -1289,8 +1288,6 @@
|
|||
"STATIC_YOINK"
|
||||
"STATIC_YOINK_SOURCE"
|
||||
"STRINGIFY"
|
||||
"isconstant"
|
||||
"chooseexpr"
|
||||
"likely"
|
||||
"unlikely"))
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@
|
|||
(cond ((not (eq 0 (logand 8 arg)))
|
||||
(cosmo--assembly (setq arg (logand (lognot 8)))
|
||||
"SILENT=0 COPTS='-Os'"))
|
||||
(t (cosmo--assembly arg "SILENT=0 COPTS='-Os' TARGET_ARCH='-march=znver2 -mdispatch-scheduler' CPPFLAGS='-DSTACK_FRAME_UNLIMITED'"))))
|
||||
(t (cosmo--assembly arg "SILENT=0 COPTS='-Os' TARGET_ARCH='-mdispatch-scheduler' CPPFLAGS='-DSTACK_FRAME_UNLIMITED'"))))
|
||||
|
||||
(defun cosmo-assembly-native (arg)
|
||||
(interactive "P")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue