4 RUN: llvm-mc -filetype=obj -triple=x86_64 %ts/s -o %t.o
6 ## Check that despite having a lower sort rank, an orphan section '.init_array'
7 ## is placed after '.data' and '.data2' and in the same memory region.
9 ## Also check that a non-SHF_ALLOC orphan section '.nonalloc' is not placed in
10 ## a memory region. Both defined memory regions are exhausted after all expected
11 ## sections are added, thus, trying to put any unexpected section would lead to
14 RUN: ld.lld -o %t -T %ts/t %t.o
15 RUN: llvm-readelf -S %t | FileCheck %s
17 CHECK: Name Type Address Off Size
18 CHECK: .text PROGBITS 0000000000008000 {{[0-9a-f]+}} 000004
19 CHECK: .data PROGBITS 0000000000009000 {{[0-9a-f]+}} 000008
20 CHECK: .data2 PROGBITS 0000000000009008 {{[0-9a-f]+}} 00000c
21 CHECK: .init_array INIT_ARRAY 0000000000009014 {{[0-9a-f]+}} 000010
22 CHECK: .nonalloc PROGBITS 0000000000000000 {{[0-9a-f]+}} 000010
24 ## Check that attributes of memory regions are ignored for orphan sections when
25 ## the anchor section specifies the memory region explicitly, This seems to
26 ## contradict https://sourceware.org/binutils/docs/ld/MEMORY.html, but better
27 ## resembles the way GNU ld actually works.
29 RUN: ld.lld -o %t2 -T %ts/t2 %t.o
30 RUN: llvm-readelf -S %t2 | FileCheck %s
32 ## Same as the previous case, but now properties of sections conflict with
33 ## memory region attributes. Still, orphan sections are placed in the same
34 ## regions as their anchors.
36 RUN: ld.lld -o %t3 -T %ts/t3 %t.o
37 RUN: llvm-readelf -S %t3 | FileCheck %s
39 ## Check that when memory regions for anchor sections are not specified
40 ## explicitly and are selected by attributes, orphan sections are also assigned
41 ## to memory regions by matching properties.
43 RUN: ld.lld -o %t4 -T %ts/t4 %t.o
44 RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=CHECK4
46 CHECK4: Name Type Address Off Size
47 CHECK4: .text PROGBITS 0000000000008000 {{[0-9a-f]+}} 000004
48 CHECK4: .init_array INIT_ARRAY 0000000000009000 {{[0-9a-f]+}} 000010
49 CHECK4: .data PROGBITS 0000000000009010 {{[0-9a-f]+}} 000008
50 CHECK4: .data2 PROGBITS 0000000000009018 {{[0-9a-f]+}} 00000c
51 CHECK4: .nonalloc PROGBITS 0000000000000000 {{[0-9a-f]+}} 000010
60 .section .data2,"aw",@progbits
63 .section .init_array,"aw",@init_array
72 TEXT : ORIGIN = 0x8000, LENGTH = 0x4
73 DATA : ORIGIN = 0x9000, LENGTH = 0x24
78 .text : { *(.text) } > TEXT
79 .data : { *(.data) } > DATA
85 TEXT (rwx) : ORIGIN = 0x8000, LENGTH = 0x4
86 DATA (rwx) : ORIGIN = 0x9000, LENGTH = 0x24
91 .text : { *(.text) } > TEXT
92 .data : { *(.data) } > DATA
98 TEXT (!w) : ORIGIN = 0x8000, LENGTH = 0x4
99 DATA (!w) : ORIGIN = 0x9000, LENGTH = 0x24
104 .text : { *(.text) } > TEXT
105 .data : { *(.data) } > DATA
111 TEXT (rx) : ORIGIN = 0x8000, LENGTH = 0x4
112 DATA (w!x) : ORIGIN = 0x9000, LENGTH = 0x24