This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Include in .symtab/.dynsym symbols introduced by optimizations
ClosedPublic

Authored by davide on Mar 22 2016, 9:54 AM.

Details

Summary

Some optimizations, e.g. SimplifyLibCalls, can replace functions with others as part of the lowering, e.g. printf => puts.
The new symbols don't have the isUsedInRegularObj flag set so they don't get included in the final symbol table (and dynamic symbol table), and the dynamic linker gets confused.

davide@foogoo:~/llvm/build/bin % ./clang blah.c -o blah -flto -fuse-ld=lld -Wl,-L/lib
davide@foogoo:~/llvm/build/bin % ./blah
Segmentation fault (core dumped)
davide@foogoo:~/llvm/build/bin % ./llvm-nm ./blah | grep puts

% cat blah.c
#include <stdio.h>

int main(void)
{

printf("blah\n");
return (0);

}

My proposed fix is to set the flag in addCombinedLtoObject() once we see the new symbols. I'm working on a testcase now, but I would like to hear if this sounds reasonable to you.

Diff Detail

Repository
rL LLVM

Event Timeline

davide updated this revision to Diff 51294.Mar 22 2016, 9:54 AM
davide retitled this revision from to [LTO] Include in .symtab/.dynsym symbols introduced by optimizations.
davide updated this object.
davide added reviewers: rafael, mehdi_amini.
davide added a subscriber: llvm-commits.
rafael edited edge metadata.Mar 22 2016, 1:15 PM
rafael added a subscriber: rafael.

I think this is fine with a test, but please upload a version that includes one.

davide updated this revision to Diff 51810.Mar 28 2016, 11:21 AM
davide edited edge metadata.

Add testcase.

ruiu added a subscriber: ruiu.Mar 28 2016, 11:59 AM

Maybe we should rename IsUsedInRegularObj -> MustBeInSymtab?

rafael added inline comments.Mar 28 2016, 3:26 PM
ELF/SymbolTable.cpp
111 ↗(On Diff #51810)

git-clang-format issue?

davide updated this revision to Diff 51846.Mar 28 2016, 3:29 PM

clang-format clean.,

rafael added inline comments.Mar 28 2016, 3:32 PM
ELF/SymbolTable.cpp
112 ↗(On Diff #51810)

You can just unconditionally set this, no?
That would be simpler and a bit more like what happens during regular symbol resolution.

test/ELF/lto/undefined-puts.ll
20 ↗(On Diff #51810)

It is also used in a relocation, no? Can you check that for completeness?

davide updated this revision to Diff 51847.Mar 28 2016, 3:44 PM

Rafael's comments.

Lgtm.

Thanks
Rafael

This revision was automatically updated to reflect the committed changes.