This is an archive of the discontinued LLVM Phabricator instance.

IR: Introduce local_unnamed_addr attribute.
ClosedPublic

Authored by pcc on May 17 2016, 5:59 PM.

Details

Summary

If a local_unnamed_addr attribute is attached to a global, the address
is known to be insignificant within the module. It is distinct from the
existing unnamed_addr attribute in that it only describes a local property
of the module rather than a global property of the symbol.

This attribute is intended to be used by the code generator and LTO to allow
the linker to decide whether the global needs to be in the symbol table. It is
possible to exclude a global from the symbol table if three things are true:

  • This attribute is present on every instance of the global (which means that the normal rule that the global must have a unique address can be broken without being observable by the program by performing comparisons against the global's address)
  • The global has linkonce_odr linkage (which means that each linkage unit must have its own copy of the global if it requires one, and the copy in each linkage unit must be the same)
  • It is a constant or a function (which means that the program cannot observe that the unique-address rule has been broken by writing to the global)

Although this attribute could in principle be computed from the module
contents, LTO clients (i.e. linkers) will normally need to be able to compute
this property as part of symbol resolution, and it would be inefficient to
materialize every module just to compute it.

See:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html
for earlier discussion.

Part of the fix for PR27553.

Diff Detail

Event Timeline

pcc updated this revision to Diff 57546.May 17 2016, 5:59 PM
pcc retitled this revision from to IR: Introduce local_unnamed_addr attribute..
pcc updated this object.
pcc added a subscriber: llvm-commits.
chandlerc edited edge metadata.May 17 2016, 6:08 PM
chandlerc added a subscriber: chandlerc.

Thanks for the detailed write-up, and sorry to Rafael and Mehdi that it's
on a new thread. =/

pcc updated this revision to Diff 60091.Jun 8 2016, 1:12 PM
pcc edited edge metadata.
  • Refresh
rafael accepted this revision.Jun 11 2016, 5:48 AM
rafael edited edge metadata.

This LGTM.

Chandler, are you OK with this being an attribute given Mehdi's argument that "llvm-dis | llvm-as" should produce equivalent bitcode?

This revision is now accepted and ready to land.Jun 11 2016, 5:48 AM

This LGTM.

Chandler, are you OK with this being an attribute given Mehdi's argument that "llvm-dis | llvm-as" should produce equivalent bitcode?

Yea, I guess.

I completely buy the argument that llvm-dis | llvm-as should produce equivalent bitcode. =] That's not my hang-up. I just think we will regret having both 'unnamed_addr' and 'local_unnamed_addr' with such subtly different semantics, and I continue to find the approach we are taking to address problems here to feel like a mis-use of the attribute system. This just doesn't feel like it fits.

But that said, I don't have an alternative suggestion at this point, and I don't want to obstruct progress. I just predict us having to walk this back at some future date and that being costly, which makes it hard for me to be super enthusiastic. Ahh, well.

This revision was automatically updated to reflect the committed changes.