[memprof] Remove an unused using directive (#117004)
[llvm-project.git] / lld / test / ELF / relocatable-comdat.s
blobc69e4928509d4384e9d3400d6c306dd3ed79927b
1 # REQUIRES: x86
2 ## Test that SHT_GROUP sections are retained in relocatable output. The content
3 ## may be rewritten because group members may change their indices. Additionally,
4 ## group member may be combined or discarded (e.g. /DISCARD/ or --gc-sections).
6 # RUN: rm -rf %t && split-file %s %t && cd %t
7 # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
8 # RUN: ld.lld -r a.o a.o -o a.ro
9 # RUN: llvm-readelf -g -S a.ro | FileCheck %s
11 # CHECK: Name Type Address Off Size ES Flg Lk Inf Al
12 # CHECK: .group GROUP 0000000000000000 {{.*}} 00001c 04 [[#]] [[#]] 4
13 # CHECK-NEXT: .rodata.bar PROGBITS 0000000000000000 {{.*}} 000001 00 AG 0 0 1
14 # CHECK-NEXT: .rodata.foo PROGBITS 0000000000000000 {{.*}} 000001 00 AG 0 0 1
15 # CHECK-NEXT: .text.bar PROGBITS 0000000000000000 {{.*}} 000008 00 AXG 0 0 1
16 # CHECK-NEXT: .rela.text.bar RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
17 # CHECK-NEXT: .text.foo PROGBITS 0000000000000000 {{.*}} 000008 00 AXG [[#]] [[#]] 1
18 # CHECK-NEXT: .rela.text.foo RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
19 # CHECK-NEXT: .note.GNU-stack
21 # CHECK: COMDAT group section [{{.*}}] `.group' [abc] contains 6 sections:
22 # CHECK-NEXT: Name
23 # CHECK-NEXT: .rodata.bar
24 # CHECK-NEXT: .rodata.foo
25 # CHECK-NEXT: .text.bar
26 # CHECK-NEXT: .rela.text.bar
27 # CHECK-NEXT: .text.foo
28 # CHECK-NEXT: .rela.text.foo
30 ## Rewrite SHT_GROUP content if some members are combined.
31 # RUN: echo 'SECTIONS { .rodata : {*(.rodata.*)} .text : {*(.text.*)} }' > combine.lds
32 # RUN: ld.lld -r -T combine.lds a.o a.o -o combine.ro
33 # RUN: llvm-readelf -g -S combine.ro | FileCheck %s --check-prefix=COMBINE
35 # COMBINE: Name Type Address Off Size ES Flg Lk Inf Al
36 # COMBINE: .rodata PROGBITS 0000000000000000 {{.*}} 000002 00 AG 0 0 1
37 # COMBINE-NEXT: .text PROGBITS 0000000000000000 {{.*}} 000010 00 AXG 0 0 4
38 # COMBINE-NEXT: .group GROUP 0000000000000000 {{.*}} 000014 04 [[#]] [[#]] 4
39 # COMBINE-NEXT: .rela.text RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
40 # COMBINE-NEXT: .rela.text RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
41 # COMBINE-NEXT: .note.GNU-stack
43 # COMBINE: COMDAT group section [{{.*}}] `.group' [abc] contains 4 sections:
44 # COMBINE-NEXT: Name
45 # COMBINE-NEXT: .rodata
46 # COMBINE-NEXT: .text
47 # COMBINE-NEXT: .rela.text
48 # COMBINE-NEXT: .rela.text
50 ## If --force-group-allocation is specified, discard .group and combine .rela.* if their relocated sections are combined.
51 # RUN: ld.lld -r -T combine.lds a.o a.o --force-group-allocation -o combine-a.ro
52 # RUN: llvm-readelf -g -S combine-a.ro | FileCheck %s --check-prefix=COMBINE-A
54 # COMBINE-A: Name Type Address Off Size ES Flg Lk Inf Al
55 # COMBINE-A: .rodata PROGBITS 0000000000000000 {{.*}} 000002 00 A 0 0 1
56 # COMBINE-A-NEXT: .text PROGBITS 0000000000000000 {{.*}} 000010 00 AX 0 0 4
57 # COMBINE-A-NEXT: .rela.text RELA 0000000000000000 {{.*}} 000030 18 I [[#]] [[#]] 8
58 # COMBINE-A-NEXT: .note.GNU-stack
60 # RUN: echo 'SECTIONS { /DISCARD/ : {*(.rodata.*)} }' > discard-rodata.lds
61 # RUN: ld.lld -r -T discard-rodata.lds a.o a.o -o discard-rodata.ro
62 # RUN: llvm-readelf -g -S discard-rodata.ro | FileCheck %s --check-prefix=NO-RODATA
64 ## Handle discarded group members.
65 # NO-RODATA: Name Type Address Off Size ES Flg Lk Inf Al
66 # NO-RODATA: .group GROUP 0000000000000000 {{.*}} 000014 04 [[#]] [[#]] 4
67 # NO-RODATA-NEXT: .text.bar PROGBITS 0000000000000000 {{.*}} 000008 00 AXG 0 0 1
68 # NO-RODATA-NEXT: .rela.text.bar RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
69 # NO-RODATA-NEXT: .text.foo PROGBITS 0000000000000000 {{.*}} 000008 00 AXG [[#]] [[#]] 1
70 # NO-RODATA-NEXT: .rela.text.foo RELA 0000000000000000 {{.*}} 000018 18 IG [[#]] [[#]] 8
71 # NO-RODATA-NEXT: .note.GNU-stack
73 # NO-RODATA: COMDAT group section [{{.*}}] `.group' [abc] contains 4 sections:
74 # NO-RODATA-NEXT: Name
75 # NO-RODATA-NEXT: .text.bar
76 # NO-RODATA-NEXT: .rela.text.bar
77 # NO-RODATA-NEXT: .text.foo
78 # NO-RODATA-NEXT: .rela.text.foo
80 #--- a.s
81 .weak abc
82 abc:
84 .section .rodata.bar,"aG",@progbits,abc,comdat
85 .byte 42
86 .section .rodata.foo,"aG",@progbits,abc,comdat
87 .byte 42
89 .section .text.bar,"axG",@progbits,abc,comdat
90 .quad abc
91 .section .text.foo,"axG",@progbits,abc,comdat
92 .quad abc