[lld] r194127 - [PECOFF] Do not wrap the linker internal file with an archive file.

Rui Ueyama ruiu at google.com
Tue Nov 5 20:30:55 PST 2013


Author: ruiu
Date: Tue Nov  5 22:30:55 2013
New Revision: 194127

URL: http://llvm.org/viewvc/llvm-project?rev=194127&view=rev
Log:
[PECOFF] Do not wrap the linker internal file with an archive file.

We wrapped the linker internal file with a virtual archive file, so that the
linker internal file was linked only when it's actually used. This was to avoid
__ImageBase being included to the resulting executable. __ImageBase used to
occupy four bytes when emitted to executable.

And then it turned out that the implementation of __ImageBase was wrong -- it
shouldn't have been a regular atom but an absolute atom. Absolute atoms point
to some memory location, but they don't occupy disk space themselves. So it
wouldn't increase executable size (except the symbol table.) That means that
it's OK to link the linker internal file unconditionally.

So this patch does that, removing the wrapper archive file. Doing this
simplifies the code.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h

Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=194127&r1=194126&r2=194127&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Tue Nov  5 22:30:55 2013
@@ -8,87 +8,28 @@
 //===----------------------------------------------------------------------===//
 
 #include "Atoms.h"
-#include "GroupedSectionsPass.h"
-#include "IdataPass.h"
 
-#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Path.h"
-#include "lld/Core/ArchiveLibraryFile.h"
-#include "lld/Core/PassManager.h"
-#include "lld/Passes/LayoutPass.h"
 #include "lld/ReaderWriter/PECOFFLinkingContext.h"
-#include "lld/ReaderWriter/Reader.h"
 #include "lld/ReaderWriter/Simple.h"
-#include "lld/ReaderWriter/Writer.h"
 
 namespace lld {
 namespace coff {
 
-namespace {
-
 // 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 {
+class LinkerGeneratedSymbolFile : public SimpleFile {
 public:
-  MemberFile(const PECOFFLinkingContext &ctx)
+  LinkerGeneratedSymbolFile(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 _imageBaseAtom.name() == name;
-  }
-
 private:
   COFFAbsoluteAtom _imageBaseAtom;
 };
 
-} // anonymous namespace
-
-// A pseudo library file to wrap MemberFile, which in turn wraps ImageBaseAtom.
-// The file the core linker handle is this.
-//
-// The reason why we don't pass MemberFile to the core linker is because, if we
-// did so, ImageBaseAtom would always be emit to the resultant executable. By
-// wrapping the file by a library file, we made it to emit ImageBaseAtom only
-// when the atom is really referenced.
-class LinkerGeneratedSymbolFile : public ArchiveLibraryFile {
-public:
-  LinkerGeneratedSymbolFile(const PECOFFLinkingContext &context)
-      : ArchiveLibraryFile(context, "Linker Internal File"),
-        _memberFile(context) {};
-
-  virtual const File *find(StringRef name, bool dataSymbolOnly) const {
-    if (_memberFile.contains(name))
-      return &_memberFile;
-    return nullptr;
-  }
-
-  virtual const atom_collection<DefinedAtom> &defined() const {
-    return _noDefinedAtoms;
-  }
-
-  virtual const atom_collection<UndefinedAtom> &undefined() const {
-    return _noUndefinedAtoms;
-  }
-
-  virtual const atom_collection<SharedLibraryAtom> &sharedLibrary() const {
-    return _noSharedLibraryAtoms;
-  }
-
-  virtual const atom_collection<AbsoluteAtom> &absolute() const {
-    return _noAbsoluteAtoms;
-  }
-
-private:
-  MemberFile _memberFile;
-};
-
 } // end namespace coff
 } // end namespace lld





More information about the llvm-commits mailing list