1## This test shows that llvm-objdump can handle sections with the same address
2## when symbols in those sections are referenced. In the past, the section
3## picked was non-deterministic, resulting in different symbols being found for
4## the section. The test uses YAML for the input, as we need a fully linked ELF
5## to reproduce the original failure.
6
7## Two empty sections, one with symbol in, one without.
8# RUN: yaml2obj %s --docnum=1 -o %t1 -D SIZE1=0 -D SIZE2=0 -D SECTION=.second -D INDEX=SHN_ABS
9# RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=TARGET
10# RUN: yaml2obj %s --docnum=1 -o %t2 -D SIZE1=0 -D SIZE2=0 -D SECTION=.first -D INDEX=SHN_ABS
11# RUN: llvm-objdump -d %t2 | FileCheck %s --check-prefix=TARGET
12
13## Two sections, one empty with symbol, other non-empty, without symbol.
14# RUN: yaml2obj %s --docnum=1 -o %t3 -D SIZE1=1 -D SIZE2=0 -D SECTION=.second -D INDEX=SHN_ABS
15# RUN: llvm-objdump -d %t3 | FileCheck %s --check-prefix=TARGET
16# RUN: yaml2obj %s --docnum=1 -o %t4 -D SIZE1=0 -D SIZE2=1 -D SECTION=.first -D INDEX=SHN_ABS
17# RUN: llvm-objdump -d %t4 | FileCheck %s --check-prefix=TARGET
18
19## Fall back to absolute symbol if no symbol found in candidate sections.
20# RUN: yaml2obj %s --docnum=1 -o %t5 -D SIZE1=1 -D SIZE2=0 -D SECTION=.caller -D INDEX=SHN_ABS
21# RUN: llvm-objdump -d %t5 | FileCheck %s --check-prefix=ABSOLUTE
22
23## Show that other symbols with reserved st_shndx values are treated as absolute
24## symbols.
25# RUN: yaml2obj %s --docnum=1 -o %t6 -D SIZE1=1 -D SIZE2=0 -D SECTION=.caller -D INDEX=SHN_LOPROC
26# RUN: llvm-objdump -d %t6 | FileCheck %s --check-prefix=ABSOLUTE
27
28## Print no target if no symbol in section/absolute symbol found.
29# RUN: llvm-objcopy %t5 %t7 -N other
30# RUN: llvm-objdump -d %t7 | FileCheck %s --check-prefix=FAIL
31
32# TARGET:   callq 0x5 <target>
33# ABSOLUTE: callq 0x5 <other+0x5>
34# FAIL:     callq 0x5{{$}}
35
36--- !ELF
37FileHeader:
38  Class:   ELFCLASS64
39  Data:    ELFDATA2LSB
40  Type:    ET_EXEC
41  Machine: EM_X86_64
42Sections:
43  - Name:    .caller
44    Type:    SHT_PROGBITS
45    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
46    Address: 0x0
47    Content: e800000000 ## Call instruction to next address.
48  - Name:    .first
49    Type:    SHT_PROGBITS
50    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
51    Address: 0x5
52    Size:    [[SIZE1]]
53  - Name:    .second
54    Type:    SHT_PROGBITS
55    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
56    Address: 0x5
57    Size:    [[SIZE2]]
58Symbols:
59  - Name:    target
60    Section: [[SECTION]]
61    Value:   0x5
62  - Name:    other
63    Index:   [[INDEX]]
64    Value:   0x0
65
66## Two empty sections, both with symbols.
67# RUN: yaml2obj %s --docnum=2 -o %t7 -D SIZE1=0 -D SIZE2=0 -D SYMVAL1=0x5 -D SYMVAL2=0x5
68# RUN: llvm-objdump -d %t7 | FileCheck %s --check-prefix=SECOND
69
70## Two sections, both with symbols, one empty, the other not.
71# RUN: yaml2obj %s --docnum=2 -o %t8 -D SIZE1=1 -D SIZE2=0 -D SYMVAL1=0x5 -D SYMVAL2=0x5
72# RUN: llvm-objdump -d %t8 | FileCheck %s --check-prefix=FIRST
73# RUN: yaml2obj %s --docnum=2 -o %t9 -D SIZE1=0 -D SIZE2=1 -D SYMVAL1=0x5 -D SYMVAL2=0x5
74# RUN: llvm-objdump -d %t9 | FileCheck %s --check-prefix=SECOND
75
76## Two sections, both with symbols, one empty, other not, symbol in non-empty
77## section has value higher than target address.
78# RUN: yaml2obj %s --docnum=2 -o %t10 -D SIZE1=1 -D SIZE2=0 -D SYMVAL1=0x6 -D SYMVAL2=0x5
79# RUN: llvm-objdump -d %t10 | FileCheck %s --check-prefix=SECOND
80# RUN: yaml2obj %s --docnum=2 -o %t11 -D SIZE1=0 -D SIZE2=1 -D SYMVAL1=0x5 -D SYMVAL2=0x6
81# RUN: llvm-objdump -d %t11 | FileCheck %s --check-prefix=FIRST
82
83# FIRST:  callq 0x5 <first>
84# SECOND: callq 0x5 <second>
85
86--- !ELF
87FileHeader:
88  Class:   ELFCLASS64
89  Data:    ELFDATA2LSB
90  Type:    ET_EXEC
91  Machine: EM_X86_64
92Sections:
93  - Name:    .caller
94    Type:    SHT_PROGBITS
95    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
96    Address: 0x0
97    Content: e800000000 ## Call instruction to next address.
98  - Name:    .first
99    Type:    SHT_PROGBITS
100    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
101    Address: 0x5
102    Size:    [[SIZE1]]
103  - Name:    .second
104    Type:    SHT_PROGBITS
105    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
106    Address: 0x5
107    Size:    [[SIZE2]]
108Symbols:
109  - Name:    first
110    Section: .first
111    Value:   [[SYMVAL1]]
112  - Name:    second
113    Section: .second
114    Value:   [[SYMVAL2]]
115