Closed RyanGlScott closed 1 year ago
A handful of thoughts that I wanted to record while looking into this:
One peculiar aspect of dynamicEntries
is that it will only compute function symbols if the header type is ET_DYN
, i.e., if we are dealing with a shared object. I'm honestly not sure why this check is here, since it means that dynamicEntries
will always be empty for non–position-independent executables, even if they otherwise contain dynamic function symbols.
I propose that when we move this code to elf-edit
, we omit the ET_DYN
check. We might even consider removing it from macaw
itself, as I'm unclear on what purpose it serves, although this is not strictly required.
There is another way to compute the dynamic symbol table by using elf-edit
's dynamicEntries
and dynSymEntry
functions. (See this part of the elf-edit
test suite for an example of how to do this.) In fact, this way of computing the dynamic symbol table gives you strictly more information that how macaw
computes it, as elf-edit
's way also gives you symbol version information.
That being said, I still think that it would be worth putting the code from macaw
code into elf-edit
, as it provides a much more straightforward API. You won't get symbol versions with this API, but that's arguably a more niche requirement.
Data.Macaw.Memory.ElfLoader
has two very intricate functions for computing the static symbol table:https://github.com/GaloisInc/macaw/blob/e4b198ab2dd882e34690ed33056d5231b2d776bf/base/src/Data/Macaw/Memory/ElfLoader.hs#L1330-L1347
And the dynamic symbol table:
https://github.com/GaloisInc/macaw/blob/e4b198ab2dd882e34690ed33056d5231b2d776bf/base/src/Data/Macaw/Memory/ElfLoader.hs#L1636-L1646
It turns out, however, that
elfStaticSymbolTable
is essentially identical todecodeHeaderSymtab
fromelf-edit
. We should removemacaw
's code in favor ofdecodeHeaderSymtab
. Moreover, the dynamic symbol table logic inmacaw
really ought to belong inelf-edit
as well, so that code should be migrated over toelf-edit
for others' benefit.