summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-10-29 00:33:34 +0000
committerRui Ueyama <ruiu@google.com>2013-10-29 00:33:34 +0000
commit90173df289f5c2c6eea1b118b941425f9ad7e54c (patch)
treed76ce0dbd7f5c63c9d2c192f0b385c71d92af4f8
parentdc4db5a6ebcdee39e0816e9ac7ae7ac480ab14fc (diff)
downloadbcm5719-llvm-90173df289f5c2c6eea1b118b941425f9ad7e54c.tar.gz
bcm5719-llvm-90173df289f5c2c6eea1b118b941425f9ad7e54c.zip
[PECOFF] Fix __ImageBase symbol.
__ImageBase is an absolute symbol whose address is the same as the image base address. What we did before this patch was to create __ImageBase symbol as a symbol whose *contents* (not location) is the image base address, which is clearly wrong. llvm-svn: 193565
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h48
-rw-r--r--lld/test/pecoff/imagebase.test9
2 files changed, 17 insertions, 40 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index 4df18ff1088..8678e42ff55 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -27,50 +27,26 @@ namespace coff {
namespace {
-// The symbol __ImageBase is a linker generated symbol. No standard library
-// files define it, but the linker is expected to prepare it as if it was read
-// from a file. The content of the atom is a 4-byte integer equal to the image
-// base address. Note that because the name is prefixed by an underscore on x86
-// Win32, the actual symbol name will be ___ImageBase (three underscores).
-class ImageBaseAtom : public COFFLinkerInternalAtom {
-public:
- ImageBaseAtom(const PECOFFLinkingContext &context, const File &file,
- uint32_t imageBase)
- : COFFLinkerInternalAtom(file, assembleRawContent(imageBase)),
- _name(context.decorateSymbol("__ImageBase")) {}
-
- virtual StringRef name() const { return _name; }
- virtual uint64_t ordinal() const { return 0; }
- virtual ContentType contentType() const { return typeData; }
- virtual ContentPermissions permissions() const { return permRW_; }
- virtual DeadStripKind deadStrip() const { return deadStripAlways; }
-
-private:
- std::vector<uint8_t> assembleRawContent(uint32_t imageBase) {
- std::vector<uint8_t> data = std::vector<uint8_t>(4);
- *(reinterpret_cast<uint32_t *>(&data[0])) = imageBase;
- return data;
- }
-
- StringRef _name;
-};
-
-// The file to wrap ImageBaseAtom. This is the only member file of
-// LinkerGeneratedSymbolFile.
+// 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.
+//
+// This is the only member file of LinkerGeneratedSymbolFile.
class MemberFile : public SimpleFile {
public:
- MemberFile(const PECOFFLinkingContext &context)
- : SimpleFile(context, "Member of the Linker Internal File"),
- _atom(context, *this, context.getBaseAddress()) {
- addAtom(_atom);
+ MemberFile(const PECOFFLinkingContext &ctx)
+ : SimpleFile(ctx, "Member of the Linker Internal File"),
+ _imageBaseAtom(*this, ctx.decorateSymbol("__ImageBase"),
+ Atom::scopeGlobal, ctx.getBaseAddress()) {
+ addAtom(_imageBaseAtom);
};
bool contains(StringRef name) const {
- return _atom.name() == name;
+ return _imageBaseAtom.name() == name;
}
private:
- ImageBaseAtom _atom;
+ COFFAbsoluteAtom _imageBaseAtom;
};
} // anonymous namespace
diff --git a/lld/test/pecoff/imagebase.test b/lld/test/pecoff/imagebase.test
index 9a89eb167a4..f4c53fe9009 100644
--- a/lld/test/pecoff/imagebase.test
+++ b/lld/test/pecoff/imagebase.test
@@ -2,11 +2,12 @@
#
# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_start /opt:noref \
# RUN: -- %t.obj \
-# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK1 %s
+# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=DEFAULT %s
#
# RUN: lld -flavor link /out:%t1 /subsystem:console /entry:_start /base:65536 \
# RUN: /opt:noref -- %t.obj \
-# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=CHECK2 %s
+# RUN: && llvm-objdump -disassemble %t1 | FileCheck -check-prefix=BASE %s
-CHECK1: a1 00 20 40 00 movl 4202496, %eax
-CHECK2: a1 00 20 01 00 movl 73728, %eax
+DEFAULT: a1 00 00 40 00 movl 4194304, %eax
+
+BASE: a1 00 00 01 00 movl 65536, %eax
OpenPOWER on IntegriCloud