[PECOFF] Create __ImageBase symbol.
__ImageBase is a symbol having 4 byte integer equal to the image base address
of the resultant executable. The linker is expected to create the symbol as if
it were read from a file.
In order to emit the symbol contents only when the symbol is actually
referenced, we created a pseudo library file to wrap the linker generated
symbol. The library file member is emitted to the output only when the member
is actually referenced, which is suitable for our purpose.
llvm-svn: 188052
diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
index ad0d563..4dbb5d7 100644
--- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
@@ -10,6 +10,7 @@
#include "Atoms.h"
#include "GroupedSectionsPass.h"
#include "IdataPass.h"
+#include "LinkerGeneratedSymbolFile.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Allocator.h"
@@ -30,24 +31,6 @@
llvm::sys::path::remove_filename(smallStr);
return !smallStr.str().empty();
}
-
-/// An instance of UndefinedSymbolFile has a list of undefined symbols
-/// specified by "/include" command line option. This will be added to the
-/// input file list to force the core linker to try to resolve the undefined
-/// symbols.
-class UndefinedSymbolFile : public SimpleFile {
-public:
- UndefinedSymbolFile(const LinkingContext &ti)
- : SimpleFile(ti, "Linker Internal File") {
- for (StringRef symbol : ti.initialUndefinedSymbols()) {
- UndefinedAtom *atom = new (_alloc) coff::COFFUndefinedAtom(*this, symbol);
- addAtom(*atom);
- }
- }
-
-private:
- llvm::BumpPtrAllocator _alloc;
-};
} // anonymous namespace
error_code PECOFFLinkingContext::parseFile(
@@ -83,8 +66,11 @@
void PECOFFLinkingContext::addImplicitFiles(InputFiles &files) const {
// Add a pseudo file for "/include" linker option.
- auto *file = new (_alloc) UndefinedSymbolFile(*this);
- files.prependFile(*file);
+ auto *undefFile = new (_alloc) coff::UndefinedSymbolFile(*this);
+ files.prependFile(*undefFile);
+
+ auto *linkerFile = new (_alloc) coff::LinkerGeneratedSymbolFile(*this);
+ files.appendFile(*linkerFile);
}
/// Append the given file to the input file list. The file must be an object