diff options
author | Rui Ueyama <ruiu@google.com> | 2015-08-28 05:47:46 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-08-28 05:47:46 +0000 |
commit | 22b1b7aad235d614a0de578cba62498b288dd830 (patch) | |
tree | c892bee7135f38f0872d9d937129791c06fd57dd /llvm/lib/Object/SymbolicFile.cpp | |
parent | 1e051aab0cc12bb4a4c1be8d1b1b70537fd0f012 (diff) | |
download | bcm5719-llvm-22b1b7aad235d614a0de578cba62498b288dd830.tar.gz bcm5719-llvm-22b1b7aad235d614a0de578cba62498b288dd830.zip |
Object: Teach llvm-ar to create symbol table for COFF short import files.
COFF short import files are special kind of files that contains only
DLL-exported symbol names. That's different from object files because
it has no data except symbol names.
This change implements a SymbolicFile interface for the short import
files so that symbol names can be accessed through that interface.
llvm-ar is now able to read the file and create symbol table entries
for short import files.
llvm-svn: 246276
Diffstat (limited to 'llvm/lib/Object/SymbolicFile.cpp')
-rw-r--r-- | llvm/lib/Object/SymbolicFile.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/llvm/lib/Object/SymbolicFile.cpp b/llvm/lib/Object/SymbolicFile.cpp index 854e68e40f4..c3106319c7f 100644 --- a/llvm/lib/Object/SymbolicFile.cpp +++ b/llvm/lib/Object/SymbolicFile.cpp @@ -11,14 +11,58 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Object/COFF.h" #include "llvm/Object/IRObjectFile.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Object/SymbolicFile.h" +#include "llvm/Support/COFF.h" #include "llvm/Support/MemoryBuffer.h" using namespace llvm; using namespace object; +// COFF short import file is a special kind of file which contains +// only symbol names for DLL-exported symbols. This class implements +// SymbolicFile interface for the file. +namespace { +class COFFImportFile : public SymbolicFile { +public: + COFFImportFile(MemoryBufferRef Source) + : SymbolicFile(sys::fs::file_magic::coff_import_library, Source) {} + + void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; } + + std::error_code printSymbolName(raw_ostream &OS, + DataRefImpl Symb) const override { + if (Symb.p == 1) + OS << "__imp_"; + OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header)); + return std::error_code(); + } + + uint32_t getSymbolFlags(DataRefImpl Symb) const override { + return SymbolRef::SF_Global; + } + + basic_symbol_iterator symbol_begin_impl() const override { + return BasicSymbolRef(DataRefImpl(), this); + } + + basic_symbol_iterator symbol_end_impl() const override { + DataRefImpl Symb; + Symb.p = isCode() ? 2 : 1; + return BasicSymbolRef(Symb, this); + } + +private: + bool isCode() const { + auto *Import = reinterpret_cast<const coff_import_header *>( + Data.getBufferStart()); + return Import->getType() == llvm::COFF::IMPORT_CODE; + } +}; +} // anonymous namespace + SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source) : Binary(Type, Source) {} @@ -54,9 +98,10 @@ ErrorOr<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile( case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub: case sys::fs::file_magic::macho_dsym_companion: case sys::fs::file_magic::macho_kext_bundle: - case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: return ObjectFile::createObjectFile(Object, Type); + case sys::fs::file_magic::coff_import_library: + return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object)); case sys::fs::file_magic::elf_relocatable: case sys::fs::file_magic::macho_object: case sys::fs::file_magic::coff_object: { |