blob: 4b0da011c9d46086e58fceadb64d63695a355b97 [file] [log] [blame]
## This test shows that llvm-objdump can handle sections with the same address
## when symbols in those sections are referenced. In the past, the section
## picked was non-deterministic, resulting in different symbols being found for
## the section. The test uses YAML for the input, as we need a fully linked ELF
## to reproduce the original failure.
## Two empty sections, one with symbol in, one without.
# RUN: yaml2obj %s --docnum=1 -o %t1 -D SIZE1=0 -D SIZE2=0 -D SECTION=.second -D INDEX=SHN_ABS
# RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=TARGET
# RUN: yaml2obj %s --docnum=1 -o %t2 -D SIZE1=0 -D SIZE2=0 -D SECTION=.first -D INDEX=SHN_ABS
# RUN: llvm-objdump -d %t2 | FileCheck %s --check-prefix=TARGET
## Two sections, one empty with symbol, other non-empty, without symbol.
# RUN: yaml2obj %s --docnum=1 -o %t3 -D SIZE1=1 -D SIZE2=0 -D SECTION=.second -D INDEX=SHN_ABS
# RUN: llvm-objdump -d %t3 | FileCheck %s --check-prefix=TARGET
# RUN: yaml2obj %s --docnum=1 -o %t4 -D SIZE1=0 -D SIZE2=1 -D SECTION=.first -D INDEX=SHN_ABS
# RUN: llvm-objdump -d %t4 | FileCheck %s --check-prefix=TARGET
## Fall back to absolute symbol if no symbol found in candidate sections.
# RUN: yaml2obj %s --docnum=1 -o %t5 -D SIZE1=1 -D SIZE2=0 -D SECTION=.caller -D INDEX=SHN_ABS
# RUN: llvm-objdump -d %t5 | FileCheck %s --check-prefix=ABSOLUTE
## Show that other symbols with reserved st_shndx values are treated as absolute
## symbols.
# RUN: yaml2obj %s --docnum=1 -o %t6 -D SIZE1=1 -D SIZE2=0 -D SECTION=.caller -D INDEX=SHN_LOPROC
# RUN: llvm-objdump -d %t6 | FileCheck %s --check-prefix=ABSOLUTE
## Print no target if no symbol in section/absolute symbol found.
# RUN: llvm-objcopy %t5 %t7 -N other
# RUN: llvm-objdump -d %t7 | FileCheck %s --check-prefix=FAIL
# TARGET: callq 0x5 <target>
# ABSOLUTE: callq 0x5 <other+0x5>
# FAIL: callq 0x5{{$}}
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .caller
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x0
Content: e800000000 ## Call instruction to next address.
- Name: .first
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x5
Size: [[SIZE1]]
- Name: .second
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x5
Size: [[SIZE2]]
Symbols:
- Name: target
Section: [[SECTION]]
Value: 0x5
- Name: other
Index: [[INDEX]]
Value: 0x0
## Two empty sections, both with symbols.
# RUN: yaml2obj %s --docnum=2 -o %t7 -D SIZE1=0 -D SIZE2=0 -D SYMVAL1=0x5 -D SYMVAL2=0x5
# RUN: llvm-objdump -d %t7 | FileCheck %s --check-prefix=SECOND
## Two sections, both with symbols, one empty, the other not.
# RUN: yaml2obj %s --docnum=2 -o %t8 -D SIZE1=1 -D SIZE2=0 -D SYMVAL1=0x5 -D SYMVAL2=0x5
# RUN: llvm-objdump -d %t8 | FileCheck %s --check-prefix=FIRST
# RUN: yaml2obj %s --docnum=2 -o %t9 -D SIZE1=0 -D SIZE2=1 -D SYMVAL1=0x5 -D SYMVAL2=0x5
# RUN: llvm-objdump -d %t9 | FileCheck %s --check-prefix=SECOND
## Two sections, both with symbols, one empty, other not, symbol in non-empty
## section has value higher than target address.
# RUN: yaml2obj %s --docnum=2 -o %t10 -D SIZE1=1 -D SIZE2=0 -D SYMVAL1=0x6 -D SYMVAL2=0x5
# RUN: llvm-objdump -d %t10 | FileCheck %s --check-prefix=SECOND
# RUN: yaml2obj %s --docnum=2 -o %t11 -D SIZE1=0 -D SIZE2=1 -D SYMVAL1=0x5 -D SYMVAL2=0x6
# RUN: llvm-objdump -d %t11 | FileCheck %s --check-prefix=FIRST
# FIRST: callq 0x5 <first>
# SECOND: callq 0x5 <second>
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .caller
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x0
Content: e800000000 ## Call instruction to next address.
- Name: .first
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x5
Size: [[SIZE1]]
- Name: .second
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Address: 0x5
Size: [[SIZE2]]
Symbols:
- Name: first
Section: .first
Value: [[SYMVAL1]]
- Name: second
Section: .second
Value: [[SYMVAL2]]