https://sourceware.org/bugzilla/show_bug.cgi?id=31688
Bug ID: 31688 Summary: ld: Add SECTION_CLASS to allow separate section matching and referring Product: binutils Version: unspecified Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: i at maskray dot me Target Milestone: --- An input section description file_pattern(section_pattern) couples two operations: * "defining": match a subset of sections that have been been matched before * "referring": assign them to the current output section Roland McGrath has an idea that we can have a new syntax to separate the two operations. https://inbox.sourceware.org/binutils/CAB=4xhqkixyfsm1nqrbfojj6vd3tvyvk-ehb2oxm+64hf9x...@mail.gmail.com/ (https://sourceware.org/pipermail/binutils/2024-February/132344.html) SECTIONS { /* Traditional output section clause: */ .output1 { *(.input1) } /* New syntax that is not an output section clause: */ SECTION_CLASS(class1) { *(.input2) } /* Output section clause referring to SECTION_CLASS: */ .output2 { *(.input3) /* normal section wildcard */ SECTION_CLASS(class1) /* reference to previously defined class */ *(.input4) /* normal section wildcard */ } .output3 { SECTION_CLASS(class1) /* reference to remainder of class not in .output2 */ } .output4 { /* reference to remainder not in .output[23], sorting applied to them */ SORT_BY_NAME(SECTION_CLASS(class1)) } /* This cannot match anything that went into a SECTION_CLASS and orphans placement does not apply to them so it's an error if any SECTION_CLASS-matched input section has not been assigned to a previous output section. */ .output5 { *(*) } } This will also be useful to tidy the .text section, whose description is currently: .text : { *(.text.unlikely .text.*_unlikely .text.unlikely.*) *(.text.exit .text.exit.*) *(.text.startup .text.startup.*) *(.text.hot .text.hot.*) *(SORT(.text.sorted.*)) *(.text .stub .text.* .gnu.linkonce.t.*) /* .gnu.warning sections are handled specially by elf.em. */ *(.gnu.warning) } We have to place .text.unlikely/.text.startup/.text.hot before .text.* as otherwise .text.* would match all text sections and render .textXXXX patterns no-ops. With SECTION_CLASS, if a user wants to make .text.unlikely/.text.startup/.text.hot output sections (gold/ld.lld -z keep-text-section-prefix; allow a program to selectively place sections into hugepages) and if they want to place .text.startup/.text.hot after .text, they can use: SECTION_CLASS(text_startup) { *(.text.startup .text.startup.*) } SECTION_CLASS(text_hot) { *(.text.hot .text.hot.*) } .text : { *(.text .text.*) } .text.startup : { SECTION_CLASS(text_startup) } .text.hot : { SECTION_CLASS(text_hot) } -- You are receiving this mail because: You are on the CC list for the bug.