https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #2 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
I'm afraid this is potentially misunderstanding what the word 'semantic' in
-fno-semantic-interposition implies. I am not the author, but I always
understood this like so:

GCC is concerned with two aspects of ELF interposition: address interposition
(for address uniqueness) and functionality interposition (e.g. hooking malloc).
For optimization, the compiler cares a lot about the latter (it blocks inlining
and other optimizations), but not so much about the former (taking an address
of a global is rarely on the hot paths, so it's not critical to convert GOT
loads to pc-relative relocations).

So GCC splits ELF interposition concerns to 'address interposition' and
'semantic interposition', maintains the ability to perform the former (so
address uniqueness is not broken), and allows the programmer to promise that
semantic interposition (interposing a function with another function that acts
differently) does not happen.

To illustrate, compiling

void f(){
  asm("#");
}
void *g(){
  f();
  return f;
}

with -O2 -fpic -fno-semantic-interposition yields

f:
        #
        ret
g:
        #
        movq    f@GOTPCREL(%rip), %rax
        ret

i.e. the call is inlined, but taking the address goes through the GOT.

Reply via email to