diff options
author | Seiya Nuta <nuta@seiya.me> | 2019-08-19 05:37:38 +0000 |
---|---|---|
committer | Seiya Nuta <nuta@seiya.me> | 2019-08-19 05:37:38 +0000 |
commit | 4a198a7f990812f6a64ecb2d20d3503c66b5dea2 (patch) | |
tree | b06fcc2073839c622c2f6eac78fd6f1c19d1dab6 /llvm/tools/llvm-objcopy/MachO/Object.h | |
parent | dfe5f3eb0a0055244d019ede9214e7df8b7a9cca (diff) | |
download | bcm5719-llvm-4a198a7f990812f6a64ecb2d20d3503c66b5dea2.tar.gz bcm5719-llvm-4a198a7f990812f6a64ecb2d20d3503c66b5dea2.zip |
[llvm-objcopy][MachO] Support load commands used in executables/shared libraries
Summary:
This patch implements copying some load commands that appear in executables/shared libraries such as the indirect symbol table.
I don't add tests intentionally because this patch is incomplete: we need a layout algorithm for executables/shared libraries. I'll submit it as a separate patch with tests.
Reviewers: alexshap, rupprecht, jhenderson, compnerd
Reviewed By: alexshap
Subscribers: abrachet, mgorny, mgrang, MaskRay, mtrent, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63395
llvm-svn: 369230
Diffstat (limited to 'llvm/tools/llvm-objcopy/MachO/Object.h')
-rw-r--r-- | llvm/tools/llvm-objcopy/MachO/Object.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/MachO/Object.h b/llvm/tools/llvm-objcopy/MachO/Object.h index ed85fcbc47f..1cebf8253d1 100644 --- a/llvm/tools/llvm-objcopy/MachO/Object.h +++ b/llvm/tools/llvm-objcopy/MachO/Object.h @@ -90,6 +90,16 @@ struct SymbolEntry { uint8_t n_sect; uint16_t n_desc; uint64_t n_value; + + bool isExternalSymbol() const { + return n_type & ((MachO::N_EXT | MachO::N_PEXT)); + } + + bool isLocalSymbol() const { return !isExternalSymbol(); } + + bool isUndefinedSymbol() const { + return (n_type & MachO::N_TYPE) == MachO::N_UNDF; + } }; /// The location of the symbol table inside the binary is described by LC_SYMTAB @@ -100,6 +110,10 @@ struct SymbolTable { const SymbolEntry *getSymbolByIndex(uint32_t Index) const; }; +struct IndirectSymbolTable { + std::vector<uint32_t> Symbols; +}; + /// The location of the string table inside the binary is described by LC_SYMTAB /// load command. struct StringTable { @@ -206,6 +220,10 @@ struct ExportInfo { ArrayRef<uint8_t> Trie; }; +struct LinkData { + ArrayRef<uint8_t> Data; +}; + struct Object { MachHeader Header; std::vector<LoadCommand> LoadCommands; @@ -218,11 +236,20 @@ struct Object { WeakBindInfo WeakBinds; LazyBindInfo LazyBinds; ExportInfo Exports; + IndirectSymbolTable IndirectSymTable; + LinkData DataInCode; + LinkData FunctionStarts; /// The index of LC_SYMTAB load command if present. Optional<size_t> SymTabCommandIndex; /// The index of LC_DYLD_INFO or LC_DYLD_INFO_ONLY load command if present. Optional<size_t> DyLdInfoCommandIndex; + /// The index LC_DYSYMTAB load comamnd if present. + Optional<size_t> DySymTabCommandIndex; + /// The index LC_DATA_IN_CODE load comamnd if present. + Optional<size_t> DataInCodeCommandIndex; + /// The index LC_FUNCTION_STARTS load comamnd if present. + Optional<size_t> FunctionStartsCommandIndex; }; } // end namespace macho |