summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index 248aaabbef4..5b9464ba644 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -11,10 +11,25 @@
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
#include "lld/ReaderWriter/Simple.h"
+#include "llvm/Support/Allocator.h"
namespace lld {
namespace pecoff {
+/// The defined atom for dllexported symbols with __imp_ prefix.
+class ImpPointerAtom : public COFFLinkerInternalAtom {
+public:
+ ImpPointerAtom(const File &file, StringRef symbolName)
+ : COFFLinkerInternalAtom(file, /*oridnal*/ 0, std::vector<uint8_t>(4),
+ symbolName) {}
+
+ uint64_t ordinal() const override { return 0; }
+ Scope scope() const override { return scopeGlobal; }
+ ContentType contentType() const override { return typeData; }
+ Alignment alignment() const override { return Alignment(4); }
+ ContentPermissions permissions() const override { return permR__; }
+};
+
// A virtual file containing absolute symbol __ImageBase. __ImageBase (or
// ___ImageBase on x86) is a linker-generated symbol whose address is the same
// as the image base address.
@@ -25,10 +40,29 @@ public:
_imageBaseAtom(*this, ctx.decorateSymbol("__ImageBase"),
Atom::scopeGlobal, ctx.getBaseAddress()) {
addAtom(_imageBaseAtom);
+
+ // Create implciit symbols for exported symbols.
+ for (const PECOFFLinkingContext::ExportDesc exp : ctx.getDllExports()) {
+ UndefinedAtom *target = new (_alloc) SimpleUndefinedAtom(*this, exp.name);
+ COFFLinkerInternalAtom *imp = createImpPointerAtom(ctx, exp.name);
+ imp->addReference(std::unique_ptr<COFFReference>(
+ new COFFReference(target, 0, llvm::COFF::IMAGE_REL_I386_DIR32)));
+ addAtom(*target);
+ addAtom(*imp);
+ }
};
private:
+ COFFLinkerInternalAtom *createImpPointerAtom(const PECOFFLinkingContext &ctx,
+ StringRef name) {
+ std::string sym = "_imp_";
+ sym.append(name);
+ sym = ctx.decorateSymbol(sym);
+ return new (_alloc) ImpPointerAtom(*this, ctx.allocate(sym));
+ }
+
COFFAbsoluteAtom _imageBaseAtom;
+ llvm::BumpPtrAllocator _alloc;
};
} // end namespace pecoff
OpenPOWER on IntegriCloud