]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/ELF/linkerscript-sections-keep.s
Vendor import of lld release_39 branch r288513:
[FreeBSD/FreeBSD.git] / test / ELF / linkerscript-sections-keep.s
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3
4 ## First check that section "keep" is garbage collected without using KEEP
5 # RUN: echo "SECTIONS { \
6 # RUN:  .text : { *(.text) } \
7 # RUN:  .keep : { *(.keep) } \
8 # RUN:  .temp : { *(.temp) }}" > %t.script
9 # RUN: ld.lld --gc-sections -o %t1 --script %t.script %t
10 # RUN: llvm-objdump -section-headers %t1 | \
11 # RUN:   FileCheck -check-prefix=SECGC %s
12 # SECGC:      Sections:
13 # SECGC-NEXT: Idx Name          Size      Address          Type
14 # SECGC-NEXT:   0               00000000 0000000000000000
15 # SECGC-NEXT:   1 .text         00000007 0000000000000158 TEXT DATA
16 # SECGC-NEXT:   2 .temp         00000004 000000000000015f DATA
17
18 ## Now apply KEEP command to preserve the section.
19 # RUN: echo "SECTIONS { \
20 # RUN:  .text : { *(.text) } \
21 # RUN:  .keep : { KEEP(*(.keep)) } \
22 # RUN:  .temp : { *(.temp) }}" > %t.script
23 # RUN: ld.lld --gc-sections -o %t1 --script %t.script %t
24 # RUN: llvm-objdump -section-headers %t1 | \
25 # RUN:   FileCheck -check-prefix=SECNOGC %s
26 # SECNOGC:      Sections:
27 # SECNOGC-NEXT: Idx Name          Size      Address          Type
28 # SECNOGC-NEXT:   0               00000000 0000000000000000
29 # SECNOGC-NEXT:   1 .text         00000007 0000000000000158 TEXT DATA
30 # SECNOGC-NEXT:   2 .keep         00000004 000000000000015f DATA
31 # SECNOGC-NEXT:   3 .temp         00000004 0000000000000163 DATA
32
33 ## A section name matches two entries in the SECTIONS directive. The
34 ## first one doesn't have KEEP, the second one does. If section that have
35 ## KEEP is the first in order then section is NOT collected.
36 # RUN: echo "SECTIONS { \
37 # RUN:  .keep : { KEEP(*(.keep)) } \
38 # RUN:  .nokeep : { *(.keep) }}" > %t.script
39 # RUN: ld.lld --gc-sections -o %t1 --script %t.script %t
40 # RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=MIXED1 %s
41 # MIXED1:      Sections:
42 # MIXED1-NEXT: Idx Name          Size      Address         Type
43 # MIXED1-NEXT:   0               00000000 0000000000000000
44 # MIXED1-NEXT:   1 .keep         00000004 0000000000000120 DATA
45 # MIXED1-NEXT:   2 .temp         00000004 0000000000000124 DATA
46 # MIXED1-NEXT:   3 .text         00000007 0000000000000128 TEXT DATA
47 # MIXED1-NEXT:   4 .symtab       00000060 0000000000000000
48 # MIXED1-NEXT:   5 .shstrtab     0000002d 0000000000000000
49 # MIXED1-NEXT:   6 .strtab       00000012 0000000000000000
50
51 ## The same, but now section without KEEP is at first place.
52 ## gold and bfd linkers disagree here. gold collects .keep while
53 ## bfd keeps it. Our current behavior is compatible with bfd although
54 ## we can choose either way.
55 # RUN: echo "SECTIONS { \
56 # RUN:  .nokeep : { *(.keep) } \
57 # RUN:  .keep : { KEEP(*(.keep)) }}" > %t.script
58 # RUN: ld.lld --gc-sections -o %t1 --script %t.script %t
59 # RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=MIXED2 %s
60 # MIXED2:      Sections:
61 # MIXED2-NEXT: Idx Name          Size      Address         Type
62 # MIXED2-NEXT:   0               00000000 0000000000000000
63 # MIXED2-NEXT:   1 .nokeep       00000004 0000000000000120 DATA
64 # MIXED2-NEXT:   2 .temp         00000004 0000000000000124 DATA
65 # MIXED2-NEXT:   3 .text         00000007 0000000000000128 TEXT DATA
66 # MIXED2-NEXT:   4 .symtab       00000060 0000000000000000
67 # MIXED2-NEXT:   5 .shstrtab     0000002f 0000000000000000
68 # MIXED2-NEXT:   6 .strtab       00000012 0000000000000000
69
70 .global _start
71 _start:
72  mov temp, %eax
73
74 .section .keep, "a"
75 keep:
76  .long 1
77
78 .section .temp, "a"
79 temp:
80  .long 2