[llvm-commits] [lld] r172297 - in /lld/trunk: include/lld/Core/File.h include/lld/Core/Pass.h include/lld/Core/Resolver.h lib/Passes/GOTPass.cpp lib/Passes/StubsPass.cpp lib/ReaderWriter/ELF/ReaderELF.cpp lib/ReaderWriter/MachO/StubsPass.hpp lib/ReaderWriter/Native/ReaderNative.cpp lib/ReaderWriter/PECOFF/ReaderCOFF.cpp lib/ReaderWriter/ReaderArchive.cpp lib/ReaderWriter/YAML/ReaderWriterYAML.cpp tools/lld-core/TestingHelpers.hpp tools/lld-core/lld-core.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Fri Jan 11 18:45:54 PST 2013
Author: mspencer
Date: Fri Jan 11 20:45:54 2013
New Revision: 172297
URL: http://llvm.org/viewvc/llvm-project?rev=172297&view=rev
Log:
Factor File::addAtom out to MutableFile::addAtom.
This removes a bunch of llvm_unreachables and makes a File's mutability part of the type system.
Modified:
lld/trunk/include/lld/Core/File.h
lld/trunk/include/lld/Core/Pass.h
lld/trunk/include/lld/Core/Resolver.h
lld/trunk/lib/Passes/GOTPass.cpp
lld/trunk/lib/Passes/StubsPass.cpp
lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
lld/trunk/tools/lld-core/TestingHelpers.hpp
lld/trunk/tools/lld-core/lld-core.cpp
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Fri Jan 11 20:45:54 2013
@@ -76,15 +76,6 @@
/// \brief For use interating over AbsoluteAtoms in this File.
typedef atom_iterator<AbsoluteAtom> absolute_iterator;
- /// Note: this method is not const. All File objects instantiated by reading
- /// an object file from disk are "const File*" objects and cannot be
- /// modified. This method can only be used with temporay File objects
- /// such as is seen by each Pass object when it runs.
- /// This method is *not* safe to call while iterating through this File's
- /// Atoms. A Pass should queue up any Atoms it want to add and then
- /// call this method when no longer iterating over the File's Atoms.
- virtual void addAtom(const Atom&) = 0;
-
/// \brief Different object file readers may instantiate and manage atoms with
/// different data structures. This class is a collection abstraction.
/// Each concrete File instance must implement these atom_collection
@@ -204,6 +195,18 @@
StringRef _path;
};
+
+/// \brief A mutable File.
+class MutableFile : public File {
+public:
+ /// \brief Add an atom to the file. Invalidates iterators for all returned
+ /// containters.
+ virtual void addAtom(const Atom&) = 0;
+
+protected:
+ /// \brief only subclasses of MutableFile can be instantiated
+ MutableFile(StringRef p) : File(p) {}
+};
} // end namespace lld
#endif
Modified: lld/trunk/include/lld/Core/Pass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Pass.h?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Pass.h (original)
+++ lld/trunk/include/lld/Core/Pass.h Fri Jan 11 20:45:54 2013
@@ -17,6 +17,7 @@
namespace lld {
class DefinedAtom;
+class MutableFile;
/// Once the core linking is done (which resolves references, coalesces atoms
/// and produces a complete Atom graph), the linker runs a series of passes
@@ -33,7 +34,7 @@
virtual ~Pass() { }
/// Do the actual work of the Pass.
- virtual void perform(File &mergedFile) = 0;
+ virtual void perform(MutableFile &mergedFile) = 0;
protected:
// Only subclassess can be instantiated.
@@ -50,7 +51,7 @@
/// Scans all Atoms looking for call-site uses of SharedLibraryAtoms
/// and transfroms the call-site to call a stub instead using the
/// helper methods below.
- virtual void perform(File &mergedFile);
+ virtual void perform(MutableFile &mergedFile);
/// If true, the pass should use stubs for references
/// to shared library symbols. If false, the pass
@@ -71,7 +72,7 @@
/// After the default implementation of perform() is done calling getStub(),
/// it will call this method to add all the stub (and support) atoms to the
/// master file object.
- virtual void addStubAtoms(File &masterFile) = 0;
+ virtual void addStubAtoms(MutableFile &masterFile) = 0;
};
/// Pass for adding GOT entries for pointers to functions/data
@@ -84,7 +85,7 @@
/// Scans all Atoms looking for pointer to SharedLibraryAtoms
/// and transfroms them to a pointer to a GOT entry using the
/// helper methods below.
- virtual void perform(File &mergedFile);
+ virtual void perform(MutableFile &mergedFile);
/// If true, the pass will use GOT entries for references
/// to shared library symbols. If false, the pass
Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Fri Jan 11 20:45:54 2013
@@ -135,7 +135,7 @@
/// @brief do work of merging and resolving and return list
void resolve();
- File& resultFile() {
+ MutableFile& resultFile() {
return _result;
}
@@ -155,9 +155,9 @@
void addAtoms(const std::vector<const DefinedAtom *>&);
- class MergedFile : public File {
+ class MergedFile : public MutableFile {
public:
- MergedFile() : File("<linker-internal>") { }
+ MergedFile() : MutableFile("<linker-internal>") { }
virtual const atom_collection<DefinedAtom>& defined() const {
return _definedAtoms;
Modified: lld/trunk/lib/Passes/GOTPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/GOTPass.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/Passes/GOTPass.cpp (original)
+++ lld/trunk/lib/Passes/GOTPass.cpp Fri Jan 11 20:45:54 2013
@@ -40,7 +40,7 @@
#include "llvm/ADT/DenseMap.h"
namespace lld {
-void GOTPass::perform(File& mergedFile) {
+void GOTPass::perform(MutableFile &mergedFile) {
// Use map so all pointers to same symbol use same GOT entry.
llvm::DenseMap<const Atom*, const DefinedAtom*> targetToGOT;
Modified: lld/trunk/lib/Passes/StubsPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/StubsPass.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/Passes/StubsPass.cpp (original)
+++ lld/trunk/lib/Passes/StubsPass.cpp Fri Jan 11 20:45:54 2013
@@ -23,7 +23,7 @@
namespace lld {
-void StubsPass::perform(File& mergedFile) {
+void StubsPass::perform(MutableFile &mergedFile) {
// Skip this pass if output format uses text relocations instead of stubs.
if ( ! this->noTextRelocs() )
return;
@@ -63,7 +63,4 @@
// Add all created stubs and support Atoms.
this->addStubAtoms(mergedFile);
}
-
-
-
}
Modified: lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp Fri Jan 11 20:45:54 2013
@@ -209,6 +209,9 @@
// Get the symbol's content:
llvm::ArrayRef<uint8_t> symbolData;
uint64_t contentSize;
+
+ // If the next symbol is at the same location
+
if (si + 1 == se) {
// if this is the last symbol, take up the remaining data.
contentSize = (isCommon) ? 0
@@ -272,10 +275,6 @@
}
}
- virtual void addAtom(const Atom&) {
- llvm_unreachable("cannot add atoms to native .o files");
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
}
Modified: lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp Fri Jan 11 20:45:54 2013
@@ -119,7 +119,7 @@
}
- virtual void addStubAtoms(File &mergedFile) {
+ virtual void addStubAtoms(MutableFile &mergedFile) {
// Exit early if no stubs needed.
if ( _targetToStub.size() == 0 )
return;
Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Fri Jan 11 20:45:54 2013
@@ -371,10 +371,6 @@
return _absoluteAtoms;
}
- virtual void addAtom(const Atom&) {
- assert(0 && "cannot add atoms to native .o files");
- }
-
private:
friend class NativeDefinedAtomV1;
friend class NativeUndefinedAtomV1;
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Jan 11 20:45:54 2013
@@ -330,10 +330,6 @@
}
}
- virtual void addAtom(const Atom&) {
- llvm_unreachable("cannot add atoms to native .obj files");
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return DefinedAtoms;
}
Modified: lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderArchive.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ReaderArchive.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ReaderArchive.cpp Fri Jan 11 20:45:54 2013
@@ -56,10 +56,6 @@
return result[0].release();
}
- virtual void addAtom(const Atom&) {
- llvm_unreachable("cannot add atoms to archive files");
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
}
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Jan 11 20:45:54 2013
@@ -614,10 +614,7 @@
const lld::File *denormalize(IO &io) {
return this;
}
-
- virtual void addAtom(const lld::Atom&) {
- llvm_unreachable("cannot add atoms to yaml .o files");
- }
+
virtual const atom_collection<lld::DefinedAtom> &defined() const {
return _noDefinedAtoms;
}
@@ -672,11 +669,7 @@
_absoluteAtoms.push_back(a);
}
const lld::File *denormalize(IO &io);
-
-
- virtual void addAtom(const lld::Atom&) {
- llvm_unreachable("cannot add atoms to yaml .o files");
- }
+
virtual const atom_collection<lld::DefinedAtom> &defined() const {
return _definedAtoms;
}
Modified: lld/trunk/tools/lld-core/TestingHelpers.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/TestingHelpers.hpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/TestingHelpers.hpp (original)
+++ lld/trunk/tools/lld-core/TestingHelpers.hpp Fri Jan 11 20:45:54 2013
@@ -213,10 +213,9 @@
uint32_t _ordinal;
};
-class TestingPassFile : public File {
+class TestingPassFile : public MutableFile {
public:
- TestingPassFile() : File("Testing pass") {
- }
+ TestingPassFile() : MutableFile("Testing pass") {}
virtual void addAtom(const Atom &atom) {
if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom))
@@ -285,7 +284,7 @@
return result;
}
- virtual void addStubAtoms(File &mergedFile) {
+ virtual void addStubAtoms(MutableFile &mergedFile) {
for (const DefinedAtom *stub : _file.defined() ) {
mergedFile.addAtom(*stub);
}
Modified: lld/trunk/tools/lld-core/lld-core.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/lld-core.cpp?rev=172297&r1=172296&r2=172297&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/lld-core.cpp (original)
+++ lld/trunk/tools/lld-core/lld-core.cpp Fri Jan 11 20:45:54 2013
@@ -263,7 +263,7 @@
// merge all atom graphs
Resolver resolver(options, inputFiles);
resolver.resolve();
- File &mergedMasterFile = resolver.resultFile();
+ MutableFile &mergedMasterFile = resolver.resultFile();
// run passes
if ( GOTPass *pass = writer->gotPass() ) {
More information about the llvm-commits
mailing list