Maybe this can be shrunk, and local.s needs some cleanup. Would appreciate comments, as I have other patches building on top of this one (I'll propose later if we're OK with the scaffolding).
Details
Diff Detail
Event Timeline
ELF/InputFiles.cpp | ||
---|---|---|
78 | return llvm::make_range... for consistency | |
ELF/Writer.cpp | ||
551 | Maybe better to rename BufStart to something like BufVisible since it points to the start of visible symbols? | |
614 | Looks like Syms = BufStart = pointer to the buffer with STN_UNDEF and local symbols already skipped, so you need to pass Syms + NumVisible as the array end. |
Please git-clang-format it.
The current behavior is equivalent to --discard-all. Please add that
option and use it in the existing tests.
For local.s, use FileCheck variables to check what Link points to or
just use "Link :". We test that in other tests already.
There is duplicated code between getNonLocalSymbols and
getLocalSymbols. Can you create a getSymbols(bool Local) helper?
This crashes trying to add local symbols to the dynamic symbol table:
$ cat t.s
.global foo
foo:
bar:
$ clang -c t.s
$ ./build/bin/lld -flavor gnu2 t.o -o t.so -shared
lld: /home/espindola/llvm/llvm/include/llvm/MC/StringTableBuilder.h:54:
size_t llvm::StringTableBuilder::getOffset(llvm::StringRef) const:
Assertion `I != StringIndexMap.end() && "String is not in table!"'
failed.
uint8_t *BufStart = Buf;
The name is not very appropriate anymore. It now points to the start
of the global symbols.
Cheers,
Rafael
Hopefully addressed (almost) all the comments.
- Cleaned up tests
- Fixup crash reported by Rafael + added a new test for that
- Rename variables
I'll refactor getLocalSymbols() and getNonLocalSymbols() in a separate NFC patch. I put an XXX on top of the function so I won't forget.
Also, I think I ran clang-format correctly on my svn checkout, but please double check.
Fix typo in comment: s/dynsm/dynsym.
Also, previous patch introduces -discard-all option and uses it in test, as proposed by Rafael.
Looking pretty good.
Is there a big reason for not refactoring the duplicated code in this patch?
ELF/InputFiles.cpp | ||
---|---|---|
75 | s/XXX/FIXME/ Please do fix it on the next patch. | |
84 | This should be >=. Which is one of the reason I asked to avoid the code duplication. | |
test/elf2/local-dynamic.s | ||
4 ↗ | (On Diff #34836) | Instead of -s you can use llvm-leadobj -t -dyn-symbols. |
New patch:
- refactor to reduce duplication (thank you for keeping me honest)
- use -dynsym instead of -s for test
We normally put {} in both the if and the else or in neither.