This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Use output section prediction when creating mergeable synthetic sections.
AbandonedPublic

Authored by grimar on Sep 25 2018, 4:56 AM.

Details

Summary

We have a bug "Section merge should match the rules specified in the linker script." (https://bugs.llvm.org//show_bug.cgi?id=38748).
Which says that LLD is unable to handle the following code correctly:

SECTIONS {
  .rodata_fooSec : { *(.rodata.foo) }
  .rodata_barSec : { *(.rodata.bar) }
}

We know about that and it happens because we create mergeable synthetic sections very early, before
parsing the linker script. That allows us to keep the whole linker logic simpler.
I would try not to change that.

What I suggest to do in this patch is to use output section prediction
and do not merge together sections which are going to be placed into different output sections.
That fixes the bug.

Also that fixes merge_sections.s. It turns out currently we missed merging optimization and this patch
fixes it either. That happened because we used output section name for a synthetic section. And script
instructions did not match it. This patch uses the name of the first input section as a name for synthetic
section instead.

There is a room for optimizations can be done here, I would like to see the feedback about the approach first.

Diff Detail

Event Timeline

grimar created this revision.Sep 25 2018, 4:56 AM
ruiu added a comment.Sep 25 2018, 6:59 AM

It sounds like a good idea, but still I don't think we want this much complexity. Linker script is a can of warms, and unfortunately it's already half-open in lld, but I'd still like to make an effort push it back to keep the code manageable. If more people come in and claim that they really need this, I'd consider that, but for now the code simplicity seems more important than satisfying the long-tail need.

Filename matching seems not to be considered in this patch.

A test case for your reference.

SECTIONS {
.rodata_A : { a.o(.rodata.foo) }
.rodata_B : { b.o(.rodata.foo) }
}

Filename matching seems not to be considered in this patch.

A test case for your reference.

SECTIONS {
.rodata_A : { a.o(.rodata.foo) }
.rodata_B : { b.o(.rodata.foo) }
}

Yes, it was not the intention to support it here. Filename matching should be
not hard to do with this approach though.

grimar abandoned this revision.Aug 2 2019, 4:46 AM

Too old.