This is an archive of the discontinued LLVM Phabricator instance.

ELF: Override DSO definitions when creating __start_* and __stop_* symbols.
ClosedPublic

Authored by pcc on Oct 12 2016, 7:12 PM.

Details

Summary

Previously we would fail to synthesise a start_ or stop_ symbol if
there existed a definition in a DSO. Instead, we would try to link against
the DSO definition. This became possible after D23552 when linking against
lld-produced DSOs but could in principle also occur when linking against
DSOs produced by other linkers.

Not only does it seem more likely that a user would expect the resolved
definition to be local to the executable, but if a start_ or stop_
symbol was synthesised by the linker, it is effectively impossible to link
against correctly from a non-PIC executable in a read-only section. Neither
a PLT nor a copy relocation would give us the right semantics here. The only
way the link could succeed is if the executable provided its own synthetic
definition of the symbol.

The fix is to also synthesise the definition if the only definition comes
from a DSO. Since this is what the addOptionalSynthetic function does,
switch to using that function.

Fixes PR30680.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 74469.Oct 12 2016, 7:12 PM
pcc retitled this revision from to ELF: Override DSO definitions when creating __start_* and __stop_* symbols..
pcc updated this object.
pcc added reviewers: ruiu, davide, grimar, rafael.
pcc added subscribers: krasin, llvm-commits.
ruiu accepted this revision.Oct 13 2016, 2:51 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 13 2016, 2:51 PM
joerg added a subscriber: joerg.Oct 13 2016, 3:09 PM

You want to allow the main program to get the start/stop of a DSO it links against? Am I understanding you correct?

You want to allow the main program to get the start/stop of a DSO it links against? Am I understanding you correct?

Yes, this is correct. One of the major reasons to allow that is that tcmalloc relies on this interface for the malloc hooks:
https://cs.chromium.org/chromium/src/third_party/tcmalloc/vendor/src/base/basictypes.h?q=ATTRIBUTE_SECTION&sq=package:chromium&dr=CSs&l=227

pcc added a comment.Oct 13 2016, 3:11 PM

No, the opposite. I want the program to get its own start/stop even if a DSO provides a definition.

In D25544#569703, @pcc wrote:

No, the opposite. I want the program to get its own start/stop even if a DSO provides a definition.

Then count me confused...

davide accepted this revision.Oct 13 2016, 3:18 PM
davide edited edge metadata.

lgtm

This revision was automatically updated to reflect the committed changes.