[lld] r190772 - [PECOFF] Use a dummy file as an "input file" for Idata atoms.

Shankar Easwaran shankare at codeaurora.org
Sun Sep 15 19:24:41 PDT 2013


testcase ?

On 9/15/2013 5:33 PM, Rui Ueyama wrote:
> Author: ruiu
> Date: Sun Sep 15 17:33:15 2013
> New Revision: 190772
>
> URL: http://llvm.org/viewvc/llvm-project?rev=190772&view=rev
> Log:
> [PECOFF] Use a dummy file as an "input file" for Idata atoms.
>
> Modified:
>      lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
>      lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=190772&r1=190771&r2=190772&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
> +++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Sun Sep 15 17:33:15 2013
> @@ -23,8 +23,9 @@
>   
>   #include "lld/Core/File.h"
>   #include "lld/Core/Pass.h"
> -#include "llvm/Support/Debug.h"
> +#include "lld/ReaderWriter/Simple.h"
>   #include "llvm/Support/COFF.h"
> +#include "llvm/Support/Debug.h"
>   #include "llvm/Support/Endian.h"
>   
>   #include <algorithm>
> @@ -58,9 +59,10 @@ void addDir32NBReloc(COFFBaseDefinedAtom
>   
>   // A state object of this pass.
>   struct Context {
> -  explicit Context(MutableFile &f) : file(f) {}
> +  explicit Context(MutableFile &f, File &g) : file(f), dummyFile(g) {}
>   
>     MutableFile &file;
> +  File &dummyFile;
>   
>     // The object to accumulate idata atoms. Idata atoms need to be grouped by
>     // type and be continuous in the output file. To force such layout, we
> @@ -82,9 +84,9 @@ public:
>     virtual ContentPermissions permissions() const { return permR__; }
>   
>   protected:
> -  IdataAtom(MutableFile &file, vector<uint8_t> data)
> -      : COFFLinkerInternalAtom(file, data) {
> -    file.addAtom(*this);
> +  IdataAtom(Context &context, vector<uint8_t> data)
> +      : COFFLinkerInternalAtom(context.dummyFile, data) {
> +    context.file.addAtom(*this);
>     }
>   };
>   
> @@ -93,7 +95,7 @@ protected:
>   class DLLNameAtom : public IdataAtom {
>   public:
>     DLLNameAtom(Context &context, StringRef name)
> -      : IdataAtom(context.file, stringRefToVector(name)) {
> +      : IdataAtom(context, stringRefToVector(name)) {
>       context.dllNameAtoms.push_back(this);
>     }
>   
> @@ -117,7 +119,7 @@ private:
>   class HintNameAtom : public IdataAtom {
>   public:
>     HintNameAtom(Context &context, uint16_t hint, StringRef importName)
> -      : IdataAtom(context.file, assembleRawContent(hint, importName)),
> +      : IdataAtom(context, assembleRawContent(hint, importName)),
>           _importName(importName) {
>       context.hintNameAtoms.push_back(this);
>     }
> @@ -144,7 +146,7 @@ private:
>   class ImportTableEntryAtom : public IdataAtom {
>   public:
>     explicit ImportTableEntryAtom(Context &context, uint32_t contents)
> -      : IdataAtom(context.file, assembleRawContent(contents)) {}
> +      : IdataAtom(context, assembleRawContent(contents)) {}
>   
>   private:
>     vector<uint8_t> assembleRawContent(uint32_t contents) {
> @@ -162,7 +164,7 @@ class ImportDirectoryAtom : public Idata
>   public:
>     ImportDirectoryAtom(Context &context, StringRef loadName,
>                         const vector<COFFSharedLibraryAtom *> &sharedAtoms)
> -      : IdataAtom(context.file, vector<uint8_t>(20, 0)) {
> +      : IdataAtom(context, vector<uint8_t>(20, 0)) {
>       addRelocations(context, loadName, sharedAtoms);
>       context.importDirectories.push_back(this);
>     }
> @@ -229,20 +231,30 @@ private:
>   class NullImportDirectoryAtom : public IdataAtom {
>   public:
>     explicit NullImportDirectoryAtom(Context &context)
> -      : IdataAtom(context.file, vector<uint8_t>(20, 0)) {
> +      : IdataAtom(context, vector<uint8_t>(20, 0)) {
>       context.importDirectories.push_back(this);
>     }
>   };
>   
>   } // anonymous namespace
>   
> +// An instance of this class represents "input file" for atoms created in this
> +// pass. Only one instance of this class is created as a field of IdataPass.
> +class IdataPassFile : public SimpleFile {
> +public:
> +  IdataPassFile(const LinkingContext &ctx)
> +      : SimpleFile(ctx, "<idata-pass-file>") {}
> +};
> +
>   class IdataPass : public lld::Pass {
>   public:
> +  IdataPass(const LinkingContext &ctx) : _dummyFile(ctx) {}
> +
>     virtual void perform(MutableFile &file) {
>       if (file.sharedLibrary().size() == 0)
>         return;
>   
> -    Context context(file);
> +    Context context(file, _dummyFile);
>       map<StringRef, vector<COFFSharedLibraryAtom *> > sharedAtoms =
>           groupByLoadName(file);
>       for (auto i : sharedAtoms) {
> @@ -291,14 +303,14 @@ private:
>     /// will be set by the writer.
>     void createDataDirectoryAtoms(Context &context) {
>       auto *dir = new (_alloc) coff::COFFDataDirectoryAtom(
> -        context.file, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE,
> +        context.dummyFile, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE,
>           context.importDirectories.size() *
>               context.importDirectories[0]->size());
>       addDir32NBReloc(dir, context.importDirectories[0]);
>       context.file.addAtom(*dir);
>   
>       auto *iat = new (_alloc) coff::COFFDataDirectoryAtom(
> -        context.file, llvm::COFF::DataDirectoryIndex::IAT,
> +        context.dummyFile, llvm::COFF::DataDirectoryIndex::IAT,
>           context.importAddressTables.size() *
>               context.importAddressTables[0]->size());
>       addDir32NBReloc(iat, context.importAddressTables[0]);
> @@ -320,6 +332,11 @@ private:
>       }
>     }
>   
> +  // A dummy file with which all the atoms created in the pass will be
> +  // associated. Atoms need to be associated to an input file even if it's not
> +  // read from a file, so we use this object.
> +  IdataPassFile _dummyFile;
> +
>     llvm::BumpPtrAllocator _alloc;
>   };
>   
>
> Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=190772&r1=190771&r2=190772&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Sun Sep 15 17:33:15 2013
> @@ -122,7 +122,7 @@ PECOFFLinkingContext::stringFromRelocKin
>   
>   void PECOFFLinkingContext::addPasses(PassManager &pm) const {
>     pm.add(std::unique_ptr<Pass>(new pecoff::GroupedSectionsPass()));
> -  pm.add(std::unique_ptr<Pass>(new pecoff::IdataPass()));
> +  pm.add(std::unique_ptr<Pass>(new pecoff::IdataPass(*this)));
>     pm.add(std::unique_ptr<Pass>(new LayoutPass()));
>   }
>   } // end namespace lld
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation




More information about the llvm-commits mailing list