mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
f9eb5e8f70
Prior to this patch, llvm-objdump would only look in the last section (according to the section header table order) that matched an address for a symbol when identifying the target symbol of a call or branch operation. If there are multiple sections with the same address, due to some of them being empty, it did not look in those, even if the symbol couldn't be found in the first section looked in. This patch causes llvm-objdump to look in all sections for possible candidate symbols. If there are multiple possible symbols, it picks one from a non-empty section, if possible (as that is more likely to be the "real" symbol since functions can't really be in emptiy sections), before falling back to those in empty sections. If all else fails, it falls back to absolute symbols as it did before. Differential Revision: https://reviews.llvm.org/D78549 Reviewed by: grimar, Higuoxing
115 lines
4.2 KiB
Plaintext
115 lines
4.2 KiB
Plaintext
## 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]]
|