let-def/owee

Symbol.name return truncated names

Drup opened this issue · 2 comments

Drup commented

Can be clearly seen when applying functions on itself

% ./_build/default/functions.exe _build/default/functions.exe | head
All symbols:
0 (function)
65 (function)
dlib__55 (function)
r_tm_clones (function)

sh_1010 (function)
mat__58 (function)
rray__size_in_bytes_1328 (function)
ring__rindex_from_opt_1173 (function)

Looking at it with nm, it's pretty clear some names are truncated.

The problem is that Owee_elf.Symbol_table is made by merging the .symtab and .dynsym tables. There are two issues here:

  • .symtab is a superset of .dynsym, so entries will be redundant
  • the symbol name of .dynsym entries should be looked up in .dynstr string table, while .symtab entries should be looked up in .strtab. However, the provenance (dynsym or strtab) is lost in the table and everything is looked up in .strtab. All .dynsym symbols will have incorrect names.

Here is what I think should be done:

  1. For backward compat, keep the existing Symbol_table interface but only lookup symbols in .symtab
  2. Expose lower-level functions for deserialization of string tables and symbol tables to the user, so that the basic infrastructure is there if someone want to deal with .dynsym directly.

There are too many ad-hoc things in ELF that I don't think it makes sense to expose an abstraction of the object format. However low-level details should be dealt with such that, assuming one is familiar with ELF, extracting other information is straightforward and doesn't require dealing with the byte-level representation.

@mshinwell: do you have any opinion on that matter?

Drup commented

I feel like the current API of owee is already quite complicated. I don't mind any changes, but I would like to know what's the correct way to extract the name of a symbol (today, and with the potential new API).