[lld] ELF: Introduce --randomize-section-padding option. (PR #117653)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 18:30:36 PST 2024
================
@@ -0,0 +1,125 @@
+# REQUIRES: x86
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
+
+## --randomize-section-padding= inserts segment offset padding and pre-section
+## padding, and does not affect flags. Segment offset padding is only inserted
+## when PT_LOAD changes, as shown by .bss size (.data and .bss share a PT_LOAD).
+
+# RUN: ld.lld --randomize-section-padding=6 %t/a.o -o %t/a.out
+# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD6 %s
+
+# PAD6: .rodata PROGBITS 0000000000200158 000158 000b8d 00 A 0 0 1
+# PAD6: .text PROGBITS 0000000000201ce8 000ce8 000270 00 AX 0 0 4
+# PAD6: .data PROGBITS 0000000000202f58 000f58 000941 00 WA 0 0 1
+# PAD6: .bss NOBITS 0000000000203899 001899 000003 00 WA 0 0 1
+
+# PAD6: 0000000000203899 0 NOTYPE LOCAL DEFAULT 4 a
+# PAD6: 000000000020389a 0 NOTYPE LOCAL DEFAULT 4 b
+# PAD6: 000000000020389b 0 NOTYPE LOCAL DEFAULT 4 c
+
+# PAD6: Hex dump of section '.rodata':
+# PAD6: 0x00200cd8 00000000 00000000 00000102 03
----------------
pcc wrote:
This one can't use -NEXT (at least not without a lot of boilerplate) because it is preceded by this:
```
Hex dump of section '.rodata':
0x00200158 00000000 00000000 00000000 00000000 ................
0x00200168 00000000 00000000 00000000 00000000 ................
0x00200178 00000000 00000000 00000000 00000000 ................
0x00200188 00000000 00000000 00000000 00000000 ................
0x00200198 00000000 00000000 00000000 00000000 ................
0x002001a8 00000000 00000000 00000000 00000000 ................
...
```
https://github.com/llvm/llvm-project/pull/117653
More information about the llvm-commits
mailing list