xref: /llvm-project/lld/test/ELF/linkerscript/data-segment-relro.test (revision 5a58e98c2018f8cfea71e34e9717da40201a966b)
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 max-page-size=65536 -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 max-page-size=65536 -z relro --orphan-handling=warn \
14# RUN:   %t/a.o %t/b.so -T %t/1.t -o %t/a2 2>&1 | FileCheck %s --check-prefix=WARN
15# RUN: llvm-readelf -S -l %t/a2 | FileCheck %s --check-prefixes=CHECK,CHECK2
16
17# WARN:     warning: <internal>:(.dynsym) is being placed in '.dynsym'
18# WARN-NOT:                     (.relro_padding)
19
20# CHECK:      Name           Type     Address          Off      Size ES Flg
21# CHECK-NEXT:                NULL     {{.*}}
22# CHECK:      .orphan.ro     PROGBITS {{.*}}                              A
23# CHECK:      .dynamic       DYNAMIC  {{.*}}                             WA
24# CHECK-NEXT: __libc_atexit  PROGBITS {{.*}}                             WA
25# CHECK-NEXT: .got           PROGBITS {{.*}}                             WA
26# CHECK2-NEXT:.relro_padding NOBITS   0000000000010100 010100 000f00 00  WA
27# CHECK-NEXT: .got.plt       PROGBITS {{.*}}                             WA
28# CHECK:      .orphan.rw     PROGBITS {{.*}}                             WA
29
30# CHECK1:      Program Headers:
31# CHECK1-NOT:  GNU_RELRO
32
33# CHECK2:      Program Headers:
34# CHECK2-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
35# CHECK2-NEXT:   PHDR           0x000040
36# CHECK2-NEXT:   LOAD           0x000000
37# CHECK2-NEXT:   LOAD           0x0002b0
38# CHECK2-NEXT:   LOAD           0x010000 0x0000000000010000 0x0000000000010000 0x000100 0x001000 RW  0x10000
39# CHECK2-NEXT:   LOAD           0x020000 0x0000000000020000 0x0000000000020000 0x000034 0x000034 RW  0x10000
40# CHECK2-NEXT:   DYNAMIC        0x010000 0x0000000000010000 0x0000000000010000 0x0000f0 0x0000f0 RW  0x8
41# CHECK2-NEXT:   GNU_RELRO      0x010000 0x0000000000010000 0x0000000000010000 0x000100 0x001000 R   0x1
42# CHECK2-NEXT:   GNU_STACK      0x000000
43
44# CHECK2:      Section to Segment mapping:
45# CHECK2:        06     .dynamic __libc_atexit .got .relro_padding {{$}}
46
47# RUN: sed '/DATA_SEGMENT_RELRO_END/d' %t/1.t > %t/2.t
48# RUN: not ld.lld %t/a.o %t/b.so -T %t/2.t -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
49
50# ERR: error: section: .got is not contiguous with other relro sections
51
52#--- a.s
53.global _start
54_start:
55  .long bar
56  jmp *bar2@GOTPCREL(%rip)
57
58.section .data,"aw"
59.quad 0
60
61.zero 4
62.section .foo,"aw"
63.section .bss,"",@nobits
64
65.section __libc_atexit,"aw",@progbits
66.dc.a __libc_atexit
67
68.section .orphan.ro,"a",@progbits
69.dc.a 0
70
71.section .orphan.rw,"aw",@progbits
72.dc.a .orphan.rw
73
74#--- 1.t
75SECTIONS {
76  . = SIZEOF_HEADERS;
77
78  .plt  : { *(.plt) }
79  .text : { *(.text) }
80
81  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
82
83  .dynamic : { *(.dynamic) }
84  ## The custom section __libc_atexit is made relro.
85  __libc_atexit : { *(__libc_atexit) }
86  .got : { *(.got) }
87
88  . = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .);
89
90  .got.plt : { *(.got.plt) }
91  .data : { *(.data) }
92  .bss : { *(.bss) }
93
94  . = DATA_SEGMENT_END (.);
95
96  .comment 0 : { *(.comment) }
97}
98