2015-08-14 22:12:54 +08:00
|
|
|
//===- InputFiles.h ---------------------------------------------*- C++ -*-===//
|
2015-05-29 03:09:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-05-29 03:09:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_COFF_INPUT_FILES_H
|
|
|
|
#define LLD_COFF_INPUT_FILES_H
|
|
|
|
|
2017-05-25 06:30:06 +08:00
|
|
|
#include "Config.h"
|
2017-10-03 05:00:41 +08:00
|
|
|
#include "lld/Common/LLVM.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2018-08-07 05:26:09 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2016-12-12 11:16:14 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2018-11-06 03:20:47 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
|
2017-02-03 07:58:14 +08:00
|
|
|
#include "llvm/LTO/LTO.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/COFF.h"
|
2015-06-13 20:50:13 +08:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-06-13 23:49:13 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace pdb {
|
|
|
|
class DbiModuleDescriptorBuilder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace coff {
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<MemoryBufferRef> getArchiveMembers(llvm::object::Archive *file);
|
2017-08-31 04:55:18 +08:00
|
|
|
|
2015-07-10 03:54:13 +08:00
|
|
|
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
|
|
|
using llvm::COFF::MachineTypes;
|
2015-05-29 03:09:30 +08:00
|
|
|
using llvm::object::Archive;
|
|
|
|
using llvm::object::COFFObjectFile;
|
2015-06-30 02:50:11 +08:00
|
|
|
using llvm::object::COFFSymbolRef;
|
2016-12-10 05:55:24 +08:00
|
|
|
using llvm::object::coff_import_header;
|
2015-07-25 07:51:14 +08:00
|
|
|
using llvm::object::coff_section;
|
2015-06-30 02:50:11 +08:00
|
|
|
|
|
|
|
class Chunk;
|
2015-06-30 06:16:21 +08:00
|
|
|
class Defined;
|
2015-08-17 15:27:45 +08:00
|
|
|
class DefinedImportData;
|
|
|
|
class DefinedImportThunk;
|
2019-02-14 11:16:44 +08:00
|
|
|
class DefinedRegular;
|
2015-07-01 03:35:21 +08:00
|
|
|
class Lazy;
|
2016-11-22 01:22:35 +08:00
|
|
|
class SectionChunk;
|
2017-11-04 05:21:47 +08:00
|
|
|
class Symbol;
|
2015-06-30 06:16:21 +08:00
|
|
|
class Undefined;
|
[LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.
Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.
The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.
Differential Revision: https://reviews.llvm.org/D59053
llvm-svn: 357383
2019-04-01 21:36:59 +08:00
|
|
|
class TpiSource;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
|
|
|
// The root class of input files.
|
|
|
|
class InputFile {
|
|
|
|
public:
|
2015-06-02 04:10:10 +08:00
|
|
|
enum Kind { ArchiveKind, ObjectKind, ImportKind, BitcodeKind };
|
2019-07-11 13:40:30 +08:00
|
|
|
Kind kind() const { return fileKind; }
|
2015-05-29 03:09:30 +08:00
|
|
|
virtual ~InputFile() {}
|
|
|
|
|
|
|
|
// Returns the filename.
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef getName() const { return mb.getBufferIdentifier(); }
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2015-08-07 03:57:21 +08:00
|
|
|
// Reads a file (the constructor doesn't do that).
|
2015-08-06 22:58:50 +08:00
|
|
|
virtual void parse() = 0;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2015-07-10 03:54:13 +08:00
|
|
|
// Returns the CPU type this file was compiled to.
|
|
|
|
virtual MachineTypes getMachineType() { return IMAGE_FILE_MACHINE_UNKNOWN; }
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
MemoryBufferRef mb;
|
2017-04-22 05:38:01 +08:00
|
|
|
|
2016-12-08 07:17:02 +08:00
|
|
|
// An archive file name if this file is created from an archive.
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef parentName;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2015-06-08 14:00:10 +08:00
|
|
|
// Returns .drectve section contents if exist.
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef getDirectives() { return directives; }
|
2015-06-08 14:00:10 +08:00
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
protected:
|
2019-07-11 13:40:30 +08:00
|
|
|
InputFile(Kind k, MemoryBufferRef m) : mb(m), fileKind(k) {}
|
2015-07-03 04:33:48 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef directives;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
|
|
|
private:
|
2019-07-11 13:40:30 +08:00
|
|
|
const Kind fileKind;
|
2015-05-29 03:09:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// .lib or .a file.
|
|
|
|
class ArchiveFile : public InputFile {
|
|
|
|
public:
|
2019-07-11 13:40:30 +08:00
|
|
|
explicit ArchiveFile(MemoryBufferRef m);
|
|
|
|
static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
|
2015-08-06 22:58:50 +08:00
|
|
|
void parse() override;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2016-12-15 12:02:23 +08:00
|
|
|
// Enqueues an archive member load for the given symbol. If we've already
|
|
|
|
// enqueued a load for the same archive member, this function does nothing,
|
|
|
|
// which ensures that we don't load the same member more than once.
|
2019-07-19 21:29:10 +08:00
|
|
|
void addMember(const Archive::Symbol &sym);
|
2015-05-29 03:09:30 +08:00
|
|
|
|
|
|
|
private:
|
2019-07-11 13:40:30 +08:00
|
|
|
std::unique_ptr<Archive> file;
|
|
|
|
llvm::DenseSet<uint64_t> seen;
|
2015-05-29 03:09:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// .obj or .o file. This may be a member of an archive file.
|
2017-07-27 07:05:24 +08:00
|
|
|
class ObjFile : public InputFile {
|
2015-05-29 03:09:30 +08:00
|
|
|
public:
|
2019-07-11 13:40:30 +08:00
|
|
|
explicit ObjFile(MemoryBufferRef m) : InputFile(ObjectKind, m) {}
|
|
|
|
static bool classof(const InputFile *f) { return f->kind() == ObjectKind; }
|
2015-08-06 22:58:50 +08:00
|
|
|
void parse() override;
|
2015-07-10 03:54:13 +08:00
|
|
|
MachineTypes getMachineType() override;
|
2019-07-11 13:40:30 +08:00
|
|
|
ArrayRef<Chunk *> getChunks() { return chunks; }
|
|
|
|
ArrayRef<SectionChunk *> getDebugChunks() { return debugChunks; }
|
|
|
|
ArrayRef<SectionChunk *> getSXDataChunks() { return sXDataChunks; }
|
|
|
|
ArrayRef<SectionChunk *> getGuardFidChunks() { return guardFidChunks; }
|
|
|
|
ArrayRef<SectionChunk *> getGuardLJmpChunks() { return guardLJmpChunks; }
|
|
|
|
ArrayRef<Symbol *> getSymbols() { return symbols; }
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
ArrayRef<uint8_t> getDebugSection(StringRef secName);
|
2019-02-23 09:46:18 +08:00
|
|
|
|
2019-07-16 16:26:38 +08:00
|
|
|
// Returns a Symbol object for the symbolIndex'th symbol in the
|
2015-05-29 03:09:30 +08:00
|
|
|
// underlying object file.
|
2019-07-11 13:40:30 +08:00
|
|
|
Symbol *getSymbol(uint32_t symbolIndex) {
|
|
|
|
return symbols[symbolIndex];
|
2015-06-27 11:40:10 +08:00
|
|
|
}
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2018-11-06 03:20:47 +08:00
|
|
|
// Returns the underlying COFF file.
|
2019-07-11 13:40:30 +08:00
|
|
|
COFFObjectFile *getCOFFObj() { return coffObj.get(); }
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2019-03-29 02:30:03 +08:00
|
|
|
// Add a symbol for a range extension thunk. Return the new symbol table
|
|
|
|
// index. This index can be used to modify a relocation.
|
2019-07-11 13:40:30 +08:00
|
|
|
uint32_t addRangeThunkSymbol(Symbol *thunk) {
|
|
|
|
symbols.push_back(thunk);
|
|
|
|
return symbols.size() - 1;
|
2019-03-29 02:30:03 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
static std::vector<ObjFile *> instances;
|
2017-07-27 08:45:26 +08:00
|
|
|
|
2018-02-06 09:58:26 +08:00
|
|
|
// Flags in the absolute @feat.00 symbol if it is present. These usually
|
|
|
|
// indicate if an object was compiled with certain security features enabled
|
|
|
|
// like stack guard, safeseh, /guard:cf, or other things.
|
2019-07-11 13:40:30 +08:00
|
|
|
uint32_t feat00Flags = 0;
|
2015-07-25 07:51:14 +08:00
|
|
|
|
2018-02-06 09:58:26 +08:00
|
|
|
// True if this object file is compatible with SEH. COFF-specific and
|
|
|
|
// x86-only. COFF spec 5.10.1. The .sxdata section.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool hasSafeSEH() { return feat00Flags & 0x1; }
|
2018-02-06 09:58:26 +08:00
|
|
|
|
|
|
|
// True if this file was compiled with /guard:cf.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool hasGuardCF() { return feat00Flags & 0x800; }
|
2015-07-25 07:51:14 +08:00
|
|
|
|
2017-06-13 23:49:13 +08:00
|
|
|
// Pointer to the PDB module descriptor builder. Various debug info records
|
|
|
|
// will reference object files by "module index", which is here. Things like
|
|
|
|
// source files and section contributions are also recorded here. Will be null
|
|
|
|
// if we are not producing a PDB.
|
2019-07-11 13:40:30 +08:00
|
|
|
llvm::pdb::DbiModuleDescriptorBuilder *moduleDBI = nullptr;
|
2017-06-13 23:49:13 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
const coff_section *addrsigSec = nullptr;
|
2018-08-24 01:44:42 +08:00
|
|
|
|
2018-11-06 03:20:47 +08:00
|
|
|
// When using Microsoft precompiled headers, this is the PCH's key.
|
|
|
|
// The same key is used by both the precompiled object, and objects using the
|
|
|
|
// precompiled object. Any difference indicates out-of-date objects.
|
2019-07-11 13:40:30 +08:00
|
|
|
llvm::Optional<uint32_t> pchSignature;
|
2018-11-06 03:20:47 +08:00
|
|
|
|
lld-link: Reject more than one resource .obj file
Users are exepcted to pass all .res files to the linker, which then
merges all the resource in all .res files into a tree structure and then
converts the final tree structure to a .obj file with .rsrc$01 and
.rsrc$02 sections and then links that.
If the user instead passes several .obj files containing such resources,
the correct thing to do would be to have custom code to merge the trees
in the resource sections instead of doing normal section merging -- but
link.exe rejects if multiple resource obj files are passed in with
LNK4078, so let lld-link do that too instead of silently writing broken
.rsrc sections in that case.
The only real way to run into this is if users manually convert .res
files to .obj files by running cvtres and then handing the resulting
.obj files to lld-link instead, which in practice likely never happens.
(lld-link is slightly stricter than link.exe now: If link.exe is passed
one .obj file created by cvtres, and a .res file, for some reason it
just emits a warning instead of an error and outputs strange looking
data. lld-link now errors out on mixed input like this.)
One way users could accidentally run into this is the following
scenario: If a .res file is passed to lib.exe, then lib.exe calls
cvtres.exe on the .res file before putting it in the output .lib.
(llvm-lib currently doesn't do this.)
link.exe's /wholearchive seems to only add obj files referenced from the
static library index, but lld-link current really adds all files in the
archive. So if lld-link /wholearchive is used with .lib files produced
by lib.exe and .res files were among the files handed to lib.exe, we
previously silently produced invalid output, but now we error out.
link.exe's /wholearchive semantics on the other hand mean that it
wouldn't load the resource object files from the .lib file at all.
Since this scenario is probably still an unlikely corner case,
the difference in behavior here seems fine -- and lld-link might have to
change to use link.exe's /wholearchive semantics in the future anyways.
Vaguely related to PR42180.
Differential Revision: https://reviews.llvm.org/D63109
llvm-svn: 363078
2019-06-11 23:22:28 +08:00
|
|
|
// Whether this is an object file created from .res files.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool isResourceObjFile = false;
|
lld-link: Reject more than one resource .obj file
Users are exepcted to pass all .res files to the linker, which then
merges all the resource in all .res files into a tree structure and then
converts the final tree structure to a .obj file with .rsrc$01 and
.rsrc$02 sections and then links that.
If the user instead passes several .obj files containing such resources,
the correct thing to do would be to have custom code to merge the trees
in the resource sections instead of doing normal section merging -- but
link.exe rejects if multiple resource obj files are passed in with
LNK4078, so let lld-link do that too instead of silently writing broken
.rsrc sections in that case.
The only real way to run into this is if users manually convert .res
files to .obj files by running cvtres and then handing the resulting
.obj files to lld-link instead, which in practice likely never happens.
(lld-link is slightly stricter than link.exe now: If link.exe is passed
one .obj file created by cvtres, and a .res file, for some reason it
just emits a warning instead of an error and outputs strange looking
data. lld-link now errors out on mixed input like this.)
One way users could accidentally run into this is the following
scenario: If a .res file is passed to lib.exe, then lib.exe calls
cvtres.exe on the .res file before putting it in the output .lib.
(llvm-lib currently doesn't do this.)
link.exe's /wholearchive seems to only add obj files referenced from the
static library index, but lld-link current really adds all files in the
archive. So if lld-link /wholearchive is used with .lib files produced
by lib.exe and .res files were among the files handed to lib.exe, we
previously silently produced invalid output, but now we error out.
link.exe's /wholearchive semantics on the other hand mean that it
wouldn't load the resource object files from the .lib file at all.
Since this scenario is probably still an unlikely corner case,
the difference in behavior here seems fine -- and lld-link might have to
change to use link.exe's /wholearchive semantics in the future anyways.
Vaguely related to PR42180.
Differential Revision: https://reviews.llvm.org/D63109
llvm-svn: 363078
2019-06-11 23:22:28 +08:00
|
|
|
|
|
|
|
// Whether this file was compiled with /hotpatch.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool hotPatchable = false;
|
2019-02-23 09:46:18 +08:00
|
|
|
|
lld-link: Reject more than one resource .obj file
Users are exepcted to pass all .res files to the linker, which then
merges all the resource in all .res files into a tree structure and then
converts the final tree structure to a .obj file with .rsrc$01 and
.rsrc$02 sections and then links that.
If the user instead passes several .obj files containing such resources,
the correct thing to do would be to have custom code to merge the trees
in the resource sections instead of doing normal section merging -- but
link.exe rejects if multiple resource obj files are passed in with
LNK4078, so let lld-link do that too instead of silently writing broken
.rsrc sections in that case.
The only real way to run into this is if users manually convert .res
files to .obj files by running cvtres and then handing the resulting
.obj files to lld-link instead, which in practice likely never happens.
(lld-link is slightly stricter than link.exe now: If link.exe is passed
one .obj file created by cvtres, and a .res file, for some reason it
just emits a warning instead of an error and outputs strange looking
data. lld-link now errors out on mixed input like this.)
One way users could accidentally run into this is the following
scenario: If a .res file is passed to lib.exe, then lib.exe calls
cvtres.exe on the .res file before putting it in the output .lib.
(llvm-lib currently doesn't do this.)
link.exe's /wholearchive seems to only add obj files referenced from the
static library index, but lld-link current really adds all files in the
archive. So if lld-link /wholearchive is used with .lib files produced
by lib.exe and .res files were among the files handed to lib.exe, we
previously silently produced invalid output, but now we error out.
link.exe's /wholearchive semantics on the other hand mean that it
wouldn't load the resource object files from the .lib file at all.
Since this scenario is probably still an unlikely corner case,
the difference in behavior here seems fine -- and lld-link might have to
change to use link.exe's /wholearchive semantics in the future anyways.
Vaguely related to PR42180.
Differential Revision: https://reviews.llvm.org/D63109
llvm-svn: 363078
2019-06-11 23:22:28 +08:00
|
|
|
// Whether the object was already merged into the final PDB.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool mergedIntoPDB = false;
|
2019-03-23 06:07:27 +08:00
|
|
|
|
[LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.
Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.
The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.
Differential Revision: https://reviews.llvm.org/D59053
llvm-svn: 357383
2019-04-01 21:36:59 +08:00
|
|
|
// If the OBJ has a .debug$T stream, this tells how it will be handled.
|
2019-07-11 13:40:30 +08:00
|
|
|
TpiSource *debugTypesObj = nullptr;
|
[LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.
Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.
The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.
Differential Revision: https://reviews.llvm.org/D59053
llvm-svn: 357383
2019-04-01 21:36:59 +08:00
|
|
|
|
|
|
|
// The .debug$T stream if there's one.
|
2019-07-11 13:40:30 +08:00
|
|
|
llvm::Optional<llvm::codeview::CVTypeArray> debugTypes;
|
[LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.
Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.
The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.
Differential Revision: https://reviews.llvm.org/D59053
llvm-svn: 357383
2019-04-01 21:36:59 +08:00
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
private:
|
2019-07-11 13:40:30 +08:00
|
|
|
const coff_section* getSection(uint32_t i);
|
|
|
|
const coff_section *getSection(COFFSymbolRef sym) {
|
|
|
|
return getSection(sym.getSectionNumber());
|
2019-02-14 11:16:44 +08:00
|
|
|
}
|
2019-01-30 10:17:27 +08:00
|
|
|
|
2015-08-06 22:58:50 +08:00
|
|
|
void initializeChunks();
|
|
|
|
void initializeSymbols();
|
2019-02-23 09:46:18 +08:00
|
|
|
void initializeFlags();
|
[LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.
Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.
The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.
Differential Revision: https://reviews.llvm.org/D59053
llvm-svn: 357383
2019-04-01 21:36:59 +08:00
|
|
|
void initializeDependencies();
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2017-11-28 09:30:07 +08:00
|
|
|
SectionChunk *
|
2019-07-11 13:40:30 +08:00
|
|
|
readSection(uint32_t sectionNumber,
|
|
|
|
const llvm::object::coff_aux_section_definition *def,
|
|
|
|
StringRef leaderName);
|
2017-11-28 09:30:07 +08:00
|
|
|
|
|
|
|
void readAssociativeDefinition(
|
2019-07-11 13:40:30 +08:00
|
|
|
COFFSymbolRef coffSym,
|
|
|
|
const llvm::object::coff_aux_section_definition *def);
|
2017-11-28 09:30:07 +08:00
|
|
|
|
2018-08-07 05:26:09 +08:00
|
|
|
void readAssociativeDefinition(
|
2019-07-11 13:40:30 +08:00
|
|
|
COFFSymbolRef coffSym,
|
|
|
|
const llvm::object::coff_aux_section_definition *def,
|
|
|
|
uint32_t parentSection);
|
2018-08-07 05:26:09 +08:00
|
|
|
|
|
|
|
void recordPrevailingSymbolForMingw(
|
2019-07-11 13:40:30 +08:00
|
|
|
COFFSymbolRef coffSym,
|
|
|
|
llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
|
2018-08-07 05:26:09 +08:00
|
|
|
|
|
|
|
void maybeAssociateSEHForMingw(
|
2019-07-11 13:40:30 +08:00
|
|
|
COFFSymbolRef sym, const llvm::object::coff_aux_section_definition *def,
|
|
|
|
const llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
|
2018-08-07 05:26:09 +08:00
|
|
|
|
2019-02-14 11:16:44 +08:00
|
|
|
// Given a new symbol Sym with comdat selection Selection, if the new
|
|
|
|
// symbol is not (yet) Prevailing and the existing comdat leader set to
|
|
|
|
// Leader, emits a diagnostic if the new symbol and its selection doesn't
|
|
|
|
// match the existing symbol and its selection. If either old or new
|
|
|
|
// symbol have selection IMAGE_COMDAT_SELECT_LARGEST, Sym might replace
|
|
|
|
// the existing leader. In that case, Prevailing is set to true.
|
2019-07-11 13:40:30 +08:00
|
|
|
void handleComdatSelection(COFFSymbolRef sym,
|
|
|
|
llvm::COFF::COMDATType &selection,
|
|
|
|
bool &prevailing, DefinedRegular *leader);
|
2019-02-14 11:16:44 +08:00
|
|
|
|
2017-11-28 09:30:07 +08:00
|
|
|
llvm::Optional<Symbol *>
|
2019-07-11 13:40:30 +08:00
|
|
|
createDefined(COFFSymbolRef sym,
|
2017-11-28 09:30:07 +08:00
|
|
|
std::vector<const llvm::object::coff_aux_section_definition *>
|
2019-07-11 13:40:30 +08:00
|
|
|
&comdatDefs,
|
|
|
|
bool &prevailingComdat);
|
|
|
|
Symbol *createRegular(COFFSymbolRef sym);
|
|
|
|
Symbol *createUndefined(COFFSymbolRef sym);
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::unique_ptr<COFFObjectFile> coffObj;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
|
|
|
// List of all chunks defined by this file. This includes both section
|
|
|
|
// chunks and non-section chunks for common symbols.
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<Chunk *> chunks;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2016-11-22 01:22:35 +08:00
|
|
|
// CodeView debug info sections.
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<SectionChunk *> debugChunks;
|
2016-11-22 01:22:35 +08:00
|
|
|
|
2018-02-06 09:58:26 +08:00
|
|
|
// Chunks containing symbol table indices of exception handlers. Only used for
|
|
|
|
// 32-bit x86.
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<SectionChunk *> sXDataChunks;
|
2018-02-06 09:58:26 +08:00
|
|
|
|
2018-02-14 04:32:53 +08:00
|
|
|
// Chunks containing symbol table indices of address taken symbols and longjmp
|
|
|
|
// targets. These are not linked into the final binary when /guard:cf is set.
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<SectionChunk *> guardFidChunks;
|
|
|
|
std::vector<SectionChunk *> guardLJmpChunks;
|
2018-02-06 09:58:26 +08:00
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
// This vector contains the same chunks as Chunks, but they are
|
|
|
|
// indexed such that you can get a SectionChunk by section index.
|
|
|
|
// Nonexistent section indices are filled with null pointers.
|
|
|
|
// (Because section number is 1-based, the first slot is always a
|
|
|
|
// null pointer.)
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<SectionChunk *> sparseChunks;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2017-11-21 02:52:53 +08:00
|
|
|
// This vector contains a list of all symbols defined or referenced by this
|
|
|
|
// file. They are indexed such that you can get a Symbol by symbol
|
2015-05-29 03:09:30 +08:00
|
|
|
// index. Nonexistent indices (which are occupied by auxiliary
|
|
|
|
// symbols in the real symbol table) are filled with null pointers.
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<Symbol *> symbols;
|
2015-05-29 03:09:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// This type represents import library members that contain DLL names
|
|
|
|
// and symbols exported from the DLLs. See Microsoft PE/COFF spec. 7
|
|
|
|
// for details about the format.
|
|
|
|
class ImportFile : public InputFile {
|
|
|
|
public:
|
2019-07-11 13:40:30 +08:00
|
|
|
explicit ImportFile(MemoryBufferRef m) : InputFile(ImportKind, m) {}
|
2017-05-25 06:30:06 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
static bool classof(const InputFile *f) { return f->kind() == ImportKind; }
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
static std::vector<ImportFile *> instances;
|
2017-07-27 08:45:26 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
Symbol *impSym = nullptr;
|
|
|
|
Symbol *thunkSym = nullptr;
|
|
|
|
std::string dllName;
|
2015-08-17 15:27:45 +08:00
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
private:
|
2015-08-06 22:58:50 +08:00
|
|
|
void parse() override;
|
2015-05-29 03:09:30 +08:00
|
|
|
|
2016-12-10 05:55:24 +08:00
|
|
|
public:
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef externalName;
|
|
|
|
const coff_import_header *hdr;
|
|
|
|
Chunk *location = nullptr;
|
2017-05-25 06:30:06 +08:00
|
|
|
|
|
|
|
// We want to eliminate dllimported symbols if no one actually refers them.
|
2018-05-11 03:01:28 +08:00
|
|
|
// These "Live" bits are used to keep track of which import library members
|
2017-05-25 06:30:06 +08:00
|
|
|
// are actually in use.
|
|
|
|
//
|
|
|
|
// If the Live bit is turned off by MarkLive, Writer will ignore dllimported
|
2018-05-11 03:01:28 +08:00
|
|
|
// symbols provided by this import library member. We also track whether the
|
|
|
|
// imported symbol is used separately from whether the thunk is used in order
|
|
|
|
// to avoid creating unnecessary thunks.
|
2019-07-11 13:40:30 +08:00
|
|
|
bool live = !config->doGC;
|
|
|
|
bool thunkLive = !config->doGC;
|
2015-05-29 03:09:30 +08:00
|
|
|
};
|
|
|
|
|
2015-06-02 04:10:10 +08:00
|
|
|
// Used for LTO.
|
|
|
|
class BitcodeFile : public InputFile {
|
|
|
|
public:
|
2019-07-11 13:40:30 +08:00
|
|
|
BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
|
|
|
|
uint64_t offsetInArchive);
|
|
|
|
static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
|
|
|
|
ArrayRef<Symbol *> getSymbols() { return symbols; }
|
2015-07-10 03:54:13 +08:00
|
|
|
MachineTypes getMachineType() override;
|
2019-07-11 13:40:30 +08:00
|
|
|
static std::vector<BitcodeFile *> instances;
|
|
|
|
std::unique_ptr<llvm::lto::InputFile> obj;
|
2016-04-15 05:41:44 +08:00
|
|
|
|
2015-06-02 04:10:10 +08:00
|
|
|
private:
|
2015-08-06 22:58:50 +08:00
|
|
|
void parse() override;
|
2015-06-02 04:10:10 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::vector<Symbol *> symbols;
|
2015-06-02 04:10:10 +08:00
|
|
|
};
|
2019-07-12 02:48:58 +08:00
|
|
|
|
|
|
|
std::string replaceThinLTOSuffix(StringRef path);
|
2015-05-29 03:09:30 +08:00
|
|
|
} // namespace coff
|
2017-01-06 18:04:08 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::string toString(const coff::InputFile *file);
|
2015-05-29 03:09:30 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|