diff options
author | Michael Trent <mtrent@apple.com> | 2020-03-04 09:10:38 -0800 |
---|---|---|
committer | Michael Trent <mtrent@apple.com> | 2020-03-04 19:57:45 -0800 |
commit | df058699d328598e636fa79684cca45857698e97 (patch) | |
tree | f27c9f6e8b40daa0976e67b4b1baf78107afe6f4 /llvm/lib/Object/MachOObjectFile.cpp | |
parent | cc61283bf6c4cb88d23c6cbdb58b8c7481709b7e (diff) | |
download | llvm-df058699d328598e636fa79684cca45857698e97.zip llvm-df058699d328598e636fa79684cca45857698e97.tar.gz llvm-df058699d328598e636fa79684cca45857698e97.tar.bz2 |
Fix dyld opcode *_ADD_ADDR_IMM_SCALED error detection.
Summary:
Move the check for malformed REBASE_OPCODE_ADD_ADDR_IMM_SCALED and
BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED opcodes after the immediate
has been applied to the SegmentOffset. This fixes specious errors
where SegmentOffset is pointing between two sections when trying to
correct the SegmentOffset value.
Update the regression tests to verify the proper error message.
Reviewers: pete, ab, lhames, steven_wu, jhenderson
Reviewed By: pete
Subscribers: hiraditya, dexonsmith, rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75629
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 8540b7a..feea11c 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -3214,6 +3214,7 @@ void MachORebaseEntry::moveNext() { SegmentOffset) << "\n"); break; case MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED: + SegmentOffset += ImmValue * PointerSize; error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset, PointerSize); if (error) { @@ -3223,18 +3224,6 @@ void MachORebaseEntry::moveNext() { moveToEnd(); return; } - SegmentOffset += ImmValue * PointerSize; - error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset, - PointerSize); - if (error) { - *E = - malformedError("for REBASE_OPCODE_ADD_ADDR_IMM_SCALED " - " (after adding immediate times the pointer size) " + - Twine(error) + " for opcode at: 0x" + - Twine::utohexstr(OpcodeStart - Opcodes.begin())); - moveToEnd(); - return; - } DEBUG_WITH_TYPE("mach-o-rebase", dbgs() << "REBASE_OPCODE_ADD_ADDR_IMM_SCALED: " << format("SegmentOffset=0x%06X", @@ -3803,15 +3792,6 @@ void MachOBindEntry::moveNext() { moveToEnd(); return; } - error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset, - PointerSize); - if (error) { - *E = malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " + - Twine(error) + " for opcode at: 0x" + - Twine::utohexstr(OpcodeStart - Opcodes.begin())); - moveToEnd(); - return; - } if (SymbolName == StringRef()) { *E = malformedError( "for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " @@ -3835,11 +3815,9 @@ void MachOBindEntry::moveNext() { error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset + AdvanceAmount, PointerSize); if (error) { - *E = - malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " - " (after adding immediate times the pointer size) " + - Twine(error) + " for opcode at: 0x" + - Twine::utohexstr(OpcodeStart - Opcodes.begin())); + *E = malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " + + Twine(error) + " for opcode at: 0x" + + Twine::utohexstr(OpcodeStart - Opcodes.begin())); moveToEnd(); return; } |