Make minor improvements

This commit is contained in:
Justine Tunney 2020-12-23 23:42:56 -08:00
parent 04caf6f9ad
commit 95b142e4e5
95 changed files with 3818 additions and 2760 deletions

View file

@ -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) {

View file

@ -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) */

View file

@ -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);
}

View file

@ -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;