I am working on https://bugs.llvm.org/show_bug.cgi?id=42622
and this patch reworks the gnu-hash-symbols.test so that it
will be easier to expand it with x86_64 case.
Details
Diff Detail
Event Timeline
test/tools/llvm-readobj/gnu-hash-symbols.test | ||
---|---|---|
1 | Rename gnu-hash-symbols.test to elf-hash-symbols.test (or other better name) This files tests both .hash (SysV hash) and .gnu.hash (GNU hash). | |
32 | Here and below it -> Here and below Or better, just explicitly mention that the contents of .hash and .gnu.hash were generated by a linker. |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
4 ↗ | (On Diff #210041) | I wonder if we should add --strict-whitespace/--match-full-lines to this. That will ensure spacing is correct. What do you think? |
20 ↗ | (On Diff #210041) | I think you need to test that there's nothing after the last line, to show that there are no more entries in .gnu.hash. |
48 ↗ | (On Diff #210041) | Perhaps you should explain what 0x2C is (I think it's the size of .hash, right?) |
78 ↗ | (On Diff #210041) | Do you think there's value for testing the case with exactly one of .hash or .gnu.hash? |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
3 ↗ | (On Diff #210041) | %t1-386.o -> %t1-386.so It is weird to name an ET_DYN *.o |
48 ↗ | (On Diff #210041) |
Nit: I think the usage here is a bit unusual. Normally a PT_DYNAMIC is created to contain .dynamic and at runtime the rtld decodes .dynamic entries by finding the PT_DYNAMIC address. Maybe you can create a PT_DYNAMIC to make the test look more reasonable? If you decide to do that, delete - Section: .dynamic from the PT_LOAD. |
78 ↗ | (On Diff #210041) | I think it is fine not to test that... |
- Addressed review comments.
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
4 ↗ | (On Diff #210041) | Yep, makes sense, done. |
48 ↗ | (On Diff #210041) | I expanded the comment to reveal the full picture of how the computation happen. Note that in this test case both .hash and .gnu.hash have section VAs = 0 |
78 ↗ | (On Diff #210041) | I do not mind. Done. Side question: if we have a file with dynamic table that has DT_HASH and DT_GNU_HASH tags |
- Addressed review comments.
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
3 ↗ | (On Diff #210041) | Done. |
48 ↗ | (On Diff #210041) |
But we are testing here the logic of llvm-readelf. It does not need PT_DYNAMIC to dump the hash tables. |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
48 ↗ | (On Diff #210041) | Moreover, I think we could improve dumper to be able to dump these section even without any .dynamic section at all. |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
218 ↗ | (On Diff #210069) | %t4.so |
48 ↗ | (On Diff #210041) | Not having PT_DYNAMIC should be fine. One more nit: it made me puzzled because .dynamic is writable and contained in the PT_LOAD but the PT_LOAD is not writable.. You can delete the SHF_WRITE flag from .dynamic (it doesn't include DT_DEBUG so it is not necessarily writable).
GNU objcopy just locates the dynamic section with either PT_DYNAMIC or .dynamic, then decodes DT_HASH and/or DT_GNU_HASH. It doesn't check SHT_HASH or SHT_GNU_HASH probably because the section header is optional in ET_DYN/ET_EXEC. However, PT_DYNAMIC must be available for the hash tables to be recognized by ld.so, so objcopy doesn't bother implementing the logic. |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
7 ↗ | (On Diff #210069) | HASH-I386 -> HASH-32 |
78 ↗ | (On Diff #210041) | I don't think llvm-objcopy should be modifying the contents of the .dynamic section or any other loadable section, with the exception of removing the contents of sections where we explicitly request to remove them. Doing so can mess up addresses and so on. |
- Addressed review comments.
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
218 ↗ | (On Diff #210069) | Oh, thanks. |
48 ↗ | (On Diff #210041) |
Sorry if I am missing something, but this patch is for llvm-readelf. Did you mean GNU readelf?
That would allow us to dump more information in a broken objects. At least it seems would be useful for the test cases like that. |
Plan a minor change.
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
48 ↗ | (On Diff #210041) |
I think I missed this one. Going to remove it. |
test/tools/llvm-readobj/elf-hash-symbols.test | ||
---|---|---|
48 ↗ | (On Diff #210041) |
My feeling is that just locating DT_HASH and DT_GNU_HASH should be good enough. There may be cases that both 1) PT_DYNAMIC is broken and 2) .dynamic is missing. In these cases, locating SHT_HASH/SHT_GNU_HASH as a fallback will still allow us to dump hash tables (your proposal). My feeling is that these cases may be rare enough that we don't need to do so. (I wanted to save you the work but I will not be opposed to the idea if you insist on implementing it...) |
Rename gnu-hash-symbols.test to elf-hash-symbols.test (or other better name)
This files tests both .hash (SysV hash) and .gnu.hash (GNU hash).