mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 09:48:29 +00:00
Add support for symbol table in .com files
This change fixes minor bugs and adds a feature, which lets us store the ELF symbol table, inside the ZIP directory. We use the path /zip/.symtab which can be safely removed using a zip editing tool, to make the binary smaller after compilation. This supplements the existing method of using a separate .com.dbg file, which is still supported. The intent is people don't always know that it's a good idea to download the debug file. It's not great having someone's first experience be a crash report, that only has numbers rather than symbols. This will help fix that!
This commit is contained in:
parent
393ca4be40
commit
23b72eb617
61 changed files with 963 additions and 510 deletions
|
@ -110,11 +110,11 @@ noasan struct SymbolTable *OpenSymbolTable(const char *filename) {
|
|||
void *map;
|
||||
long *stp;
|
||||
struct stat st;
|
||||
size_t n, m, tsz;
|
||||
unsigned i, j, x;
|
||||
const Elf64_Ehdr *elf;
|
||||
const char *name_base;
|
||||
struct SymbolTable *t;
|
||||
size_t n, m, tsz, size;
|
||||
const Elf64_Sym *symtab, *sym;
|
||||
ptrdiff_t names_offset, name_base_offset, stp_offset;
|
||||
map = MAP_FAILED;
|
||||
|
@ -136,13 +136,19 @@ noasan struct SymbolTable *OpenSymbolTable(const char *filename) {
|
|||
tsz += m;
|
||||
tsz = ROUNDUP(tsz, FRAMESIZE);
|
||||
stp_offset = tsz;
|
||||
size = tsz;
|
||||
tsz += sizeof(const Elf64_Sym *) * n;
|
||||
tsz = ROUNDUP(tsz, FRAMESIZE);
|
||||
t = mmap(0, tsz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||
if (t == MAP_FAILED) goto SystemError;
|
||||
t->mapsize = tsz;
|
||||
t->names = (unsigned *)((char *)t + names_offset);
|
||||
t->name_base = (char *)((char *)t + name_base_offset);
|
||||
t->magic = SYMBOLS_MAGIC;
|
||||
t->abi = SYMBOLS_ABI;
|
||||
t->size = size;
|
||||
t->mapsize = size;
|
||||
t->names_offset = names_offset;
|
||||
t->name_base_offset = name_base_offset;
|
||||
t->names = (uint32_t *)((char *)t + t->names_offset);
|
||||
t->name_base = (char *)((char *)t + t->name_base_offset);
|
||||
GetImageRange(elf, &t->addr_base, &t->addr_end);
|
||||
memcpy(t->name_base, name_base, m);
|
||||
--t->addr_end;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue