This is an archive of the discontinued LLVM Phabricator instance.

With -fno-plt, GOTPCREL references must use RIP
ClosedPublic

Authored by tmsriram on Apr 9 2018, 3:04 PM.

Details

Summary

With -fno-plt, global value references can use GOTPCREL and RIP must be used.

A simple example that breaks with -fno-plt:

extern "C"
{
attribute((weak)) int weakfunc();

int fp_weakfunc() {

if (&weakfunc)
  return 1;
return 0;

}
}

$ clang -O2 -fno-plt -S file.cc
$ cat file.s
...
fp_weakfunc: # @fp_weakfunc
.cfi_startproc

%bb.0:

xorl %eax, %eax
cmpq $0, weakfunc@GOTPCREL
...

That's a GOTPCREL reference without %rip. This will force the linker to only patch it with the offset in the GOT and will get the exact opposite program behavior at run-time. This patch fixes it.

Diff Detail

Repository
rL LLVM

Event Timeline

tmsriram created this revision.Apr 9 2018, 3:04 PM
espindola accepted this revision.Apr 10 2018, 10:51 AM

LGTM with nits.

lib/Target/X86/X86ISelLowering.cpp
15511 ↗(On Diff #141747)

The comment and assert feel a bit much. It is sufficient to say that a GOTPCREL always needs (%rip).

test/CodeGen/X86/no-plt.ll
6 ↗(On Diff #141747)

you don't need:

dso_local
local_unnamed_addr
"#0"
entry:

please simplify.

This revision is now accepted and ready to land.Apr 10 2018, 10:51 AM
tmsriram updated this revision to Diff 141917.Apr 10 2018, 2:56 PM

Simplify test and condition.

tmsriram marked an inline comment as done.Apr 10 2018, 2:57 PM
This revision was automatically updated to reflect the committed changes.