diff options
author | Michael Trent <mtrent@apple.com> | 2017-12-15 17:57:40 +0000 |
---|---|---|
committer | Michael Trent <mtrent@apple.com> | 2017-12-15 17:57:40 +0000 |
commit | 6469bc65e33d0f2f3e0577a5f82ddb34d310f818 (patch) | |
tree | 9873dfb7e15c02da3a0cdecb5d4bb36f2dde2199 /lib/Object | |
parent | 2a6a25b91be31cb54c1f19ecca2b0b462fd097a2 (diff) |
Updated llvm-objdump to display local relocations in Mach-O binaries
Summary:
llvm-objdump's Mach-O parser was updated in r306037 to display external
relocations for MH_KEXT_BUNDLE file types. This change extends the Macho-O
parser to display local relocations for MH_PRELOAD files. When used with
the -macho option relocations will be displayed in a historical format.
All tests are passing for llvm, clang, and lld. llvm-objdump builds without
compiler warnings.
rdar://35778019
Reviewers: enderby
Reviewed By: enderby
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D41199
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320832 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object')
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 83becc41319..2e3415618e5 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1960,6 +1960,7 @@ MachOObjectFile::section_rel_end(DataRefImpl Sec) const { relocation_iterator MachOObjectFile::extrel_begin() const { DataRefImpl Ret; + // for DYSYMTAB symbols, Ret.d.a == 0 for external relocations Ret.d.a = 0; // Would normally be a section index. Ret.d.b = 0; // Index into the external relocations return relocation_iterator(RelocationRef(Ret, this)); @@ -1968,11 +1969,29 @@ relocation_iterator MachOObjectFile::extrel_begin() const { relocation_iterator MachOObjectFile::extrel_end() const { MachO::dysymtab_command DysymtabLoadCmd = getDysymtabLoadCommand(); DataRefImpl Ret; + // for DYSYMTAB symbols, Ret.d.a == 0 for external relocations Ret.d.a = 0; // Would normally be a section index. Ret.d.b = DysymtabLoadCmd.nextrel; // Index into the external relocations return relocation_iterator(RelocationRef(Ret, this)); } +relocation_iterator MachOObjectFile::locrel_begin() const { + DataRefImpl Ret; + // for DYSYMTAB symbols, Ret.d.a == 1 for local relocations + Ret.d.a = 1; // Would normally be a section index. + Ret.d.b = 0; // Index into the local relocations + return relocation_iterator(RelocationRef(Ret, this)); +} + +relocation_iterator MachOObjectFile::locrel_end() const { + MachO::dysymtab_command DysymtabLoadCmd = getDysymtabLoadCommand(); + DataRefImpl Ret; + // for DYSYMTAB symbols, Ret.d.a == 1 for local relocations + Ret.d.a = 1; // Would normally be a section index. + Ret.d.b = DysymtabLoadCmd.nlocrel; // Index into the local relocations + return relocation_iterator(RelocationRef(Ret, this)); +} + void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const { ++Rel.d.b; } @@ -4301,7 +4320,10 @@ MachOObjectFile::getRelocation(DataRefImpl Rel) const { } } else { MachO::dysymtab_command DysymtabLoadCmd = getDysymtabLoadCommand(); - Offset = DysymtabLoadCmd.extreloff; // Offset to the external relocations + if (Rel.d.a == 0) + Offset = DysymtabLoadCmd.extreloff; // Offset to the external relocations + else + Offset = DysymtabLoadCmd.locreloff; // Offset to the local relocations } auto P = reinterpret_cast<const MachO::any_relocation_info *>( |