This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Let linkerscript to use own outputsections factory.
AbandonedPublic

Authored by grimar on Aug 9 2016, 6:46 AM.

Details

Reviewers
ruiu
rafael
Summary

Currenly when linking FreeBSD kernel LLD produces 7 different .rodata sections because of difference
in attributes:

[ 6] .rodata           PROGBITS         ffffffff80c87c8c  00c86c8c
     00000000000e6e4d  0000000000000001 AMS       0     0     1
[ 7] .rodata           PROGBITS         ffffffff80d6eae0  00d6dae0
     0000000000246f00  0000000000000000   A       0     0     32
[ 8] .rodata           PROGBITS         ffffffff80fb59e0  00fb49e0
     00000000000001f0  0000000000000010  AM       0     0     16
[ 9] .rodata           PROGBITS         ffffffff80fb5bd0  00fb4bd0
     00000000000002a0  0000000000000004 AMS       0     0     16
[10] .rodata           PROGBITS         ffffffff80fb5e70  00fb4e70
     0000000000000108  0000000000000008  AM       0     0     8
[11] .rodata           PROGBITS         ffffffff80fb5f78  00fb4f78
     000000000000000c  0000000000000004 AMS       0     0     4
[12] .rodata           PROGBITS         ffffffff80fb5f88  00fb4f88
     0000000000001158  0000000000000001 AMS       0     0     8

At the same time ld produce only one. That probably means we need to use different logic for
creating output sections when do scripted layout.

Patch stops exporting regular output sections factory and introduces new one for using from
linker script side. That allowed to implement combining of output sections with different attributes.

Currently implemention does not support combine of SHT_MERGE sections with non-SHT_MERGE. But I believe
it should be not hard to implement basing on these new changes. One of possible way probably would be
to do scan of input sections to find out if there is a mix of "aM" vs "a" for example, and if so - do not create
megreable output section, but create regular one that should support adding mergeable input sections
as regular ones.

Diff Detail

Event Timeline

grimar updated this revision to Diff 67329.Aug 9 2016, 6:46 AM
grimar retitled this revision from to [ELF] - Separate common output sections factory from one that linkerscript uses..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, davide, evgeny777.
grimar retitled this revision from [ELF] - Separate common output sections factory from one that linkerscript uses. to [ELF] - Let linkerscript to use own outputsections factory..Aug 9 2016, 6:48 AM
grimar updated this revision to Diff 67332.Aug 9 2016, 6:56 AM
  • Cosmetic changes.
grimar updated this revision to Diff 67346.Aug 9 2016, 7:41 AM
  • Simplify LinkerScript<ELFT>::assignAddresses() (since this patch makes output sections to be unique by name,

there is no more need in loops like "for each section with this name... assign address")

ruiu edited edge metadata.Aug 9 2016, 11:21 AM

Is there any problem if we group sections just by name?

In D23315#510206, @ruiu wrote:

Is there any problem if we group sections just by name?

Do you mean group into one output section by name ? That is exactly what this patch do.
For linkerscript's OutputSectionFactory "key" is simple StringRef which is output section name.
And I combine the flags when add more sections.

Main change of this patch which do all logic is class OutputSectionFactory in LinkerScript.cpp.
All other changes mostly for moving default factory back to writer and for stop exporting it.

grimar updated this revision to Diff 67682.Aug 11 2016, 6:13 AM
grimar edited edge metadata.
  • Rebased.
grimar updated this revision to Diff 67683.Aug 11 2016, 6:31 AM
  • Cosmetic changes.
ruiu added a comment.Aug 11 2016, 2:51 PM

I do not see a benefit of doing this with a factory class. Actually I'm starting to regret to introduce the factory class to do this relatively simple things. We are doing too much object-oriented dance here. I believe this can be done just by a simple function.

grimar abandoned this revision.Aug 17 2016, 12:56 AM

Another patch was landed for this.