1# REQUIRES: x86 2# RUN: rm -rf %t && split-file %s %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o 4# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/shared.s -o %t/b.o 5# RUN: ld.lld -shared -soname=b %t/b.o -o %t/b.so 6 7## With relro or without DATA_SEGMENT_RELRO_END just aligns to 8## page boundary. 9 10# RUN: ld.lld --hash-style=sysv -z norelro %t/a.o %t/b.so -T %t/1.t -o %t/a1 11# RUN: llvm-readelf -S -l %t/a1 | FileCheck %s --check-prefixes=CHECK,CHECK1 12 13# RUN: ld.lld --hash-style=sysv -z relro %t/a.o %t/b.so -T %t/1.t -o %t/a2 14# RUN: llvm-readelf -S -l %t/a2 | FileCheck %s --check-prefixes=CHECK,CHECK2 15 16# CHECK: Name Type Address Off Size ES Flg 17# CHECK-NEXT: NULL {{.*}} 18# CHECK: .orphan.ro PROGBITS {{.*}} A 19# CHECK: .dynamic DYNAMIC {{.*}} WA 20# CHECK-NEXT: __libc_atexit PROGBITS {{.*}} WA 21# CHECK-NEXT: .got PROGBITS {{.*}} WA 22# CHECK-NEXT: .got.plt PROGBITS {{.*}} WA 23# CHECK: .orphan.rw PROGBITS {{.*}} WA 24 25# CHECK1: Program Headers: 26# CHECK1-NOT: GNU_RELRO 27 28# CHECK2: Program Headers: 29# CHECK2-NEXT: Type 30# CHECK2-NEXT: PHDR 31# CHECK2-NEXT: LOAD 32# CHECK2-NEXT: LOAD 33# CHECK2-NEXT: LOAD 34# CHECK2-NEXT: LOAD 35# CHECK2-NEXT: DYNAMIC 36# CHECK2-NEXT: GNU_RELRO 37# CHECK2-NEXT: GNU_STACK 38 39# CHECK2: Section to Segment mapping: 40# CHECK2: 06 .dynamic __libc_atexit .got {{$}} 41 42# RUN: sed '/DATA_SEGMENT_RELRO_END/d' %t/1.t > %t/2.t 43# RUN: not ld.lld %t/a.o %t/b.so -T %t/2.t -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR 44 45# ERR: error: section: .got is not contiguous with other relro sections 46 47#--- a.s 48.global _start 49_start: 50 .long bar 51 jmp *bar2@GOTPCREL(%rip) 52 53.section .data,"aw" 54.quad 0 55 56.zero 4 57.section .foo,"aw" 58.section .bss,"",@nobits 59 60.section __libc_atexit,"aw",@progbits 61.dc.a __libc_atexit 62 63.section .orphan.ro,"a",@progbits 64.dc.a 0 65 66.section .orphan.rw,"aw",@progbits 67.dc.a .orphan.rw 68 69#--- 1.t 70SECTIONS { 71 . = SIZEOF_HEADERS; 72 73 .plt : { *(.plt) } 74 .text : { *(.text) } 75 76 . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); 77 78 .dynamic : { *(.dynamic) } 79 ## The custom section __libc_atexit is made relro. 80 __libc_atexit : { *(__libc_atexit) } 81 .got : { *(.got) } 82 83 . = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .); 84 85 .got.plt : { *(.got.plt) } 86 .data : { *(.data) } 87 .bss : { *(.bss) } 88 89 . = DATA_SEGMENT_END (.); 90 91 .comment 0 : { *(.comment) } 92} 93