This is an archive of the discontinued LLVM Phabricator instance.

[LLD/ELF2] Initial support for local symbols in symtab
ClosedPublic

Authored by davide on Sep 14 2015, 10:14 PM.

Details

Summary

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).

Diff Detail

Repository
rL LLVM

Event Timeline

davide updated this revision to Diff 34778.Sep 14 2015, 10:14 PM
davide retitled this revision from to [LLD/ELF2] Initial support for local symbols in symtab.
davide updated this object.
davide added reviewers: rafael, Bigcheese.
davide set the repository for this revision to rL LLVM.
davide added a subscriber: llvm-commits.
silvas added a subscriber: silvas.Sep 14 2015, 10:54 PM
silvas added inline comments.
test/elf2/local.s
14 ↗(On Diff #34778)

Offset doesn't seem to matter for this test?

16–17 ↗(On Diff #34778)

Do we care about these indices? We aren't checking that 5 and 4 are a particular thing.

32 ↗(On Diff #34778)

I don't think we need to check the exact string table index.

denis-protivensky added inline comments.
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.

rafael edited edge metadata.Sep 15 2015, 5:21 AM
rafael added a subscriber: rafael.

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

davide updated this revision to Diff 34835.Sep 15 2015, 2:28 PM
davide edited edge metadata.
davide removed rL LLVM as the repository for this revision.

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.

davide updated this revision to Diff 34836.Sep 15 2015, 2:31 PM

Fix typo in comment: s/dynsm/dynsym.
Also, previous patch introduces -discard-all option and uses it in test, as proposed by Rafael.

davide updated this revision to Diff 34838.Sep 15 2015, 2:37 PM
  • Clean up tests a little bit more.

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.

davide updated this revision to Diff 34918.Sep 16 2015, 12:56 PM

New patch:

  • refactor to reduce duplication (thank you for keeping me honest)
  • use -dynsym instead of -s for test
rafael accepted this revision.Sep 16 2015, 1:14 PM
rafael edited edge metadata.

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 {

This revision is now accepted and ready to land.Sep 16 2015, 1:14 PM
This revision was automatically updated to reflect the committed changes.