This is an archive of the discontinued LLVM Phabricator instance.

Skip scanRelocs for non-alloc sections.
ClosedPublic

Authored by ruiu on Apr 27 2016, 9:17 PM.

Details

Summary

Relocations against sections with no SHF_ALLOC bit are R_ABS relocations.
Currently we are creating Relocations vector for them, but that is wasteful.
This patch is to skip vector construction and to directly apply relocations
in place.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 55375.Apr 27 2016, 9:17 PM
ruiu retitled this revision from to Skip scanRelocs for non-alloc sections..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
rafael edited edge metadata.Apr 28 2016, 9:01 AM

I really like this. It is a lot simpler than what I was expecting.
But why the test changed?

ELF/InputSection.h
222 ↗(On Diff #55375)

Native?

ELF/Writer.cpp
535 ↗(On Diff #55375)

This is now always false.

test/ELF/relocation-non-alloc.s
36 ↗(On Diff #55375)

Is the change expected?

ruiu added inline comments.Apr 28 2016, 9:10 AM
ELF/InputSection.h
222 ↗(On Diff #55375)

Do you have any suggestions for better name?

test/ELF/relocation-non-alloc.s
36 ↗(On Diff #55375)

Yes. BFD and gold both produces this pattern rather than the old one. This is a test to produce a DSO file with a non-alloc section pointing to an interruptible symbol. This seems to be unrealistic test case. LLD previously handle interruptible symbols addresses as 0 because it can change at runtime, but GNU linkers don't seem to bother it.

rafael accepted this revision.Apr 28 2016, 10:02 AM
rafael edited edge metadata.

LGTM with the name changed and the IsAlloc bool replaced with false.

ELF/InputSection.cpp
230 ↗(On Diff #55375)

Debug section is -> Debug sections are.

ELF/InputSection.h
222 ↗(On Diff #55375)

Maybe just relocateNonAlloc?

test/ELF/relocation-non-alloc.s
36 ↗(On Diff #55375)

OK, I think I see what is going on.

For preemptable symbols in alloc sections we have to create a dynamic relocation. Having created one, we know the dynamic linker will take care of everything and we don't need to do anything else.

I am not sure if these show up in practice in non alloc sections, but it seems reasonable to have them point to the symbol in the file we are producing since there will be no dynamic relocation.

This revision is now accepted and ready to land.Apr 28 2016, 10:02 AM
ruiu added a comment.Apr 28 2016, 11:39 AM

So, this patch seems to be pretty effective for large executables with debug info. r266158 (Rafael's patch to change the way how we apply relocations) caused a temporary performance degradation for such executables, but this patch makes it even faster than before.

Time to link clang with debug info (output size is 1070 MB):

before r266158: 15.312 seconds (0%)
r266158:        17.301 seconds (+13.0%)
Head:           16.484 seconds (+7.7%)
w/patch:        13.166 seconds (-14.0%)
This revision was automatically updated to reflect the committed changes.