Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,20 +747,25 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
assert(RelaSec &&
"Can't read a SHT_LLVM_BB_ADDR_MAP section in a relocatable "
"object file without providing a relocation section.");
// We might end up with relocations in CREL here. If we do, return an
// error since we do not currently support them.
if (RelaSec->sh_type == ELF::SHT_CREL)
return createError("unable to read relocations for section " +
describe(EF, Sec) +
" as the corresponding relocation section format is "
"CREL, which is not currently supported.");
Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas = EF.relas(*RelaSec);
if (!Relas)
return createError("unable to read relocations for section " +
describe(EF, Sec) + ": " +
toString(Relas.takeError()));
for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas)
FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
if (RelaSec->sh_type == ELF::SHT_CREL) {
Expected<typename ELFFile<ELFT>::RelsOrRelas> Relas = EF.crels(*RelaSec);
if (!Relas)
return createError("unable to read CREL relocations for section " +
describe(EF, Sec) + ": " +
toString(Relas.takeError()));
for (typename ELFFile<ELFT>::Elf_Rela Rela : std::get<1>(*Relas)) {
FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
}
} else {
Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas =
EF.relas(*RelaSec);
if (!Relas)
return createError("unable to read relocations for section " +
describe(EF, Sec) + ": " +
toString(Relas.takeError()));
for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas)
FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
}
}
auto GetAddressForRelocation =
[&](unsigned RelocationOffsetInSection) -> Expected<unsigned> {
Expand Down
59 changes: 56 additions & 3 deletions llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## This test checks how we handle the --bb-addr-map option on relocatable
## object files.

# RUN: yaml2obj %s -o %t1.o
# RUN: yaml2obj -D RELOCATION_SECTION_NAME=.rela.llvm_bb_addr_map \
# RUN: -D RELOCATION_SECTION_TYPE=SHT_RELA %s -o %t1.o
# RUN: llvm-readobj %t1.o --bb-addr-map | FileCheck %s

# CHECK: BBAddrMap [
Expand Down Expand Up @@ -77,8 +78,8 @@ Sections:
AddressOffset: 0x0
Size: 0x11
Metadata: 0x8
- Name: .rela.llvm_bb_addr_map
Type: SHT_RELA
- Name: [[RELOCATION_SECTION_NAME]]
Type: [[RELOCATION_SECTION_TYPE]]
Flags: [ SHF_INFO_LINK ]
Link: .symtab
Info: .llvm_bb_addr_map
Expand Down Expand Up @@ -228,3 +229,55 @@ Sections:
# ET-DYN-NO-WARNING: ]
# ET-DYN-NO-WARNING: }
# ET-DYN-NO-WARNING: ]

## Check that we can correctly decode a BBAddrMap in a reloctable object file
## with CREL relocations.

# RUN: yaml2obj -D RELOCATION_SECTION_NAME=.crel.llvm_bb_addr_map \
# RUN: -D RELOCATION_SECTION_TYPE=SHT_CREL %s -o %t6.o
# RUN: llvm-readobj %t6.o --bb-addr-map | FileCheck %s --check-prefix=CREL

# CREL: BBAddrMap [
# CREL-NEXT: Function {
# CREL-NEXT: At: 0x0
# CREL-NEXT: Name: <?>
# CREL-NEXT: BB Ranges [
# CREL-NEXT: {
# CREL-NEXT: Base Address: 0x0
# CREL-NEXT: BB Entries [
# CREL-NEXT: {
# CREL-NEXT: ID: 0
# CREL-NEXT: Offset: 0x0
# CREL-NEXT: Size: 0xF
# CREL-NEXT: HasReturn: Yes
# CREL-NEXT: HasTailCall: No
# CREL-NEXT: IsEHPad: No
# CREL-NEXT: CanFallThrough: No
# CREL-NEXT: HasIndirectBranch: No
# CREL-NEXT: }
# CREL-NEXT: ]
# CREL-NEXT: }
# CREL-NEXT: ]
# CREL-NEXT: }
# CREL-NEXT: Function {
# CREL-NEXT: At: 0x10
# CREL-NEXT: Name: <?>
# CREL-NEXT: BB Ranges [
# CREL-NEXT: {
# CREL-NEXT: Base Address: 0x10
# CREL-NEXT: BB Entries [
# CREL-NEXT: {
# CREL-NEXT: ID: 0
# CREL-NEXT: Offset: 0x0
# CREL-NEXT: Size: 0x11
# CREL-NEXT: HasReturn: No
# CREL-NEXT: HasTailCall: No
# CREL-NEXT: IsEHPad: No
# CREL-NEXT: CanFallThrough: Yes
# CREL-NEXT: HasIndirectBranch: No
# CREL-NEXT: }
# CREL-NEXT: ]
# CREL-NEXT: }
# CREL-NEXT: ]
# CREL-NEXT: }
# CREL-NEXT: ]
Loading