[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
+# PAD6: Hex dump of section '.text':
+# PAD6: 0x00201f48 cccccccc cccccccc cccccccc 0405cc06
+# PAD6: Hex dump of section '.data':
+# PAD6: 0x00203888 00000000 00000000 00000000 00000708
+# PAD6: 0x00203898 09
+
+## Size of segment offset padding and location of pre-section padding is
+## dependent on the seed.
+
+# RUN: ld.lld --randomize-section-padding=46 %t/a.o -o %t/a.out
+# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46 %s
+
+# PAD46: .rodata PROGBITS 0000000000200158 000158 000cc0 00 A 0 0 1
+# PAD46: .text PROGBITS 0000000000201e18 000e18 0009bf 00 AX 0 0 4
----------------
pcc wrote:
Done
https://github.com/llvm/llvm-project/pull/117653
More information about the llvm-commits
mailing list