This is an archive of the discontinued LLVM Phabricator instance.

[ELF/AArch64] Add support for the R_AARCH64_COPY relocation.
ClosedPublic

Authored by ikudrin on Nov 27 2015, 6:49 AM.

Details

Summary

Generate the R_AARCH64_COPY relocation for non-GOT relocations,
which reference object symbols from shared libraries.

Diff Detail

Event Timeline

ikudrin updated this revision to Diff 41303.Nov 27 2015, 6:49 AM
ikudrin retitled this revision from to [ELF/AArch64] Add support for the R_AARCH64_COPY relocation..
ikudrin updated this object.
ikudrin added reviewers: ruiu, davide, rafael.
ikudrin added a project: lld.
ikudrin added a subscriber: llvm-commits.
ruiu added inline comments.Nov 27 2015, 7:07 AM
ELF/Target.cpp
917–919

These are GOT-relative relocations. Do you need to create copy relocations for them?

ikudrin added inline comments.Nov 27 2015, 7:27 AM
ELF/Target.cpp
917–919

They are in the same table "4-6, Data relocations" and in the same section "4.6.5 Static Data relocations" as R_AARCH64_ABS* in the following spec: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf.

Can you hint me for some other specs?

ruiu added inline comments.Nov 27 2015, 7:31 AM
ELF/Target.cpp
917–919

I'm sorry if that's not clear, I pointed out PREL relocations. (I selected these three lines on Phab, but Phab includes plus/minus one lines to the diff in addition to the selection I made on the web UI.)

ikudrin added inline comments.Nov 27 2015, 7:43 AM
ELF/Target.cpp
917–919

Yes, I've commented the same lines, about _PREL* relocs. I have to admit that I haven't found a real sample to check all of them. I filled the list basing mostly on my understanding of specs. I'll really appreciate any hints and samples.

ruiu added inline comments.Nov 27 2015, 9:20 AM
ELF/Target.cpp
917–919

Since they are GOT-relative, all code that uses these relocations should always reference data through GOT, so no need to create copy relocations. Gold doesn't create copy relocations for them too.

ikudrin added inline comments.Nov 27 2015, 9:30 AM
ELF/Target.cpp
917–919

The spec says that they are position-relative, not GOT-relative. http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf.
Am I wrong? Do you have the other spec?

ruiu added inline comments.Nov 27 2015, 9:33 AM
ELF/Target.cpp
917–919

Hm, I may have misread the spec. But could you take a look at gold? It seems to me that they do not create copy relocations for them.

ikudrin added inline comments.Nov 27 2015, 10:25 AM
ELF/Target.cpp
917–919

Gold doesn't produce COPY relocations in that case. It only makes PLT entry if some conditions met. And they have a comment "This is used to fill the GOT absolute address".

ruiu added inline comments.Nov 30 2015, 10:01 AM
ELF/Target.cpp
917–919

Doesn't that mean we shouldn't create COPY relocations for PREL relocations, no? Or, are we different from gold?

ikudrin added inline comments.Nov 30 2015, 10:49 AM
ELF/Target.cpp
917–919

I've not finished my investigations with gold yet. I don't feel like we should just copy their behavior, I prefer to understand it first.

ruiu added inline comments.Nov 30 2015, 10:53 AM
ELF/Target.cpp
917–919

I completely agree.

ikudrin updated this revision to Diff 41522.Dec 1 2015, 9:07 AM
ikudrin updated this object.
  • Removed R_AARCH64_PREL{16,32,64} relocations from the list of sources for COPY relocation.
  • Sorted relocation codes.
ruiu edited edge metadata.Dec 1 2015, 9:14 AM

What was the conclusion on PREL relocations?

In D15043#299593, @ruiu wrote:

What was the conclusion on PREL relocations?

  • Neither ld, nor gold create a COPY relocation for a source PREL relocation.
  • For me, it's hard to imagine using a PREL relocation against an external preemtible object symbol.

So, nobody probably will suffer.

We have another difference from gold, concerning ABS relocations. They don't generate a COPY relocation if an ABS relocation targets a r/w segment; in this case, they just preserve the original relocation. Everything works fine because the dynamic linker from glibc supports ABS{32,64} relocations in addition to the standard dynamic relocations. I am not sure about other dynamic linkers, in particular, on FreeBSD, and anyway ld generates COPY relocations in that situation. Thus, I decided to generate COPY relocations in that case.

ruiu accepted this revision.Dec 1 2015, 9:51 AM
ruiu edited edge metadata.

LGTM. Thank you for investigating!

This revision is now accepted and ready to land.Dec 1 2015, 9:51 AM
ikudrin updated this revision to Diff 41632.Dec 2 2015, 8:32 AM
ikudrin edited edge metadata.
  • Add check for the type of the output because COPY relocations shouldn't be created for shared objects.
ruiu added a comment.Dec 2 2015, 10:25 AM

LGTM

ELF/Target.cpp
923–924

You may want to move this at beginning of this function?

This revision was automatically updated to reflect the committed changes.