This is an archive of the discontinued LLVM Phabricator instance.

Change how we apply rellocations
ClosedPublic

Authored by rafael on Apr 1 2016, 1:34 PM.

Details

Reviewers
ruiu
Summary

With this patch we use the first scan over the relocations to remember the information we found about them: will them be relaxed, will a plt be used, etc.

With that the actual relocation application becomes much simpler. That is particularly true for the interfaces in Target.h.

This passes all tests, but I am still debugging a difference in the produced clang binary.

Diff Detail

Event Timeline

rafael updated this revision to Diff 52418.Apr 1 2016, 1:34 PM
rafael retitled this revision from to Change how we apply rellocations.
rafael updated this object.
rafael added a reviewer: ruiu.
rafael added a subscriber: llvm-commits.
emaste added a subscriber: emaste.Apr 1 2016, 1:39 PM
ruiu edited edge metadata.Apr 1 2016, 3:17 PM

First round of review comments.

ELF/InputSection.cpp
309–312

Sort.

ELF/InputSection.h
28

I'd define R_* names directly inside lld::ELF namespace because they don't conflict with other identifiers because of its R_ prefix.

39

I'd name R_PPC_PLT_OPD since this is PPC-specific.

54

I'd probably avoid naming this "Expr" because it is not an expression. It is more like the relocation type, right?

ELF/Target.cpp
236

You want to make this a pure virtual function.

530

It is no longer SA (which implies S+A) right? You want to give a new name.

ELF/Writer.cpp
607–615

You can separate IsSizeRel from other types.

if (Target->isSizeRel(Type)) {
  C.Relocations.push_back({Relocation::R_SIZE, Type, RI.r_offset, Addend, &Body});
  continue;
}

if (!Config->Pic ||  ...) {
  C.Relocations.push_back({Expr, Type, RI.r_offset, Addend, &Body});
  continue;
}

Hi Rafael,

What is the state of this patch: under active development or postponed?

rafael updated this revision to Diff 53091.Apr 8 2016, 2:45 PM
rafael edited edge metadata.

Rebased patch.

Sorry for the crazy delay. The two main things that are delaying this are

  • I noticed this was not handling non alloc sections.
  • I think I can dramatically reduced the number of enumerations that are needed. Similar to what I did in r265682.

I am giving the second idea a push. With that in place I will then fix the first one and upload a new patch that also addresses the review comments.

atanasyan added inline comments.Apr 10 2016, 11:42 PM
ELF/InputSection.h
39

I'd name R_PPC_PLT_OPD since this is PPC-specific.

I suggest to rename s/R_GOT_PAGE_PC/R_AARCH64_GOT_PAGE_PC/ and s/R_PAGE_PC/R_AARCH64_PAGE_PC/ by the same reason.

ruiu added inline comments.Apr 11 2016, 11:16 AM
ELF/InputSection.cpp
308

This function can be separated into three parts: the first switch-case, the middle ifs to adjust SymVA for special cases, and the last switch-case.

Looks like in most cases you can return from this function from the first switch-case. Why don't you do that?

ELF/InputSection.h
28

So you think that that's not a good idea?

Comment at: ELF/InputSection.h:53
@@ +52,3 @@
+ R_TLSLD_PC
+ } Expr;

+ uint32_t Type;

I'd probably avoid naming this "Expr" because it is not an expression. It is more like the relocation type, right?

It is part of it. The relocation type also says where to write (bits
10-21 for example), which is why I went with expr: it mostly just
shows which expression the relocation computes.

I will upload a new WIP patch in a second.

The final version I want to commit has far fewer enums by representing
the target by just addend and output section. With that representation
we don't need, for example, R_PC and and R_GOT_PC.

Cheers,
Rafael

rafael updated this revision to Diff 53324.Apr 11 2016, 3:05 PM

Rebase and fix some review comments.

silvas added a subscriber: silvas.Apr 11 2016, 3:23 PM
silvas added inline comments.
ELF/Target.cpp
530

Val is very generic. The previous names were based on computations in the psABI specs. Where is the documentation of the meaning of Val?

grimar added a subscriber: grimar.Apr 12 2016, 1:14 AM
rafael updated this revision to Diff 53399.Apr 12 2016, 8:18 AM

Address review comments.

Simplify mips got handling.

ruiu added inline comments.Apr 12 2016, 10:00 AM
ELF/InputSection.cpp
189

Why don't you return early in this switch-case? For example, for R_ABS, you can immediately return Body.getVA<ELFT>(A).

ruiu added inline comments.Apr 12 2016, 11:19 AM
ELF/InputSection.cpp
273–274

This if falls through because there's no continue. Is this expected?

rafael updated this revision to Diff 53457.Apr 12 2016, 1:51 PM

Early return as much as possible.

I will add processing of non alloca sections next.

rafael updated this revision to Diff 53459.Apr 12 2016, 2:17 PM

Pass new mips tests.

I will really add non alloca sections next.

rafael updated this revision to Diff 53487.Apr 12 2016, 4:13 PM

I think this patch handles all the cases.

It is a small speedup or slowdown in all testcases, with one exception: debug info. Since we were not doing the first pass for non alloc sections, this slows it down.

Linking scylla with debug info goes from 4.880429771 seconds to 5.623892311 seconds (gold is at 6.48).

The slowdown is regrettable, but I think we should do this as it is a big maintenance improvement. If the speed at which we handle debug info becomes an issue, we can special case non alloc sections by

  • Moving the body of scan reloc to a helper function/class that just stays which dynamic relocs/exprs it maps to.
  • For alloc sections, do it like now.
  • For non alloc sections, don't do the first scan and have relocate call the helper for each relocation and immediately relocate it.
ruiu accepted this revision.Apr 12 2016, 4:35 PM
ruiu edited edge metadata.

LGTM

The current way of handling relocation is too overloaded and hard to (or even impossible to) understand. This patch is toward the right direction.

We eventually want to have a separate function to apply relocations for non-alloc sections becasue non-alloc sections don't need these crazy number of decisions we make in scanRelocs. I believe that writing a separate function for non-alloc to directly apply relocations is fairly easy. So I consider the performance degradation caused by this change is rather temporary.

This revision is now accepted and ready to land.Apr 12 2016, 4:35 PM
grimar added inline comments.Apr 14 2016, 9:34 AM
ELF/Target.cpp
708

I think R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX should be here either.

Is this one ready to land?

ruiu closed this revision.Apr 21 2016, 2:44 PM

This has landed already as r266158.