summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/include/lld/Core/File.h21
-rw-r--r--lld/include/lld/Core/Pass.h9
-rw-r--r--lld/include/lld/Core/Resolver.h6
-rw-r--r--lld/lib/Passes/GOTPass.cpp2
-rw-r--r--lld/lib/Passes/StubsPass.cpp5
-rw-r--r--lld/lib/ReaderWriter/ELF/ReaderELF.cpp7
-rw-r--r--lld/lib/ReaderWriter/MachO/StubsPass.hpp2
-rw-r--r--lld/lib/ReaderWriter/Native/ReaderNative.cpp4
-rw-r--r--lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp4
-rw-r--r--lld/lib/ReaderWriter/ReaderArchive.cpp4
-rw-r--r--lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp11
-rw-r--r--lld/tools/lld-core/TestingHelpers.hpp7
-rw-r--r--lld/tools/lld-core/lld-core.cpp2
13 files changed, 32 insertions, 52 deletions
diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h
index 167161411bb..d403da00445 100644
--- a/lld/include/lld/Core/File.h
+++ b/lld/include/lld/Core/File.h
@@ -76,15 +76,6 @@ public:
/// \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 @@ protected:
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
diff --git a/lld/include/lld/Core/Pass.h b/lld/include/lld/Core/Pass.h
index 7d854d3098e..651a565bb19 100644
--- a/lld/include/lld/Core/Pass.h
+++ b/lld/include/lld/Core/Pass.h
@@ -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 @@ public:
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 @@ public:
/// 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 @@ public:
/// 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 @@ public:
/// 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
diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h
index 64437fbcf61..c0cca09580f 100644
--- a/lld/include/lld/Core/Resolver.h
+++ b/lld/include/lld/Core/Resolver.h
@@ -135,7 +135,7 @@ public:
/// @brief do work of merging and resolving and return list
void resolve();
- File& resultFile() {
+ MutableFile& resultFile() {
return _result;
}
@@ -155,9 +155,9 @@ private:
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;
diff --git a/lld/lib/Passes/GOTPass.cpp b/lld/lib/Passes/GOTPass.cpp
index 78b1f5064da..1a819eb5a62 100644
--- a/lld/lib/Passes/GOTPass.cpp
+++ b/lld/lib/Passes/GOTPass.cpp
@@ -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;
diff --git a/lld/lib/Passes/StubsPass.cpp b/lld/lib/Passes/StubsPass.cpp
index c468959d2cc..ef3870580cb 100644
--- a/lld/lib/Passes/StubsPass.cpp
+++ b/lld/lib/Passes/StubsPass.cpp
@@ -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 @@ void StubsPass::perform(File& mergedFile) {
// Add all created stubs and support Atoms.
this->addStubAtoms(mergedFile);
}
-
-
-
}
diff --git a/lld/lib/ReaderWriter/ELF/ReaderELF.cpp b/lld/lib/ReaderWriter/ELF/ReaderELF.cpp
index c6553c58d90..f40dacc8f80 100644
--- a/lld/lib/ReaderWriter/ELF/ReaderELF.cpp
+++ b/lld/lib/ReaderWriter/ELF/ReaderELF.cpp
@@ -209,6 +209,9 @@ public:
// 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 @@ public:
}
}
- virtual void addAtom(const Atom&) {
- llvm_unreachable("cannot add atoms to native .o files");
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
}
diff --git a/lld/lib/ReaderWriter/MachO/StubsPass.hpp b/lld/lib/ReaderWriter/MachO/StubsPass.hpp
index ba326e0400a..71e76541f72 100644
--- a/lld/lib/ReaderWriter/MachO/StubsPass.hpp
+++ b/lld/lib/ReaderWriter/MachO/StubsPass.hpp
@@ -119,7 +119,7 @@ public:
}
- virtual void addStubAtoms(File &mergedFile) {
+ virtual void addStubAtoms(MutableFile &mergedFile) {
// Exit early if no stubs needed.
if ( _targetToStub.size() == 0 )
return;
diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
index 1ad37c79892..36389d0cb51 100644
--- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp
+++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
@@ -371,10 +371,6 @@ public:
return _absoluteAtoms;
}
- virtual void addAtom(const Atom&) {
- assert(0 && "cannot add atoms to native .o files");
- }
-
private:
friend class NativeDefinedAtomV1;
friend class NativeUndefinedAtomV1;
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
index 4b1fd68a0b3..3058e81ec89 100644
--- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
@@ -330,10 +330,6 @@ public:
}
}
- virtual void addAtom(const Atom&) {
- llvm_unreachable("cannot add atoms to native .obj files");
- }
-
virtual const atom_collection<DefinedAtom> &defined() const {
return DefinedAtoms;
}
diff --git a/lld/lib/ReaderWriter/ReaderArchive.cpp b/lld/lib/ReaderWriter/ReaderArchive.cpp
index 4a7acdb6a1d..99955617396 100644
--- a/lld/lib/ReaderWriter/ReaderArchive.cpp
+++ b/lld/lib/ReaderWriter/ReaderArchive.cpp
@@ -56,10 +56,6 @@ public:
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;
}
diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
index 93dcf214b43..a89958560c3 100644
--- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -614,10 +614,7 @@ struct MappingTraits<const lld::File*> {
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 @@ struct MappingTraits<const lld::File*> {
_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;
}
diff --git a/lld/tools/lld-core/TestingHelpers.hpp b/lld/tools/lld-core/TestingHelpers.hpp
index 5f065d803fb..4c82630a55e 100644
--- a/lld/tools/lld-core/TestingHelpers.hpp
+++ b/lld/tools/lld-core/TestingHelpers.hpp
@@ -213,10 +213,9 @@ private:
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 @@ public:
return result;
}
- virtual void addStubAtoms(File &mergedFile) {
+ virtual void addStubAtoms(MutableFile &mergedFile) {
for (const DefinedAtom *stub : _file.defined() ) {
mergedFile.addAtom(*stub);
}
diff --git a/lld/tools/lld-core/lld-core.cpp b/lld/tools/lld-core/lld-core.cpp
index eeb49296234..7fcebdedd70 100644
--- a/lld/tools/lld-core/lld-core.cpp
+++ b/lld/tools/lld-core/lld-core.cpp
@@ -263,7 +263,7 @@ int main(int argc, char *argv[]) {
// 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() ) {
OpenPOWER on IntegriCloud