[lld] r197137 - [PECOFF] Replace DLLNameAtom with COFFStringAtom.
Rui Ueyama
ruiu at google.com
Thu Dec 12 00:53:46 PST 2013
Author: ruiu
Date: Thu Dec 12 02:53:46 2013
New Revision: 197137
URL: http://llvm.org/viewvc/llvm-project?rev=197137&view=rev
Log:
[PECOFF] Replace DLLNameAtom with COFFStringAtom.
DLLNameAtom is an atom whose content is a string. IdataAtom is not going to
be the only place we need such atom, so I want to generalize it.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h?rev=197137&r1=197136&r2=197137&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Thu Dec 12 02:53:46 2013
@@ -248,6 +248,29 @@ private:
std::vector<uint8_t> _data;
};
+class COFFStringAtom : public COFFLinkerInternalAtom {
+public:
+ COFFStringAtom(const File &file, uint64_t ordinal, StringRef sectionName,
+ StringRef contents)
+ : COFFLinkerInternalAtom(file, ordinal, stringRefToVector(contents)),
+ _sectionName(sectionName) {}
+
+ virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
+ virtual StringRef customSectionName() const { return _sectionName; }
+ virtual ContentType contentType() const { return typeData; }
+ virtual ContentPermissions permissions() const { return permR__; }
+
+private:
+ StringRef _sectionName;
+
+ std::vector<uint8_t> stringRefToVector(StringRef name) const {
+ std::vector<uint8_t> ret(name.size() + 1);
+ memcpy(&ret[0], name.data(), name.size());
+ ret[name.size()] = 0;
+ return ret;
+ }
+};
+
// A COFFSharedLibraryAtom represents a symbol for data in an import library. A
// reference to a COFFSharedLibraryAtom will be transformed to a real reference
// to an import address table entry in Idata pass.
Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp?rev=197137&r1=197136&r2=197137&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp Thu Dec 12 02:53:46 2013
@@ -24,13 +24,6 @@
namespace lld {
namespace pecoff {
-static std::vector<uint8_t> stringRefToVector(StringRef name) {
- std::vector<uint8_t> ret(name.size() + 1);
- memcpy(&ret[0], name.data(), name.size());
- ret[name.size()] = 0;
- return ret;
-}
-
static void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target,
size_t offsetInAtom = 0) {
atom->addReference(std::unique_ptr<COFFReference>(new COFFReference(
@@ -45,9 +38,6 @@ IdataAtom::IdataAtom(Context &context, s
context.file.addAtom(*this);
}
-DLLNameAtom::DLLNameAtom(Context &context, StringRef name)
- : IdataAtom(context, stringRefToVector(name)) {}
-
HintNameAtom::HintNameAtom(Context &context, uint16_t hint,
StringRef importName)
: IdataAtom(context, assembleRawContent(hint, importName)),
@@ -91,8 +81,11 @@ void ImportDirectoryAtom::addRelocations
offsetof(ImportDirectoryTableEntry, ImportLookupTableRVA));
addDir32NBReloc(this, importAddressTables[0],
offsetof(ImportDirectoryTableEntry, ImportAddressTableRVA));
- addDir32NBReloc(this, new (_alloc) DLLNameAtom(context, loadName),
- offsetof(ImportDirectoryTableEntry, NameRVA));
+ auto *atom = new (_alloc) coff::COFFStringAtom(
+ context.dummyFile, context.dummyFile.getNextOrdinal(), ".idata",
+ loadName);
+ context.file.addAtom(*atom);
+ addDir32NBReloc(this, atom, offsetof(ImportDirectoryTableEntry, NameRVA));
}
std::vector<ImportTableEntryAtom *> ImportDirectoryAtom::createImportTableAtoms(
Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=197137&r1=197136&r2=197137&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Thu Dec 12 02:53:46 2013
@@ -64,13 +64,6 @@ protected:
IdataAtom(Context &context, std::vector<uint8_t> data);
};
-/// A DLLNameAtom contains a name of a DLL and is referenced by the Name RVA
-/// field in the import directory table entry.
-class DLLNameAtom : public IdataAtom {
-public:
- DLLNameAtom(Context &context, StringRef name);
-};
-
/// A HintNameAtom represents a symbol that will be imported from a DLL at
/// runtime. It consists with an optional hint, which is a small integer, and a
/// symbol name.
More information about the llvm-commits
mailing list