r203052 - Construct GlobalValues with the correct linkage instead of using setLinkage.

Rafael Espíndola rafael.espindola at gmail.com
Thu Mar 6 11:40:13 PST 2014


> weak-def tells the linker the content can be merged/coalesced by name.
> The ‘l’ symbol prefix tells the linker the not add the symbol name to the final output.
> This combination really only make sense for visibility=hidden symbols (which they were).

OK. Lets try to figure out the correct way to represent this at the
LLVM IR. Some extra questions:

* Is the merge required to happen or it is just an optimization?
* Is it legal to merge by value?
* Is it legal to drop the symbol if it is not used in a translation unit?
* Is the content guaranteed to be the same in every TU?

And some observations

* Using private is currently the only direct way to hide a symbol
(other than manually applying the 'l' prefix).
* Using private, linker_private, linker_private_weak or internal is at
least undesirable. If llvm renames the symbol during IR link, it
prevents the linker from doing the merge. It might also be incorrect
if the merge is required to happen or if it is illegal to merge by
content.
* The merge by name property at the IR level is only provided by weak,
linkonce, weak_odr and linkonce_odr, so they do look to be the best
candidates.

Since no IR linkage maps directly to what we want, the two options seem to be
* Keep using an explicit 'l' prefix and one of (linkonce|weak)(_odr|),
but document why.
* Add a new linkage that the same as the selected
(linkonce|weak)(_odr|), but adds the 'l' prefix.

Given how specific this is, I would probably go with the first option.

Cheers,
Rafael




More information about the cfe-commits mailing list