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
- Repository
- rL LLVM
Event Timeline
ELF/InputFiles.cpp | ||
---|---|---|
78 ↗ | (On Diff #34778) | return llvm::make_range... for consistency |
ELF/Writer.cpp | ||
551 ↗ | (On Diff #34778) | Maybe better to rename BufStart to something like BufVisible since it points to the start of visible symbols? |
614 ↗ | (On Diff #34778) | 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 ↗ | (On Diff #34836) | s/XXX/FIXME/ Please do fix it on the next patch. |
84 ↗ | (On Diff #34836) | 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
LGTM with a nit.
ELF/InputFiles.cpp | ||
---|---|---|
67 ↗ | (On Diff #34918) | We normally put {} in both the if and the else or in neither. |
72 ↗ | (On Diff #34918) | You don't need this special case. The line bellow becomes return llvm::make_range(Syms.begin() + 1, Syms.begin() + 1); Which is a valid empty range. With that you can also drop the { |