|
| 1 | +# REQUIRES: x86 |
| 2 | + |
| 3 | +# RUN: rm -rf %t && split-file %s %t && cd %t |
| 4 | + |
| 5 | +# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o |
| 6 | + |
| 7 | +# RUN: ld.lld -z keep-data-section-prefix -T x.lds a.o -o out1 |
| 8 | +# RUN: llvm-readelf -l out1 | FileCheck --check-prefixes=SEG,LS %s |
| 9 | +# RUN: llvm-readelf -S out1 | FileCheck %s --check-prefix=CHECK-LS |
| 10 | + |
| 11 | +# RUN: ld.lld -z keep-data-section-prefix a.o -o out2 |
| 12 | +# RUN: llvm-readelf -l out2 | FileCheck --check-prefixes=SEG,PRE %s |
| 13 | +# RUN: llvm-readelf -S out2 | FileCheck %s --check-prefix=CHECK-PRE |
| 14 | + |
| 15 | +# RUN: ld.lld a.o -o out3 |
| 16 | +# RUN: llvm-readelf -l out3 | FileCheck --check-prefixes=SEG,PRE %s |
| 17 | +# RUN: llvm-readelf -S out3 | FileCheck %s --check-prefix=CHECK-PRE |
| 18 | + |
| 19 | +# RUN: not ld.lld -T x.lds a.o 2>&1 | FileCheck %s |
| 20 | +# CHECK: error: section: .relro_padding is not contiguous with other relro sections |
| 21 | + |
| 22 | +## The first RW PT_LOAD segment has FileSiz 0x126f (0x1000 + 0x200 + 0x60 + 0xf), |
| 23 | +## and its p_offset p_vaddr p_paddr p_filesz should match PT_GNU_RELRO. |
| 24 | +# Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align |
| 25 | +# SEG: LOAD 0x0001c8 0x00000000002011c8 0x00000000002011c8 0x000001 0x000001 R E 0x1000 |
| 26 | +# SEG-NEXT: LOAD 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x00126f 0x001e37 RW 0x1000 |
| 27 | +# SEG-NEXT: LOAD 0x001438 0x0000000000204438 0x0000000000204438 0x000001 0x000002 RW 0x1000 |
| 28 | +# SEG-NEXT: GNU_RELRO 0x0001c9 0x00000000002021c9 0x00000000002021c9 0x00126f 0x001e37 R 0x1 |
| 29 | +# SEG-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0 |
| 30 | + |
| 31 | +## Input to output mapping per linker script |
| 32 | +## .data.rel.ro.split -> .data.rel.ro |
| 33 | +## .data.rel.ro -> .data.rel.ro |
| 34 | +## .data.rel.ro.hot -> .data.rel.ro.hot |
| 35 | +## .data.rel.ro.unlikely -> .data.rel.ro.unlikely |
| 36 | +# LS: .text |
| 37 | +# LS-NEXT: .data.rel.ro.hot .data.rel.ro .data.rel.ro.unlikely .relro_padding |
| 38 | +# LS-NEXT: .data .bss |
| 39 | + |
| 40 | +# [Nr] Name Type Address Off Size |
| 41 | +# CHECK-LS: .data.rel.ro.hot PROGBITS 00000000002021c9 0001c9 00000f |
| 42 | +# CHECK-LS-NEXT: .data.rel.ro PROGBITS 00000000002021d8 0001d8 000260 |
| 43 | +# CHECK-LS-NEXT: .data.rel.ro.unlikely PROGBITS 0000000000202438 000438 001000 |
| 44 | +# CHECK-LS-NEXT: .relro_padding NOBITS 0000000000203438 001438 000bc8 |
| 45 | +# CHECK-LS-NEXT: .data PROGBITS 0000000000204438 001438 000001 |
| 46 | +# CHECK-LS-NEXT: .bss NOBITS 0000000000204439 001439 000001 |
| 47 | + |
| 48 | +## Linker script is not provided to map data sections. |
| 49 | +## So all input sections with prefix .data.rel.ro will map to .data.rel.ro in the output. |
| 50 | +# PRE: .text |
| 51 | +# PRE-NEXT: .data.rel.ro .relro_padding |
| 52 | +# PRE-NEXT: .data .bss |
| 53 | + |
| 54 | +# [Nr] Name Type Address Off Size |
| 55 | +# CHECK-PRE: .data.rel.ro PROGBITS 00000000002021c9 0001c9 00126f |
| 56 | +# CHECK-PRE-NEXT: .relro_padding NOBITS 0000000000203438 001438 000bc8 |
| 57 | +# CHECK-PRE-NEXT: .data PROGBITS 0000000000204438 001438 000001 |
| 58 | +# CHECK-PRE-NEXT: .bss NOBITS 0000000000204439 001439 000001 |
| 59 | + |
| 60 | +#--- x.lds |
| 61 | +SECTIONS { |
| 62 | + .data.rel.ro.hot : { *(.data.rel.ro.hot) } |
| 63 | + .data.rel.ro : { .data.rel.ro } |
| 64 | + .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely) } |
| 65 | +} INSERT AFTER .text |
| 66 | + |
| 67 | + |
| 68 | +#--- a.s |
| 69 | +.globl _start |
| 70 | +_start: |
| 71 | + ret |
| 72 | + |
| 73 | +.section .data.rel.ro.hot, "aw" |
| 74 | +.space 15 |
| 75 | + |
| 76 | +.section .data.rel.ro, "aw" |
| 77 | +.space 96 |
| 78 | + |
| 79 | +.section .data.rel.ro.split,"aw" |
| 80 | +.space 512 |
| 81 | + |
| 82 | +.section .data.rel.ro.unlikely, "aw" |
| 83 | +.space 4096 |
| 84 | + |
| 85 | +.section .data, "aw" |
| 86 | +.space 1 |
| 87 | + |
| 88 | +.section .bss, "aw" |
| 89 | +.space 1 |
0 commit comments