This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] - Calculate the string table section sizes correctly.
ClosedPublic

Authored by grimar on Mar 18 2019, 6:23 AM.

Details

Summary

This fixes the https://bugs.llvm.org/show_bug.cgi?id=40980.

Previously if string optimization occurred as a result of
StringTableBuilder's finalize() method, the size wasn't updated.

This hopefully also makes the interaction between sections during finalization
processes a bit more clear.

Diff Detail

Event Timeline

grimar created this revision.Mar 18 2019, 6:23 AM
jhenderson accepted this revision.Mar 18 2019, 6:37 AM

LGTM, with a couple of comment nits.

I think you might have flushed out another bug with string table building, based on the size changes in the two archive tests. Could you double-check, and fix or file a bug, please? I'm guessing it's just that we're adding an extra null byte.

tools/llvm-objcopy/ELF/Object.cpp
1612

when -> that

1613

I'd replace everything from the "and we need..." to the end of the comment with "which in turn affects section offsets."

This revision is now accepted and ready to land.Mar 18 2019, 6:37 AM
grimar added a comment.EditedMar 18 2019, 6:45 AM

LGTM, with a couple of comment nits.

I think you might have flushed out another bug with string table building, based on the size changes in the two archive tests. Could you double-check, and fix or file a bug, please? I'm guessing it's just that we're adding an extra null byte.

Yes, sure, I am actually looking at this :) It seems the issue is that we add a zero's symbol name here (instead of ignoring that symbol):

(https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L498)

// Add all of our strings to SymbolNames so that SymbolNames has the right
// size before layout is decided.
for (auto &Sym : Symbols)
  SymbolNames->addString(Sym->Name);

I am not sure yet, just made this observation during developing this patch.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2019, 7:26 AM

LGTM, with a couple of comment nits.

I think you might have flushed out another bug with string table building, based on the size changes in the two archive tests. Could you double-check, and fix or file a bug, please? I'm guessing it's just that we're adding an extra null byte.

Yes, sure, I am actually looking at this :) It seems the issue is that we add a zero's symbol name here (instead of ignoring that symbol):

(https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L498)

// Add all of our strings to SymbolNames so that SymbolNames has the right
// size before layout is decided.
for (auto &Sym : Symbols)
  SymbolNames->addString(Sym->Name);

I am not sure yet, just made this observation during developing this patch.

I posted a patch for this: D59496

Maybe we should make "prepareForLayout" a top level operation that we can just run on all sections?

Maybe we should make "prepareForLayout" a top level operation that we can just run on all sections?

I thought about this, but the problem is call order: we should call it for symbol table earlier than for string table sections, for example.
i.e. it would not make the code to be a simple loop.