close
Skip to content

Support shf link order#1085

Draft
quic-seaswara wants to merge 2 commits intomainfrom
support_shf_link_order
Draft

Support shf link order#1085
quic-seaswara wants to merge 2 commits intomainfrom
support_shf_link_order

Conversation

@quic-seaswara
Copy link
Copy Markdown
Contributor

No description provided.

Be consistent across partial link, GC, and COMDAT.

User-visible improvements:
- Garbage collection now consistently follows dependencies
through sh_link, so dependent link-order sections are kept
or removed together with their target sections.

- COMDAT resolution now drops SHF_LINK_ORDER members from
discarded duplicate groups.

- Output ordering and linker map ordering for link-order
sections are validated to stay aligned.

- User guide documentation now explains SHF_LINK_ORDER
behavior for partial linking, garbage collection, and linker
scripts.

Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
- Adds --trace=link-order to print SHF_LINK_ORDER
dependencies.

- Adds --trace=discard-sections to print why sections were
discarded.

- Extends --trace=garbage-collection and --trace=live-edges
to show SHF_LINK_ORDER dependency edges in reachability
output.

- Explicit /DISCARD/ of link-order sections.

- Discard of SHF_LINK_ORDER dependents when their linked
parent section is discarded.

- Link-order edge visibility in live-edge tracing output.

Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
@quic-seaswara quic-seaswara requested a review from parth-07 April 21, 2026 01:06
@quic-areg
Copy link
Copy Markdown
Contributor

This PR is quite difficult to review because it bundles several independent changes. The core SHF_LINK_ORDER functionality should be split from the additions to existing --trace options, at least.

The new lit %standalone_inputs lit substitution introduced exclusively for these tests feels awkward and unnecessary, and introduces a convention used nowhere else in the test suite. The assembler-with-cpp +#include asm_section_type_macros.h + %standalone_inputs chain is unnecessary. It seems like this was added because @progbits syntax is not accepted on arm. %progbits should be accepted by all targets and allow us to remove all of these new constructions.

Functionality-wise, eld seems to allow what lld and bfd reject:

cat > 1.s << \!
.section .text.foo,"ax",%progbits
.globl foo
foo:
  .word 0

.section .text.bar,"ax",%progbits
.globl bar
bar:
  .word 0

.section .meta.bar,"ao",%progbits,.text.bar
.globl meta_bar
meta_bar:
  .word 0xBBBB

.text
.globl _start
_start:
  .word foo
  .word meta_bar
!

llvm-mc -filetype=obj -triple=aarch64-linux 1.s -o 1.o
ld.eld --gc-sections -e _start 1.o -o e.out
ld.lld --gc-sections -e _start 1.o -o l.out
/usr/bin/aarch64-linux-gnu-ld --gc-sections -e _start 1.o -o g.out
-ld.eld --gc-sections -e _start 1.o -o e.out
ld.lld --gc-sections -e _start 1.o -o l.out
+ld.lld: error: 1.o:(.meta.bar): sh_link points to discarded section 1.o:(.text.bar)
/usr/bin/aarch64-linux-gnu-ld --gc-sections -e _start 1.o -o g.out
+`meta_bar' referenced in section `.text' of 1.o: defined in discarded section `.meta.bar' of 1.o

I have other comments, but this should do for now.

@quic-seaswara
Copy link
Copy Markdown
Contributor Author

Thanks for the review!. I will create a seperate PR for tracing diagnostics. Will remove asm-helper, good to know %progbits is accepted by all targets.

@quic-seaswara quic-seaswara marked this pull request as draft April 21, 2026 20:51
@quic-seaswara quic-seaswara requested a review from quic-areg April 21, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants