Skip to content

Commit be7a546

Browse files
author
Kai Luo
committed
[JITLink][ELF] Fix reading target architecture when the ELF object is big-endian
Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D156982
1 parent dc7c018 commit be7a546

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/ExecutionEngine/JITLink/ELF.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ Expected<uint16_t> readTargetMachineArch(StringRef Buffer) {
5252
}
5353
}
5454

55+
if (Data[ELF::EI_DATA] == ELF::ELFDATA2MSB) {
56+
if (Data[ELF::EI_CLASS] == ELF::ELFCLASS64) {
57+
if (auto File = llvm::object::ELF64BEFile::create(Buffer)) {
58+
return File->getHeader().e_machine;
59+
} else {
60+
return File.takeError();
61+
}
62+
} else if (Data[ELF::EI_CLASS] == ELF::ELFCLASS32) {
63+
if (auto File = llvm::object::ELF32BEFile::create(Buffer)) {
64+
return File->getHeader().e_machine;
65+
} else {
66+
return File.takeError();
67+
}
68+
}
69+
}
70+
5571
return ELF::EM_NONE;
5672
}
5773

llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
33
# RUN: foo=0xffff8800 -noexec %t
44
# RUN: llvm-mc -triple=powerpc64-unknown-linux-gnu -filetype=obj -o %t %s
5-
# RUN: not llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
5+
# RUN: llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
66
# RUN: foo=0xffff8800 -noexec %t
77
#
88
# Check typical relocations involving external function call, external variable

0 commit comments

Comments
 (0)