File: data-segment-relro.test

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (92 lines) | stat: -rw-r--r-- 2,637 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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:      .orphan.ro     PROGBITS {{.*}}                              A
# CHECK:      .dynamic       DYNAMIC  {{.*}}                             WA
# CHECK-NEXT: __libc_atexit  PROGBITS {{.*}}                             WA
# CHECK-NEXT: .got           PROGBITS {{.*}}                             WA
# CHECK-NEXT: .got.plt       PROGBITS {{.*}}                             WA
# CHECK:      .orphan.rw     PROGBITS {{.*}}                             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 __libc_atexit .got {{$}}

# RUN: sed '/DATA_SEGMENT_RELRO_END/d' %t/1.t > %t/2.t
# RUN: not ld.lld %t/a.o %t/b.so -T %t/2.t -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR

# ERR: error: section: .got is not contiguous with other relro sections

#--- 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

.section .orphan.ro,"a",@progbits
.dc.a 0

.section .orphan.rw,"aw",@progbits
.dc.a .orphan.rw

#--- 1.t
SECTIONS {
  . = SIZEOF_HEADERS;

  .plt  : { *(.plt) }
  .text : { *(.text) }

  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));

  .dynamic : { *(.dynamic) }
  ## The custom section __libc_atexit is made relro.
  __libc_atexit : { *(__libc_atexit) }
  .got : { *(.got) }

  . = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .);

  .got.plt : { *(.got.plt) }
  .data : { *(.data) }
  .bss : { *(.bss) }

  . = DATA_SEGMENT_END (.);

  .comment 0 : { *(.comment) }
}