Skip to content

Commit a6f1976

Browse files
committed
[llvm-objcopy][MachO] Correctly identify object file endianness.
The header magic value is held in the native endianness, so the method used in cc0ec3f. Use MachOReader / MachOWriter's existing endianness tests instead.
1 parent 186709c commit a6f1976

File tree

3 files changed

+2
-7
lines changed

3 files changed

+2
-7
lines changed

llvm/tools/llvm-objcopy/MachO/MachOReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void MachOReader::setSymbolInRelocationInfo(Object &O) const {
206206
for (auto &Reloc : Sec->Relocations)
207207
if (!Reloc.Scattered)
208208
Reloc.Symbol = O.SymTable.getSymbolByIndex(
209-
Reloc.getPlainRelocationSymbolNum(O.isLittleEndian()));
209+
Reloc.getPlainRelocationSymbolNum(MachOObj.isLittleEndian()));
210210
}
211211

212212
void MachOReader::readRebaseInfo(Object &O) const {

llvm/tools/llvm-objcopy/MachO/MachOWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void MachOWriter::writeSections() {
242242
auto RelocInfo = Sec->Relocations[Index];
243243
if (!RelocInfo.Scattered)
244244
RelocInfo.setPlainRelocationSymbolNum(RelocInfo.Symbol->Index,
245-
O.isLittleEndian());
245+
IsLittleEndian);
246246

247247
if (IsLittleEndian != sys::IsLittleEndianHost)
248248
MachO::swapStruct(

llvm/tools/llvm-objcopy/MachO/Object.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ struct Object {
314314
/// is not too long (SegName.size() should be less than or equal to 16).
315315
LoadCommand &addSegment(StringRef SegName);
316316

317-
bool isLittleEndian() const {
318-
StringRef Magic(reinterpret_cast<const char *>(&Header.Magic), 4);
319-
return Magic == "\xCE\xFA\xED\xFE" || Magic == "\xCF\xFA\xED\xFE";
320-
}
321-
322317
bool is64Bit() const {
323318
return Header.Magic == MachO::MH_MAGIC_64 ||
324319
Header.Magic == MachO::MH_CIGAM_64;

0 commit comments

Comments
 (0)