Page MenuHomePhabricator

-fno-semantic-interposition: Don't set dso_local on GlobalVariable
ClosedPublic

Authored by MaskRay on May 16 2021, 12:23 PM.

Details

Summary

clang -fpic -fno-semantic-interposition may set dso_local on variables for -fpic.

GCC folks consider there are 'address interposition' and 'semantic interposition',
and 'disabling semantic interposition' can optimize function calls but
cannot change variable references to use local aliases
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483).

This patch removes dso_local for variables in
clang -fpic -fno-semantic-interposition mode so that the built shared objects can
work with copy relocations.

Example:

// a.c
int var;
int *addr() { return var; }

// old: cannot be interposed
movslq  .Lvar$local(%rip), %rax
// new: can be interposed
movq    var@GOTPCREL(%rip), %rax
movslq  (%rax), %rax

The local alias lowering for GlobalVariables is kept in case there is a
future option allowing local aliases.

Diff Detail

Event Timeline

MaskRay requested review of this revision.May 16 2021, 12:23 PM
MaskRay created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2021, 12:23 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk accepted this revision.May 19 2021, 1:20 PM

lgtm

This revision is now accepted and ready to land.May 19 2021, 1:20 PM