[llvm] be7a546 - [JITLink][ELF] Fix reading target architecture when the ELF object is big-endian
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 19:55:46 PDT 2023
Author: Kai Luo
Date: 2023-08-04T10:55:38+08:00
New Revision: be7a54655c4a505bac8642b378d51acdc9fddd17
URL: https://github.com/llvm/llvm-project/commit/be7a54655c4a505bac8642b378d51acdc9fddd17
DIFF: https://github.com/llvm/llvm-project/commit/be7a54655c4a505bac8642b378d51acdc9fddd17.diff
LOG: [JITLink][ELF] Fix reading target architecture when the ELF object is big-endian
Reviewed By: lhames
Differential Revision: https://reviews.llvm.org/D156982
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/ELF.cpp
llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
index dd08a23306ffc4..d60f33f5d011b6 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
@@ -52,6 +52,22 @@ Expected<uint16_t> readTargetMachineArch(StringRef Buffer) {
}
}
+ if (Data[ELF::EI_DATA] == ELF::ELFDATA2MSB) {
+ if (Data[ELF::EI_CLASS] == ELF::ELFCLASS64) {
+ if (auto File = llvm::object::ELF64BEFile::create(Buffer)) {
+ return File->getHeader().e_machine;
+ } else {
+ return File.takeError();
+ }
+ } else if (Data[ELF::EI_CLASS] == ELF::ELFCLASS32) {
+ if (auto File = llvm::object::ELF32BEFile::create(Buffer)) {
+ return File->getHeader().e_machine;
+ } else {
+ return File.takeError();
+ }
+ }
+ }
+
return ELF::EM_NONE;
}
diff --git a/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s b/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s
index 1e7b6c73725ed7..6f6aa33289816b 100644
--- a/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s
+++ b/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s
@@ -2,7 +2,7 @@
# RUN: llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
# RUN: foo=0xffff8800 -noexec %t
# RUN: llvm-mc -triple=powerpc64-unknown-linux-gnu -filetype=obj -o %t %s
-# RUN: not llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
+# RUN: llvm-jitlink -abs external_var=0xffff0000 -abs puts=0xffff6400 -abs \
# RUN: foo=0xffff8800 -noexec %t
#
# Check typical relocations involving external function call, external variable
More information about the llvm-commits
mailing list