|
| 1 | +# REQUIRES: x86 |
| 2 | +# RUN: split-file %s %t |
| 3 | +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o |
| 4 | + |
| 5 | +## --randomize-section-padding= inserts segment offset padding and pre-section |
| 6 | +## padding, and does not affect flags. Segment offset padding is only inserted |
| 7 | +## when PT_LOAD changes, as shown by .bss size (.data and .bss share a PT_LOAD). |
| 8 | + |
| 9 | +# RUN: ld.lld --randomize-section-padding=6 %t/a.o -o %t/a.out |
| 10 | +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD6 %s |
| 11 | + |
| 12 | +# PAD6: .rodata PROGBITS 0000000000200158 000158 000b8d 00 A 0 0 1 |
| 13 | +# PAD6-NEXT: .text PROGBITS 0000000000201ce8 000ce8 000270 00 AX 0 0 4 |
| 14 | +# PAD6-NEXT: .data PROGBITS 0000000000202f58 000f58 000941 00 WA 0 0 1 |
| 15 | +# PAD6-NEXT: .bss NOBITS 0000000000203899 001899 000003 00 WA 0 0 1 |
| 16 | + |
| 17 | +# PAD6: 0000000000203899 0 NOTYPE LOCAL DEFAULT 4 a |
| 18 | +# PAD6: 000000000020389a 0 NOTYPE LOCAL DEFAULT 4 b |
| 19 | +# PAD6: 000000000020389b 0 NOTYPE LOCAL DEFAULT 4 c |
| 20 | + |
| 21 | +# PAD6: Hex dump of section '.rodata': |
| 22 | +# PAD6: 0x00200cd8 00000000 00000000 00000102 03 |
| 23 | +# PAD6: Hex dump of section '.text': |
| 24 | +# PAD6: 0x00201f48 cccccccc cccccccc cccccccc 0405cc06 |
| 25 | +# PAD6: Hex dump of section '.data': |
| 26 | +# PAD6: 0x00203888 00000000 00000000 00000000 00000708 |
| 27 | +# PAD6: 0x00203898 09 |
| 28 | + |
| 29 | +## Size of segment offset padding and location of pre-section padding is |
| 30 | +## dependent on the seed. |
| 31 | + |
| 32 | +# RUN: ld.lld --randomize-section-padding=46 %t/a.o -o %t/a.out |
| 33 | +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46 %s |
| 34 | + |
| 35 | +# PAD46: .rodata PROGBITS 0000000000200158 000158 000cc0 00 A 0 0 1 |
| 36 | +# PAD46-NEXT: .text PROGBITS 0000000000201e18 000e18 0009bf 00 AX 0 0 4 |
| 37 | +# PAD46-NEXT: .data PROGBITS 00000000002037d7 0017d7 000540 00 WA 0 0 1 |
| 38 | +# PAD46-NEXT: .bss NOBITS 0000000000203d17 001d17 000004 00 WA 0 0 1 |
| 39 | + |
| 40 | +# PAD46: 0000000000203d17 0 NOTYPE LOCAL DEFAULT 4 a |
| 41 | +# PAD46: 0000000000203d18 0 NOTYPE LOCAL DEFAULT 4 b |
| 42 | +# PAD46: 0000000000203d1a 0 NOTYPE LOCAL DEFAULT 4 c |
| 43 | + |
| 44 | +# PAD46: Hex dump of section '.rodata': |
| 45 | +# PAD46: 0x00200e08 00000000 00000000 00000000 00010203 |
| 46 | +# PAD46: Hex dump of section '.text': |
| 47 | +# PAD46: 0x002027c8 cccccccc cccccccc cccccccc 040506 |
| 48 | +# PAD46: Hex dump of section '.data': |
| 49 | +# PAD46: 0x00203d07 00000000 00000000 00000000 07000809 |
| 50 | + |
| 51 | +## When there are multiple InputSectionDescriptions for an output section, |
| 52 | +## segment offset padding is inserted in the first InputSectionDescription. |
| 53 | + |
| 54 | +# RUN: ld.lld --randomize-section-padding=46 %t/a.o %t/a.lds -o %t/a.out |
| 55 | + |
| 56 | +# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46-LDS %s |
| 57 | + |
| 58 | +# PAD46-LDS: .rodata PROGBITS 0000000000000158 000158 000cc0 00 A 0 0 1 |
| 59 | +# PAD46-LDS-NEXT: .text PROGBITS 0000000000001000 001000 0009c0 00 AX 0 0 4 |
| 60 | +# PAD46-LDS-NEXT: .data PROGBITS 0000000000002000 002000 000540 00 WA 0 0 1 |
| 61 | +# PAD46-LDS-NEXT: .bss NOBITS 0000000000002540 002540 000004 00 WA 0 0 1 |
| 62 | + |
| 63 | +# PAD46-LDS: 0000000000002543 0 NOTYPE LOCAL DEFAULT 4 a |
| 64 | +# PAD46-LDS: 0000000000002541 0 NOTYPE LOCAL DEFAULT 4 b |
| 65 | +# PAD46-LDS: 0000000000002540 0 NOTYPE LOCAL DEFAULT 4 c |
| 66 | + |
| 67 | +# PAD46-LDS: Hex dump of section '.rodata': |
| 68 | +# PAD46-LDS: 0x00000e08 00000000 00000000 00000000 00030201 ................ |
| 69 | +# PAD46-LDS: Hex dump of section '.text': |
| 70 | +# PAD46-LDS: 0x000019b0 cccccccc cccccccc cccc0605 04cccccc ................ |
| 71 | +# PAD46-LDS: Hex dump of section '.data': |
| 72 | +# PAD46-LDS: 0x00002530 00000000 00000000 00000000 09000807 ................ |
| 73 | + |
| 74 | +#--- a.s |
| 75 | + |
| 76 | +.section .rodata.a,"a",@progbits |
| 77 | +.byte 1 |
| 78 | + |
| 79 | +.section .rodata.b,"a",@progbits |
| 80 | +.byte 2 |
| 81 | + |
| 82 | +.section .rodata.c,"a",@progbits |
| 83 | +.byte 3 |
| 84 | + |
| 85 | +.section .text.a,"ax",@progbits |
| 86 | +.byte 4 |
| 87 | + |
| 88 | +.section .text.b,"ax",@progbits |
| 89 | +.byte 5 |
| 90 | + |
| 91 | +.section .text.c,"ax",@progbits |
| 92 | +.byte 6 |
| 93 | + |
| 94 | +.section .data.a,"aw",@progbits |
| 95 | +.byte 7 |
| 96 | + |
| 97 | +.section .data.b,"aw",@progbits |
| 98 | +.byte 8 |
| 99 | + |
| 100 | +.section .data.c,"aw",@progbits |
| 101 | +.byte 9 |
| 102 | + |
| 103 | +.section .bss.a,"a",@nobits |
| 104 | +a: |
| 105 | +.zero 1 |
| 106 | + |
| 107 | +.section .bss.b,"a",@nobits |
| 108 | +b: |
| 109 | +.zero 1 |
| 110 | + |
| 111 | +.section .bss.c,"a",@nobits |
| 112 | +c: |
| 113 | +.zero 1 |
| 114 | + |
| 115 | +#--- a.lds |
| 116 | + |
| 117 | +SECTIONS { |
| 118 | + . = SIZEOF_HEADERS; |
| 119 | + .rodata : { *(.rodata.c) *(.rodata.b) *(.rodata.a) } |
| 120 | + . = ALIGN(CONSTANT(MAXPAGESIZE)); |
| 121 | + .text : { *(.text.c) *(.text.b) *(.text.a) } |
| 122 | + . = ALIGN(CONSTANT(MAXPAGESIZE)); |
| 123 | + .data : { *(.data.c) *(.data.b) *(.data.a) } |
| 124 | + .bss : { *(.bss.c) *(.bss.b) *(.bss.a) } |
| 125 | +} |
0 commit comments