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

--- Comment #8 from Fangrui Song <i at maskray dot me> ---
Seems that -fno-plt -fno-pic does have the required properties.
A side effect is that all external calls use the   (x86-64) call
*f@GOTPCREL(%rip) (x86-32) call *f@GOT  form.

The instruction is one byte longer. (Calling a function is a common case.
Taking the address in a non-vtable case is uncommon. So I'd rather punish the
uncommon address taking).
When the linker notices that the branch target is defined in the executable, it
can optimize out the GOT to use an addr32 prefix instead.
(gold and ld.lld haven't implemented the optimization for 32-bit)

__attribute__((noplt))
int f();
void h() {}

void *g()
{
  h();       // call h
  f();       // call *f@GOTPCREL(%rip)
  return f;  // movq f@GOTPCREL(%rip), %rax
}

Reply via email to