Skip to content

Commit

Permalink
Add the error handling for Mach-O dyld compact lazy bind, weak bind and
Browse files Browse the repository at this point in the history
rebase entry errors and test cases for each of the error checks.

Also verified with Nick Kledzik that a BIND_OPCODE_SET_ADDEND_SLEB
opcode is legal in a lazy bind table, so code that had that as an error
check was removed.

With MachORebaseEntry and MachOBindEntry classes now returning
an llvm::Error in all cases for malformed input the variables Malformed
and logic to set use them is no longer needed and has been removed
from those classes.

Also in a few places, removed the redundant Done assignment to true
when also calling moveToEnd() as it does that assignment.

This only leaves the dyld compact export entries left to have
error handling yet to be added for the dyld compact info.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298883 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
enderby committed Mar 27, 2017
1 parent fcdf36f commit 3903b47
Show file tree
Hide file tree
Showing 22 changed files with 351 additions and 52 deletions.
24 changes: 19 additions & 5 deletions include/llvm/Object/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MachORebaseEntry {
MachORebaseEntry(Error *Err, const MachOObjectFile *O,
ArrayRef<uint8_t> opcodes, bool is64Bit);

uint32_t segmentIndex() const;
int32_t segmentIndex() const;
uint64_t segmentOffset() const;
StringRef typeName() const;
StringRef segmentName() const;
Expand All @@ -161,19 +161,18 @@ class MachORebaseEntry {
friend class MachOObjectFile;
void moveToFirst();
void moveToEnd();
uint64_t readULEB128();
uint64_t readULEB128(const char **error);

Error *E;
const MachOObjectFile *O;
ArrayRef<uint8_t> Opcodes;
const uint8_t *Ptr;
uint64_t SegmentOffset;
uint32_t SegmentIndex;
int32_t SegmentIndex;
uint64_t RemainingLoopCount;
uint64_t AdvanceAmount;
uint8_t RebaseType;
uint8_t PointerSize;
bool Malformed;
bool Done;
};
typedef content_iterator<MachORebaseEntry> rebase_iterator;
Expand Down Expand Up @@ -231,7 +230,6 @@ class MachOBindEntry {
uint8_t BindType;
uint8_t PointerSize;
Kind TableKind;
bool Malformed;
bool Done;
};
typedef content_iterator<MachOBindEntry> bind_iterator;
Expand Down Expand Up @@ -378,6 +376,22 @@ class MachOObjectFile : public ObjectFile {
SegIndex, SegOffset);
}

/// For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to
/// validate a MachORebaseEntry.
const char *RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
bool endInvalid) const {
return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
endInvalid);
}
/// For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for
/// the REBASE_OPCODE_DO_*_TIMES* opcodes.
const char *RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
uint8_t PointerSize, int32_t SegIndex,
uint64_t SegOffset) const {
return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
SegIndex, SegOffset);
}

/// For use with the SegIndex of a checked Mach-O Bind or Rebase entry to
/// get the segment name.
StringRef BindRebaseSegmentName(int32_t SegIndex) const {
Expand Down
Loading

0 comments on commit 3903b47

Please sign in to comment.