File: orphan-memory.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 (118 lines) | stat: -rw-r--r-- 3,167 bytes parent folder | download | duplicates (18)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
REQUIRES: x86

RUN: split-file %s %ts
RUN: llvm-mc -filetype=obj -triple=x86_64 %ts/s -o %t.o

## Check that despite having a lower sort rank, an orphan section '.init_array'
## is placed after '.data' and '.data2' and in the same memory region.

## Also check that a non-SHF_ALLOC orphan section '.nonalloc' is not placed in
## a memory region. Both defined memory regions are exhausted after all expected
## sections are added, thus, trying to put any unexpected section would lead to
## an error.

RUN: ld.lld -o %t -T %ts/t %t.o
RUN: llvm-readelf -S %t | FileCheck %s

CHECK: Name        Type       Address          Off           Size
CHECK: .text       PROGBITS   0000000000008000 {{[0-9a-f]+}} 000004
CHECK: .data       PROGBITS   0000000000009000 {{[0-9a-f]+}} 000008
CHECK: .data2      PROGBITS   0000000000009008 {{[0-9a-f]+}} 00000c
CHECK: .init_array INIT_ARRAY 0000000000009014 {{[0-9a-f]+}} 000010
CHECK: .nonalloc   PROGBITS   0000000000000000 {{[0-9a-f]+}} 000010

## Check that attributes of memory regions are ignored for orphan sections when
## the anchor section specifies the memory region explicitly, This seems to
## contradict https://sourceware.org/binutils/docs/ld/MEMORY.html, but better
## resembles the way GNU ld actually works.

RUN: ld.lld -o %t2 -T %ts/t2 %t.o
RUN: llvm-readelf -S %t2 | FileCheck %s

## Same as the previous case, but now properties of sections conflict with
## memory region attributes. Still, orphan sections are placed in the same
## regions as their anchors.

RUN: ld.lld -o %t3 -T %ts/t3 %t.o
RUN: llvm-readelf -S %t3 | FileCheck %s

## Check that when memory regions for anchor sections are not specified
## explicitly and are selected by attributes, orphan sections are also assigned
## to memory regions by matching properties.

RUN: ld.lld -o %t4 -T %ts/t4 %t.o
RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=CHECK4

CHECK4: Name        Type       Address          Off           Size
CHECK4: .text       PROGBITS   0000000000008000 {{[0-9a-f]+}} 000004
CHECK4: .init_array INIT_ARRAY 0000000000009000 {{[0-9a-f]+}} 000010
CHECK4: .data       PROGBITS   0000000000009010 {{[0-9a-f]+}} 000008
CHECK4: .data2      PROGBITS   0000000000009018 {{[0-9a-f]+}} 00000c
CHECK4: .nonalloc   PROGBITS   0000000000000000 {{[0-9a-f]+}} 000010

#--- s
  .text
  .zero 4

  .data
  .zero 8

  .section .data2,"aw",@progbits
  .zero 0xc

  .section .init_array,"aw",@init_array
  .zero 0x10

  .section .nonalloc,""
  .zero 0x10

#--- t
MEMORY
{
  TEXT : ORIGIN = 0x8000, LENGTH = 0x4
  DATA : ORIGIN = 0x9000, LENGTH = 0x24
}

SECTIONS
{
  .text : { *(.text) } > TEXT
  .data : { *(.data) } > DATA
}

#--- t2
MEMORY
{
  TEXT (rwx) : ORIGIN = 0x8000, LENGTH = 0x4
  DATA (rwx) : ORIGIN = 0x9000, LENGTH = 0x24
}

SECTIONS
{
  .text : { *(.text) } > TEXT
  .data : { *(.data) } > DATA
}

#--- t3
MEMORY
{
  TEXT (!w) : ORIGIN = 0x8000, LENGTH = 0x4
  DATA (!w) : ORIGIN = 0x9000, LENGTH = 0x24
}

SECTIONS
{
  .text : { *(.text) } > TEXT
  .data : { *(.data) } > DATA
}

#--- t4
MEMORY
{
  TEXT (rx)  : ORIGIN = 0x8000, LENGTH = 0x4
  DATA (w!x) : ORIGIN = 0x9000, LENGTH = 0x24
}

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