1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3
4# Test that .orphan_rx is placed after __stack_end. This matches bfd's
5# behavior when the orphan section is the last one.
6
7# RUN: echo "SECTIONS {             \
8# RUN:        __start_text = .;     \
9# RUN:        .text : { *(.text*) } \
10# RUN:        __end_text = .;       \
11# RUN:        __stack_start = .;    \
12# RUN:        . = . + 0x1000;       \
13# RUN:        __stack_end = .;      \
14# RUN:      }" > %t.script
15# RUN: ld.lld -o %t --script %t.script %t.o
16# RUN: llvm-readelf -S --symbols %t | FileCheck %s
17
18# CHECK-DAG: .text             PROGBITS        0000000000000000
19# CHECK-DAG: .orphan_rx        PROGBITS        0000000000001004
20
21# CHECK-DAG: 0000000000000000 {{.*}} __start_text
22# CHECK-DAG: 0000000000000004 {{.*}} __end_text
23# CHECK-DAG: 0000000000000004 {{.*}} __stack_start
24# CHECK-DAG: 0000000000001004 {{.*}} __stack_end
25
26# Test that .orphan_rx is now placed before __stack_end. This matches bfd's
27# behavior when the orphan section is not the last one.
28
29# RUN: echo "SECTIONS {             \
30# RUN:        __start_text = .;     \
31# RUN:        .text : { *(.text*) } \
32# RUN:        __end_text = .;       \
33# RUN:        __stack_start = .;    \
34# RUN:        . = . + 0x1000;       \
35# RUN:        __stack_end = .;      \
36# RUN:        .orphan_rw : { *(.orphan_rw*) } \
37# RUN:      }" > %t.script
38# RUN: ld.lld -o %t --script %t.script %t.o
39# RUN: llvm-readelf -S --symbols %t | FileCheck --check-prefix=MIDDLE %s
40
41# MIDDLE-DAG: .text             PROGBITS        0000000000000000
42# MIDDLE-DAG: .orphan_rx        PROGBITS        0000000000000004
43
44# MIDDLE-DAG: 0000000000000000 {{.*}} __start_text
45# MIDDLE-DAG: 0000000000000004 {{.*}} __end_text
46# MIDDLE-DAG: 0000000000000004 {{.*}} __stack_start
47# MIDDLE-DAG: 0000000000001008 {{.*}} __stack_end
48
49        .global _start
50_start:
51        .zero 4
52
53        .section .orphan_rx,"ax"
54        .zero 4
55
56        .section .orphan_rw,"aw"
57        .zero 4
58