Skip to content

Commit

Permalink
[JITLink][ELF] Fix reading target architecture when the ELF object is…
Browse files Browse the repository at this point in the history
… big-endian

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D156982
  • Loading branch information
bzEq committed Aug 4, 2023
1 parent dc7c018 commit be7a546
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-relocs.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be7a546

Please sign in to comment.