Skip to content

[BOLT,test] Make linker scripts less sensitive to lld's orphan placement #93763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented May 30, 2024

Then two tests rely on .interp being the first section.
llvm-bolt would crash if lld places .interp after .got
(f639b57).

For best portability, when a linker scripts specifies a SECTIONS
command, the first section for each PT_LOAD segment should be specified
with a MAXPAGESIZE alignment. Otherwise, linkers have freedom to decide
how to place orphan sections, which might break intention.

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented May 30, 2024

@llvm/pr-subscribers-bolt

Author: Fangrui Song (MaskRay)

Changes

Then two tests rely on .interp being the first section.
llvm-bolt would crash if lld places .interp after .got
(f639b57).

For best portability, when a linker scripts specifies a SECTIONS
command, the first section for each PT_LOAD segment should be specified
with a MAXPAGESIZE alignment. Otherwise, linkers have freedom to decide
how to place orphan sections, which might break intention.


Full diff: https://github.com/llvm/llvm-project/pull/93763.diff

2 Files Affected:

  • (modified) bolt/test/AArch64/Inputs/array_end.lld_script (+3)
  • (modified) bolt/test/Inputs/lsda.ldscript (+3)
diff --git a/bolt/test/AArch64/Inputs/array_end.lld_script b/bolt/test/AArch64/Inputs/array_end.lld_script
index 182c13d370a39..bf77c0493a095 100644
--- a/bolt/test/AArch64/Inputs/array_end.lld_script
+++ b/bolt/test/AArch64/Inputs/array_end.lld_script
@@ -1,4 +1,7 @@
 SECTIONS {
+  .interp : { *(.interp) }
+
+  . = ALIGN(CONSTANT(MAXPAGESIZE));
   .fini_array    :
   {
     PROVIDE_HIDDEN (__fini_array_start = .);
diff --git a/bolt/test/Inputs/lsda.ldscript b/bolt/test/Inputs/lsda.ldscript
index aa608ecd97e8c..011e0c6ac8a0f 100644
--- a/bolt/test/Inputs/lsda.ldscript
+++ b/bolt/test/Inputs/lsda.ldscript
@@ -1,5 +1,8 @@
 SECTIONS {
+  .interp : { *(.interp) }
+  . = ALIGN(CONSTANT(MAXPAGESIZE));
   .text : { *(.text*) }
+  . = ALIGN(CONSTANT(MAXPAGESIZE));
   .gcc_except_table.main : { *(.gcc_except_table*) }
   . = 0x20000;
   .eh_frame : { *(.eh_frame) }

Copy link
Member

@yota9 yota9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ayermolo
Copy link
Contributor

thanks!

@MaskRay MaskRay merged commit ce5b371 into main May 30, 2024
8 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/bolttest-make-linker-scripts-less-sensitive-to-llds-orphan-placement branch May 30, 2024 17:12
MaskRay added a commit that referenced this pull request May 30, 2024
Follow-up to a previous simplification
2473b1a.

The xor difference between a SHT_NOTE and a read-only SHT_PROGBITS
(previously >=NOT_SPECIAL) should be smaller than RF_EXEC. Otherwise,
for the following section layout, `findOrphanPos` would place .text
before note.

```
// simplified from linkerscript/custom-section-type.s
non orphans:
progbits 0x8060c00 NOT_SPECIAL
note     0x8040003

orphan:
.text    0x8061000 NOT_SPECIAL
```

rw-text.lds in orphan.s (added by
73e07e9) demonstrates a similar case.
The new behavior is more similar to GNU ld.

#93763 fixed BOLT's brittle reliance on the previous .interp behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants