llvm-project/lld/test/ELF/linkerscript/data-segment-relro.test
2022-04-28 22:29:39 -07:00

82 lines
2.2 KiB
Plaintext

# REQUIRES: x86
# RUN: rm -rf %t && split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/shared.s -o %t/b.o
# RUN: ld.lld -shared -soname=b %t/b.o -o %t/b.so
## With relro or without DATA_SEGMENT_RELRO_END just aligns to
## page boundary.
# RUN: ld.lld --hash-style=sysv -z norelro %t/a.o %t/b.so -T %t/1.t -o %t/a1
# RUN: llvm-readelf -S -l %t/a1 | FileCheck %s --check-prefixes=CHECK,CHECK1
# RUN: ld.lld --hash-style=sysv -z relro %t/a.o %t/b.so -T %t/1.t -o %t/a2
# RUN: llvm-readelf -S -l %t/a2 | FileCheck %s --check-prefixes=CHECK,CHECK2
# CHECK: Name Type Address Off Size ES Flg
# CHECK-NEXT: NULL {{.*}}
# CHECK: .dynamic DYNAMIC 0000000000001000 001000 0000f0 10 WA
# CHECK-NEXT: .got PROGBITS 00000000000010f0 0010f0 000008 00 WA
# CHECK-NEXT: __libc_atexit PROGBITS 0000000000002000 002000 000008 00 WA
# CHECK-NEXT: .got.plt PROGBITS 0000000000002008 002008 000020 00 WA
# CHECK1: Program Headers:
# CHECK1-NOT: GNU_RELRO
# CHECK2: Program Headers:
# CHECK2-NEXT: Type
# CHECK2-NEXT: PHDR
# CHECK2-NEXT: LOAD
# CHECK2-NEXT: LOAD
# CHECK2-NEXT: LOAD
# CHECK2-NEXT: LOAD
# CHECK2-NEXT: DYNAMIC
# CHECK2-NEXT: GNU_RELRO
# CHECK2-NEXT: GNU_STACK
# CHECK2: Section to Segment mapping:
# CHECK2: 06 .dynamic .got {{$}}
# RUN: sed '/DATA_SEGMENT_RELRO_END/d' %t/1.t > %t/2.t
# RUN: ld.lld %t/a.o %t/b.so -T %t/2.t -o /dev/null
#--- a.s
.global _start
_start:
.long bar
jmp *bar2@GOTPCREL(%rip)
.section .data,"aw"
.quad 0
.zero 4
.section .foo,"aw"
.section .bss,"",@nobits
.section __libc_atexit,"aw",@progbits
.dc.a __libc_atexit
#--- 1.t
SECTIONS {
. = SIZEOF_HEADERS;
.plt : { *(.plt) }
.text : { *(.text) }
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
.dynamic : { *(.dynamic) }
.got : { *(.got) }
. = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .);
__libc_atexit : { *(__libc_atexit) }
.got.plt : { *(.got.plt) }
.data : { *(.data) }
.bss : { *(.bss) }
. = DATA_SEGMENT_END (.);
.comment 0 : { *(.comment) }
}