diff options
Diffstat (limited to 'contrib/llvm/tools/lld/ELF/InputFiles.h')
-rw-r--r-- | contrib/llvm/tools/lld/ELF/InputFiles.h | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/contrib/llvm/tools/lld/ELF/InputFiles.h b/contrib/llvm/tools/lld/ELF/InputFiles.h index 70109f002e98..0db3203b0ba2 100644 --- a/contrib/llvm/tools/lld/ELF/InputFiles.h +++ b/contrib/llvm/tools/lld/ELF/InputFiles.h @@ -12,22 +12,20 @@ #include "Config.h" #include "lld/Common/ErrorHandler.h" - #include "lld/Common/LLVM.h" #include "lld/Common/Reproduce.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" #include "llvm/IR/Comdat.h" #include "llvm/Object/Archive.h" #include "llvm/Object/ELF.h" #include "llvm/Object/IRObjectFile.h" #include "llvm/Support/Threading.h" - #include <map> namespace llvm { -class DWARFDebugLine; class TarWriter; struct DILineInfo; namespace lto { @@ -48,7 +46,6 @@ namespace elf { using llvm::object::Archive; -class Lazy; class Symbol; // If -reproduce option is given, all input files are written @@ -90,15 +87,15 @@ public: // Returns object file symbols. It is a runtime error to call this // function on files of other types. ArrayRef<Symbol *> getSymbols() { - assert(FileKind == ObjKind || FileKind == BitcodeKind || - FileKind == ArchiveKind); + assert(FileKind == BinaryKind || FileKind == ObjKind || + FileKind == BitcodeKind); return Symbols; } // Filename of .a which contained this file. If this file was // not in an archive file, it is the empty string. We use this // string for creating error messages. - StringRef ArchiveName; + std::string ArchiveName; // If this is an architecture-specific file, the following members // have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type. @@ -112,6 +109,20 @@ public: std::string getSrcMsg(const Symbol &Sym, InputSectionBase &Sec, uint64_t Offset); + // True if this is an argument for --just-symbols. Usually false. + bool JustSymbols = false; + + // GroupId is used for --warn-backrefs which is an optional error + // checking feature. All files within the same --{start,end}-group or + // --{start,end}-lib get the same group ID. Otherwise, each file gets a new + // group ID. For more info, see checkDependency() in SymbolTable.cpp. + uint32_t GroupId; + static bool IsInGroup; + static uint32_t NextGroupId; + + // Index of MIPS GOT built for this file. + llvm::Optional<size_t> MipsGotIndex; + protected: InputFile(Kind K, MemoryBufferRef M); std::vector<InputSectionBase *> Sections; @@ -144,7 +155,7 @@ public: protected: ArrayRef<Elf_Sym> ELFSyms; - uint32_t FirstNonLocal = 0; + uint32_t FirstGlobal = 0; ArrayRef<Elf_Word> SymtabSHNDX; StringRef StringTable; void initSymtab(ArrayRef<Elf_Shdr> Sections, const Elf_Shdr *Symtab); @@ -183,9 +194,6 @@ public: return getSymbol(SymIndex); } - // Returns source line information for a given offset. - // If no information is available, returns "". - std::string getLineInfo(InputSectionBase *S, uint64_t Offset); llvm::Optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t); llvm::Optional<std::pair<std::string, unsigned>> getVariableLoc(StringRef Name); @@ -199,10 +207,22 @@ public: // symbol table. StringRef SourceFile; + // True if the file defines functions compiled with + // -fsplit-stack. Usually false. + bool SplitStack = false; + + // True if the file defines functions compiled with -fsplit-stack, + // but had one or more functions with the no_split_stack attribute. + bool SomeNoSplitStack = false; + + // Pointer to this input file's .llvm_addrsig section, if it has one. + const Elf_Shdr *AddrsigSec = nullptr; + private: void initializeSections(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups); void initializeSymbols(); + void initializeJustSymbols(); void initializeDwarf(); InputSectionBase *getRelocTarget(const Elf_Shdr &Sec); InputSectionBase *createInputSection(const Elf_Shdr &Sec); @@ -218,8 +238,14 @@ private: // reporting. Linker may find reasonable number of errors in a // single object file, so we cache debugging information in order to // parse it only once for each object file we link. - std::unique_ptr<llvm::DWARFDebugLine> DwarfLine; - llvm::DenseMap<StringRef, std::pair<unsigned, unsigned>> VariableLoc; + std::unique_ptr<llvm::DWARFContext> Dwarf; + std::vector<const llvm::DWARFDebugLine::LineTable *> LineTables; + struct VarLoc { + const llvm::DWARFDebugLine::LineTable *LT; + unsigned File; + unsigned Line; + }; + llvm::DenseMap<StringRef, VarLoc> VariableLoc; llvm::once_flag InitDwarfLine; }; @@ -243,13 +269,11 @@ public: template <class ELFT> void parse(); MemoryBufferRef getBuffer(); InputFile *fetch(); + bool AddedToLink = false; private: - std::vector<StringRef> getSymbolNames(); - template <class ELFT> std::vector<StringRef> getElfSymbols(); - std::vector<StringRef> getBitcodeSymbols(); + template <class ELFT> void addElfSymbols(); - bool Seen = false; uint64_t OffsetInArchive; }; @@ -260,11 +284,11 @@ public: static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; } template <class ELFT> void parse(); - // Returns a memory buffer for a given symbol and the offset in the archive - // for the member. An empty memory buffer and an offset of zero - // is returned if we have already returned the same memory buffer. - // (So that we don't instantiate same members more than once.) - std::pair<MemoryBufferRef, uint64_t> getMember(const Archive::Symbol *Sym); + // Pulls out an object file that contains a definition for Sym and + // returns it. If the same file was instantiated before, this + // function returns a nullptr (so we don't instantiate the same file + // more than once.) + InputFile *fetch(const Archive::Symbol &Sym); private: std::unique_ptr<Archive> File; @@ -291,7 +315,6 @@ template <class ELFT> class SharedFile : public ELFFileBase<ELFT> { typedef typename ELFT::Verdef Elf_Verdef; typedef typename ELFT::Versym Elf_Versym; - std::vector<StringRef> Undefs; const Elf_Shdr *VersymSec = nullptr; const Elf_Shdr *VerdefSec = nullptr; @@ -299,8 +322,6 @@ public: std::vector<const Elf_Verdef *> Verdefs; std::string SoName; - llvm::ArrayRef<StringRef> getUndefinedSymbols() { return Undefs; } - static bool classof(const InputFile *F) { return F->kind() == Base::SharedKind; } @@ -309,7 +330,9 @@ public: void parseSoName(); void parseRest(); - std::vector<const Elf_Verdef *> parseVerdefs(const Elf_Versym *&Versym); + uint32_t getAlignment(ArrayRef<Elf_Shdr> Sections, const Elf_Sym &Sym); + std::vector<const Elf_Verdef *> parseVerdefs(); + std::vector<uint32_t> parseVersyms(); struct NeededVer { // The string table offset of the version name in the output file. @@ -338,8 +361,15 @@ InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "", uint64_t OffsetInArchive = 0); InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName); +inline bool isBitcode(MemoryBufferRef MB) { + return identify_magic(MB.getBuffer()) == llvm::file_magic::bitcode; +} + +std::string replaceThinLTOSuffix(StringRef Path); + extern std::vector<BinaryFile *> BinaryFiles; extern std::vector<BitcodeFile *> BitcodeFiles; +extern std::vector<LazyObjFile *> LazyObjFiles; extern std::vector<InputFile *> ObjectFiles; extern std::vector<InputFile *> SharedFiles; |