DynamicFile and ELFFile are instantiated for four different types,
ELF{32,64}{BE,LE}. Because the classes are instantiated in each
compilation unit, including the header file makes object files
10MB larger.
On Windows, issue of excessive template instantiation is critical,
since the regular COFF file supports only up to 65534 sections.
(We could use the extended COFF file format, but generating that
much COMDAT sections is not a good thing in the first place
because it means long compile time and long link time.)
I confirmed that this change makes AArch64TargetHandler.cpp.o
from 21MB to 8.5MB. It feels still too large, but I think it's
a good start.
llvm-svn: 234808
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
//===- lib/ReaderWriter/ELF/DynamicFile.h ---------------------------------===//
|
|
//
|
|
// The LLVM Linker
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_READER_WRITER_ELF_DYNAMIC_FILE_H
|
|
#define LLD_READER_WRITER_ELF_DYNAMIC_FILE_H
|
|
|
|
#include "Atoms.h"
|
|
#include "lld/Core/SharedLibraryFile.h"
|
|
#include <unordered_map>
|
|
|
|
namespace lld {
|
|
class ELFLinkingContext;
|
|
|
|
namespace elf {
|
|
|
|
template <class ELFT> class DynamicFile : public SharedLibraryFile {
|
|
public:
|
|
static ErrorOr<std::unique_ptr<DynamicFile>>
|
|
create(std::unique_ptr<llvm::MemoryBuffer> mb, ELFLinkingContext &ctx);
|
|
|
|
DynamicFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx);
|
|
|
|
const SharedLibraryAtom *exports(StringRef name,
|
|
bool dataSymbolOnly) const override;
|
|
|
|
StringRef getDSOName() const override;
|
|
|
|
static bool canParse(file_magic magic);
|
|
|
|
protected:
|
|
std::error_code doParse() override;
|
|
|
|
private:
|
|
mutable llvm::BumpPtrAllocator _alloc;
|
|
std::unique_ptr<llvm::object::ELFFile<ELFT>> _objFile;
|
|
/// \brief DT_SONAME
|
|
StringRef _soname;
|
|
|
|
struct SymAtomPair {
|
|
const typename llvm::object::ELFFile<ELFT>::Elf_Sym *_symbol = nullptr;
|
|
const SharedLibraryAtom *_atom = nullptr;
|
|
};
|
|
|
|
std::unique_ptr<MemoryBuffer> _mb;
|
|
ELFLinkingContext &_ctx;
|
|
bool _useShlibUndefines;
|
|
mutable std::unordered_map<StringRef, SymAtomPair> _nameToSym;
|
|
};
|
|
|
|
} // end namespace elf
|
|
} // end namespace lld
|
|
|
|
#endif
|