This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Allow using PLT relocations when "-z notext" is given.
ClosedPublic

Authored by grimar on Dec 22 2017, 3:47 AM.

Details

Summary

This is PR35720.

Currently LLD allows dynamic relocations against text when -z notext is given.
Though for non-PIC relocations like R_X86_64_PC32 that does not work,
we produce "relocation R_X86_64_PC32 cannot be used against shared object;"
error because they may overflow in runtime.

Solution implemented is to use PLT for them.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Dec 22 2017, 3:47 AM
emaste added inline comments.Dec 22 2017, 6:28 AM
ELF/Relocations.cpp
558 ↗(On Diff #128009)

Convention would have the comment before the function, no?

grimar updated this revision to Diff 128023.Dec 22 2017, 6:52 AM
grimar marked an inline comment as done.

Addressed review comment:

  • Moved function comment outsize and converted to function header comment.

I can confirm this fixes the reduced test case, but the 'hello world' test on FreeBSD still fails, now with:

/home/emaste/src/llvm/build/bin/ld.lld: error: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
>>> defined in usr/lib/crtbegin.o
>>> referenced by /usr/home/emaste/src/freebsd/contrib/gcc/crtstuff.c
>>>               usr/lib/crtbegin.o:(frame_dummy)
grimar added a comment.EditedDec 22 2017, 7:55 AM

I can confirm this fixes the reduced test case, but the 'hello world' test on FreeBSD still fails, now with:

/home/emaste/src/llvm/build/bin/ld.lld: error: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
>>> defined in usr/lib/crtbegin.o
>>> referenced by /usr/home/emaste/src/freebsd/contrib/gcc/crtstuff.c
>>>               usr/lib/crtbegin.o:(frame_dummy)

I guess 'frame_dummy' is not of STT_FUNC type probably. I'll check the initial testcase (sorry that did not do that before posting the patch).

I can confirm this fixes the reduced test case, but the 'hello world' test on FreeBSD still fails, now with:

/home/emaste/src/llvm/build/bin/ld.lld: error: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
>>> defined in usr/lib/crtbegin.o
>>> referenced by /usr/home/emaste/src/freebsd/contrib/gcc/crtstuff.c
>>>               usr/lib/crtbegin.o:(frame_dummy)

It happens because R_X86_64_32 reloc is used against _Jv_RegisterClasses, which is
NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses

That looks to be different issue. It is not a function and I do not see dynamic relocation for it in bfd output,
I can try to investigate it tomorrow.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 23 2017, 1:01 AM
This revision was automatically updated to reflect the committed changes.