|
| 1 | +# REQUIRES: x86 |
| 2 | +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o |
| 3 | + |
| 4 | +## --randomize-section-padding= inserts segment offset padding and pre-section |
| 5 | +## padding, and does not affect flags. Segment offset padding is only inserted |
| 6 | +## when PT_LOAD changes, as shown by .bss size (.data and .bss share a PT_LOAD). |
| 7 | + |
| 8 | +# RUN: ld.lld --randomize-section-padding=6 %t.o -o %t.out |
| 9 | +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t.out | FileCheck --check-prefix=PAD6 %s |
| 10 | + |
| 11 | +# PAD6: .rodata PROGBITS 0000000000200158 000158 000b8d 00 A 0 0 1 |
| 12 | +# PAD6: .text PROGBITS 0000000000201ce8 000ce8 000270 00 AX 0 0 4 |
| 13 | +# PAD6: .data PROGBITS 0000000000202f58 000f58 000941 00 WA 0 0 1 |
| 14 | +# PAD6: .bss NOBITS 0000000000203899 001899 000003 00 WA 0 0 1 |
| 15 | + |
| 16 | +# PAD6: 0000000000203899 0 NOTYPE LOCAL DEFAULT 4 a |
| 17 | +# PAD6: 000000000020389a 0 NOTYPE LOCAL DEFAULT 4 b |
| 18 | +# PAD6: 000000000020389b 0 NOTYPE LOCAL DEFAULT 4 c |
| 19 | + |
| 20 | +# PAD6: Hex dump of section '.rodata': |
| 21 | +# PAD6: 0x00200cd8 00000000 00000000 00000102 03 |
| 22 | +# PAD6: Hex dump of section '.text': |
| 23 | +# PAD6: 0x00201f48 cccccccc cccccccc cccccccc 0405cc06 |
| 24 | +# PAD6: Hex dump of section '.data': |
| 25 | +# PAD6: 0x00203888 00000000 00000000 00000000 00000708 |
| 26 | +# PAD6: 0x00203898 09 |
| 27 | + |
| 28 | +## Size of segment offset padding and location of pre-section padding is |
| 29 | +## dependent on the seed. |
| 30 | + |
| 31 | +# RUN: ld.lld --randomize-section-padding=46 %t.o -o %t.out |
| 32 | +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t.out | FileCheck --check-prefix=PAD46 %s |
| 33 | + |
| 34 | +# PAD46: .rodata PROGBITS 0000000000200158 000158 000cc0 00 A 0 0 1 |
| 35 | +# PAD46: .text PROGBITS 0000000000201e18 000e18 0009bf 00 AX 0 0 4 |
| 36 | +# PAD46: .data PROGBITS 00000000002037d7 0017d7 000540 00 WA 0 0 1 |
| 37 | +# PAD46: .bss NOBITS 0000000000203d17 001d17 000004 00 WA 0 0 1 |
| 38 | + |
| 39 | +# PAD46: 0000000000203d17 0 NOTYPE LOCAL DEFAULT 4 a |
| 40 | +# PAD46: 0000000000203d18 0 NOTYPE LOCAL DEFAULT 4 b |
| 41 | +# PAD46: 0000000000203d1a 0 NOTYPE LOCAL DEFAULT 4 c |
| 42 | + |
| 43 | +# PAD46: Hex dump of section '.rodata': |
| 44 | +# PAD46: 0x00200e08 00000000 00000000 00000000 00010203 |
| 45 | +# PAD46: Hex dump of section '.text': |
| 46 | +# PAD46: 0x002027c8 cccccccc cccccccc cccccccc 040506 |
| 47 | +# PAD46: Hex dump of section '.data': |
| 48 | +# PAD46: 0x00203d07 00000000 00000000 00000000 07000809 |
| 49 | + |
| 50 | +.section .rodata.a,"a",@progbits |
| 51 | +.byte 1 |
| 52 | + |
| 53 | +.section .rodata.b,"a",@progbits |
| 54 | +.byte 2 |
| 55 | + |
| 56 | +.section .rodata.c,"a",@progbits |
| 57 | +.byte 3 |
| 58 | + |
| 59 | +.section .text.a,"ax",@progbits |
| 60 | +.byte 4 |
| 61 | + |
| 62 | +.section .text.b,"ax",@progbits |
| 63 | +.byte 5 |
| 64 | + |
| 65 | +.section .text.c,"ax",@progbits |
| 66 | +.byte 6 |
| 67 | + |
| 68 | +.section .data.a,"aw",@progbits |
| 69 | +.byte 7 |
| 70 | + |
| 71 | +.section .data.b,"aw",@progbits |
| 72 | +.byte 8 |
| 73 | + |
| 74 | +.section .data.c,"aw",@progbits |
| 75 | +.byte 9 |
| 76 | + |
| 77 | +.section .bss.a,"a",@nobits |
| 78 | +a: |
| 79 | +.zero 1 |
| 80 | + |
| 81 | +.section .bss.b,"a",@nobits |
| 82 | +b: |
| 83 | +.zero 1 |
| 84 | + |
| 85 | +.section .bss.c,"a",@nobits |
| 86 | +c: |
| 87 | +.zero 1 |
| 88 | + |
0 commit comments