File: input-section-flags.s

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (115 lines) | stat: -rw-r--r-- 3,867 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
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o

## Test the INPUT_SECTION_FLAGS feature. It prefixes an input section list and
## restricts matches to sections that have the required flags and do not have
## any of the must not have flags.

## Uniquely identify each .sec section by flag alone, with .text going into
## to the SHF_EXECINSTR requiring .outsec2
# RUN: echo "SECTIONS { \
# RUN: .outsec1 : { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
# RUN:                                  !SHF_WRITE & !SHF_MERGE) *(.sec.*) } \
# RUN: .outsec2 : { INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE\
# RUN:                                  & !SHF_MERGE) *(.sec.* .text) } \
# RUN: .outsec3 : { INPUT_SECTION_FLAGS(SHF_WRITE) *(.sec.*) } \
# RUN: .outsec4 : { INPUT_SECTION_FLAGS(SHF_MERGE & !SHF_STRINGS) *(.sec.*) } \
# RUN: .outsec5 : { INPUT_SECTION_FLAGS(SHF_STRINGS) *(.sec.*) } \
# RUN: } " > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t.o
# RUN: llvm-readobj --symbols %t1 | FileCheck %s
# CHECK:  Name: _start
# CHECK:  Section: .outsec2
# CHECK:  Name: s1
# CHECK:  Section: .outsec1
# CHECK:  Name: s2
# CHECK:  Section: .outsec2
# CHECK:  Name: s3
# CHECK:  Section: .outsec3
# CHECK:  Name: s4
# CHECK:  Section: .outsec4
# CHECK:  Name: s5
# CHECK:  Section: .outsec5

## Same test but using OVERLAY.
# RUN: echo "SECTIONS { \
# RUN: OVERLAY 0x1000 : AT ( 0x4000 ) { \
# RUN: .outsec1 { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
# RUN:                                !SHF_WRITE & !SHF_MERGE) *(.sec.*) }\
# RUN: .outsec2 { INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE \
# RUN:                                & !SHF_MERGE) *(.sec.* .text) } \
# RUN: .outsec3 { INPUT_SECTION_FLAGS(SHF_WRITE) *(.sec.*) } \
# RUN: .outsec4 { INPUT_SECTION_FLAGS(SHF_MERGE & !SHF_STRINGS) *(.sec.*) } \
# RUN: .outsec5 { INPUT_SECTION_FLAGS(SHF_STRINGS) *(.sec.*) } \
# RUN: } } " > %t2.script

# RUN: ld.lld -o %t2 --script %t2.script %t.o
# RUN: llvm-readobj --symbols %t2 | FileCheck %s

## Same test but using hex representations of the flags.
# RUN: echo "SECTIONS { \
# RUN: .outsec1 : { INPUT_SECTION_FLAGS(0x2 & !0x4 & !0x1 & !0x10) *(.sec.*) }\
# RUN: .outsec2 : { INPUT_SECTION_FLAGS(0x2 & 0x4 & !0x1 & !0x10) \
# RUN:              *(.sec.* .text) } \
# RUN: .outsec3 : { INPUT_SECTION_FLAGS(0x1) *(.sec.*) } \
# RUN: .outsec4 : { INPUT_SECTION_FLAGS(0x10 & !0x20) *(.sec.*) } \
# RUN: .outsec5 : { INPUT_SECTION_FLAGS(0x20) *(.sec.*) } \
# RUN: } " > %t3.script

# RUN: ld.lld -o %t3 --script %t3.script %t.o
# RUN: llvm-readobj --symbols %t3 | FileCheck %s

## Check that we can handle multiple InputSectionDescriptions in a single
## OutputSection
# RUN: echo "SECTIONS { \
# RUN: .outsec1 : { INPUT_SECTION_FLAGS(SHF_ALLOC & !SHF_EXECINSTR & \
# RUN:                                  !SHF_WRITE & !SHF_MERGE) *(.sec.*) ; \
# RUN:              INPUT_SECTION_FLAGS(SHF_ALLOC & SHF_EXECINSTR & !SHF_WRITE\
# RUN:                                  & !SHF_MERGE)  *(.sec.* *.text) }\
# RUN: } " > %t4.script

# RUN: ld.lld -o %t4 --script %t4.script %t.o
# RUN: llvm-readobj --symbols %t4 | FileCheck --check-prefix MULTIPLE %s

# MULTIPLE:  Name: _start
# MULTIPLE:  Section: .outsec1
# MULTIPLE:  Name: s1
# MULTIPLE:  Section: .outsec1
# MULTIPLE:  Name: s2
# MULTIPLE:  Section: .outsec1
# MULTIPLE:  Name: s3
# MULTIPLE:  Section: .sec.aw
# MULTIPLE:  Name: s4
# MULTIPLE:  Section: .sec.aM
# MULTIPLE:  Name: s5
# MULTIPLE:  Section: .sec.aMS

 .text
 .global _start
_start:
 nop

 .section .sec.a, "a", @progbits
 .globl s1
s1:
 .long 1

 .section .sec.ax, "ax", @progbits
 .globl s2
s2:
 .long 2

 .section .sec.aw, "aw", @progbits
 .globl s3
s3:
 .long 3

 .section .sec.aM, "aM", @progbits, 4
 .globl s4
s4:
 .long 4

 .section .sec.aMS, "aMS", @progbits, 1
 .globl s5
s5:
 .asciz "a"