1# REQUIRES: x86
2
3# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t1.obj
4# RUN: llvm-mc -triple=x86_64-windows-gnu %S/Inputs/associative-comdat-mingw-2.s -filetype=obj -o %t2.obj
5
6# RUN: lld-link -lldmingw -entry:main %t1.obj %t2.obj -out:%t.gc.exe -verbose
7# RUN: llvm-readobj --sections %t.gc.exe | FileCheck %s
8
9# CHECK: Sections [
10# CHECK:   Section {
11# CHECK:     Number: 2
12# CHECK-LABEL:     Name: .rdata (2E 72 64 61 74 61 00 00)
13#             This is the critical check to show that only *one* definition of
14#             .xdata$foo was retained. This *must* be 0x24 (0x4 for the .xdata
15#             section and 0x20 for the .ctors/.dtors headers/ends).
16#             Make sure that no other .xdata sections get included, which would
17#             increase the size here.
18# CHECK-NEXT:     VirtualSize: 0x24
19
20        .text
21        .def            main;
22        .scl            2;
23        .type           32;
24        .endef
25        .globl          main
26        .p2align        4, 0x90
27main:
28        call            foo
29        retq
30
31# Defines .text$foo (which has a leader symbol and is referenced like
32# normally), and .xdata$foo (which lacks a leader symbol, which normally
33# would be declared associative to the symbol foo).
34# .xdata$foo should be implicitly treated as associative to foo and brought
35# in, while .xdata$bar, implicitly associative to bar, not included, and
36# .xdata$baz not included since there's no symbol baz.
37
38# GNU binutils ld doesn't do this at all, but always includes all .xdata/.pdata
39# comdat sections, even if --gc-sections is used.
40
41        .section        .xdata$foo,"dr"
42        .linkonce       discard
43        .p2align        3
44        .long           42
45
46        .section        .xdata$bar,"dr"
47        .linkonce       discard
48        .p2align        3
49        .long           43
50
51        .section        .xdata$baz,"dr"
52        .linkonce       discard
53        .p2align        3
54        .long           44
55
56        .def            foo;
57        .scl            2;
58        .type           32;
59        .endef
60        .section        .text$foo,"xr",discard,foo
61        .globl          foo
62        .p2align        4
63foo:
64        ret
65
66        .def            bar;
67        .scl            2;
68        .type           32;
69        .endef
70        .section        .text$bar,"xr",discard,bar
71        .globl          bar
72        .p2align        4
73bar:
74        ret
75