[llvm] a6f1976 - [llvm-objcopy][MachO] Correctly identify object file endianness.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 21:54:13 PDT 2020
Author: Lang Hames
Date: 2020-04-16T21:54:01-07:00
New Revision: a6f19762c6d9d3ff4074b85194c9409635aa8014
URL: https://github.com/llvm/llvm-project/commit/a6f19762c6d9d3ff4074b85194c9409635aa8014
DIFF: https://github.com/llvm/llvm-project/commit/a6f19762c6d9d3ff4074b85194c9409635aa8014.diff
LOG: [llvm-objcopy][MachO] Correctly identify object file endianness.
The header magic value is held in the native endianness, so the method used in
cc0ec3fdb9d. Use MachOReader / MachOWriter's existing endianness tests instead.
Added:
Modified:
llvm/tools/llvm-objcopy/MachO/MachOReader.cpp
llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp
llvm/tools/llvm-objcopy/MachO/Object.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-objcopy/MachO/MachOReader.cpp b/llvm/tools/llvm-objcopy/MachO/MachOReader.cpp
index e2eeee4ab5f4..6d08e3abccf5 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOReader.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOReader.cpp
@@ -206,7 +206,7 @@ void MachOReader::setSymbolInRelocationInfo(Object &O) const {
for (auto &Reloc : Sec->Relocations)
if (!Reloc.Scattered)
Reloc.Symbol = O.SymTable.getSymbolByIndex(
- Reloc.getPlainRelocationSymbolNum(O.isLittleEndian()));
+ Reloc.getPlainRelocationSymbolNum(MachOObj.isLittleEndian()));
}
void MachOReader::readRebaseInfo(Object &O) const {
diff --git a/llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp b/llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp
index a08d54d59723..db31ef518aa8 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp
@@ -242,7 +242,7 @@ void MachOWriter::writeSections() {
auto RelocInfo = Sec->Relocations[Index];
if (!RelocInfo.Scattered)
RelocInfo.setPlainRelocationSymbolNum(RelocInfo.Symbol->Index,
- O.isLittleEndian());
+ IsLittleEndian);
if (IsLittleEndian != sys::IsLittleEndianHost)
MachO::swapStruct(
diff --git a/llvm/tools/llvm-objcopy/MachO/Object.h b/llvm/tools/llvm-objcopy/MachO/Object.h
index c834105a00aa..d0d4554d7560 100644
--- a/llvm/tools/llvm-objcopy/MachO/Object.h
+++ b/llvm/tools/llvm-objcopy/MachO/Object.h
@@ -314,11 +314,6 @@ struct Object {
/// is not too long (SegName.size() should be less than or equal to 16).
LoadCommand &addSegment(StringRef SegName);
- bool isLittleEndian() const {
- StringRef Magic(reinterpret_cast<const char *>(&Header.Magic), 4);
- return Magic == "\xCE\xFA\xED\xFE" || Magic == "\xCF\xFA\xED\xFE";
- }
-
bool is64Bit() const {
return Header.Magic == MachO::MH_MAGIC_64 ||
Header.Magic == MachO::MH_CIGAM_64;
More information about the llvm-commits
mailing list