Page MenuHomePhabricator

[ELF] Allow SHF_LINK_ORDER sections to have sh_link=0
Needs ReviewPublic

Authored by MaskRay on Jan 17 2020, 9:01 AM.

Details

Summary

Part of https://bugs.llvm.org/show_bug.cgi?id=41734

The semantics of SHF_LINK_ORDER have been extended to represent metadata
sections associated with some other sections (usually text).

The associated text section may be discarded (e.g. LTO) and we want the
metadata section to have sh_link=0 (D72899).

Normally the metadata section is only referenced by the associated text
section. sh_link=0 means the associated text section is discarded, and
the metadata section will be garbage collected. If there is another
section (.gc_root) referencing the metadata section, the metadata
section will be retained. It's the .gc_root consumer's job to validate
the metadata sections.

.section .meta,"awo",@progbits,,unique,0
1:
.section .meta,"awo",@progbits,foo,unique,1
2:

.section .gc_root,"a",@progbits
.quad 1b
.quad 2b

Diff Detail

Unit TestsFailed

TimeTest
350 msLLVM-Unit.TableGen/_/TableGenTests::Automata.BinPackerAutomatonAccepts
Note: Google Test filter = Automata.BinPackerAutomatonAccepts [==========] Running 1 test from 1 test case. [----------] Global test environment set-up.
350 msLLVM-Unit.TableGen/_/TableGenTests::Automata.BinPackerAutomatonExplains
Note: Google Test filter = Automata.BinPackerAutomatonExplains [==========] Running 1 test from 1 test case. [----------] Global test environment set-up.

Event Timeline

MaskRay created this revision.Jan 17 2020, 9:01 AM

Unit tests: fail. 61935 tests passed, 2 failed and 783 were skipped.

failed: LLVM-Unit.TableGen/_/TableGenTests/Automata.BinPackerAutomatonAccepts
failed: LLVM-Unit.TableGen/_/TableGenTests/Automata.BinPackerAutomatonExplains

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

I'm reluctantly in favour of making the change on the basis that there exists a design using SHF_LINKORDER that lets this happen. My reservation is that in some use cases of SHF_LINKORDER such as .ARM.exidx sections where there is a 1 : 1 relationship between meta-data and "content" (for want of a better word) section then sh_link = 0 would be a sign that something had gone badly wrong. Having said that there isn't any thing in ELF that forbids the use case that this needs. I think that for .ARM.exidx which is the other main user of SHF_LINKORDER we handle it as a special case so this shouldn't make a difference in practice.

Reverse-ping, thanks.

pcc added a comment.Jun 3 2020, 6:09 PM

Should we drop this and just let users set sh_link=self if they want these semantics?

phosek added a subscriber: phosek.Thu, Jun 11, 3:57 AM
In D72904#2071861, @pcc wrote:

Should we drop this and just let users set sh_link=self if they want these semantics?

One issue I ran into while trying to use sh_link=self in D76802 is that bfd.ld doesn't seem to handle that case: older versions of bfd.ld report an error while the tip-of-tree version hits an infinite loop.