summaryrefslogtreecommitdiffstats
path: root/lld/lib
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2013-10-24 03:30:03 +0000
committerShankar Easwaran <shankare@codeaurora.org>2013-10-24 03:30:03 +0000
commit89c2d8facaf9c97a2802a3ee139647b7c346ea5e (patch)
treee6574b2843cd52ce5494e2786cc576434bce706b /lld/lib
parent887c20ffc2691c26be081da69fb8844cdbf63832 (diff)
downloadbcm5719-llvm-89c2d8facaf9c97a2802a3ee139647b7c346ea5e.tar.gz
bcm5719-llvm-89c2d8facaf9c97a2802a3ee139647b7c346ea5e.zip
[PassManager] add ReaderWriter{Native,YAML} to the Driver.
Disable tests to be run with REQUIRES: disable. Note disable is not added to the config by the test runner Mkaefiles, so essentially disables the test. Code changes would be required to fix these tests :- test/darwin/hello-world.objtxt test/elf/check.test test/elf/phdr.test test/elf/ppc.test test/elf/undef-from-main-dso.test test/elf/X86_64/note-sections-ro_plus_rw.test test/pecoff/alignment.test test/pecoff/base-reloc.test test/pecoff/bss-section.test test/pecoff/drectve.test test/pecoff/dynamic.test test/pecoff/dynamicbase.test test/pecoff/entry.test test/pecoff/hello.test test/pecoff/imagebase.test test/pecoff/importlib.test test/pecoff/lib.test test/pecoff/multi.test test/pecoff/reloc.test test/pecoff/weak-external.test llvm-svn: 193300
Diffstat (limited to 'lld/lib')
-rw-r--r--lld/lib/Core/PassManager.cpp2
-rw-r--r--lld/lib/Core/Resolver.cpp2
-rw-r--r--lld/lib/Driver/Driver.cpp12
-rw-r--r--lld/lib/Passes/CMakeLists.txt4
-rw-r--r--lld/lib/Passes/GOTPass.cpp6
-rw-r--r--lld/lib/Passes/LayoutPass.cpp4
-rw-r--r--lld/lib/Passes/RoundTripNativePass.cpp44
-rw-r--r--lld/lib/Passes/RoundTripYAMLPass.cpp44
-rw-r--r--lld/lib/Passes/StubsPass.cpp6
-rw-r--r--lld/lib/ReaderWriter/CoreLinkingContext.cpp5
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp14
-rw-r--r--lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp18
-rw-r--r--lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h6
-rw-r--r--lld/lib/ReaderWriter/PECOFF/IdataPass.h8
14 files changed, 138 insertions, 37 deletions
diff --git a/lld/lib/Core/PassManager.cpp b/lld/lib/Core/PassManager.cpp
index 238fb0a6b64..715a5fbda11 100644
--- a/lld/lib/Core/PassManager.cpp
+++ b/lld/lib/Core/PassManager.cpp
@@ -15,7 +15,7 @@
#include "llvm/Support/ErrorOr.h"
namespace lld {
-ErrorOr<void> PassManager::runOnFile(MutableFile &mf) {
+ErrorOr<void> PassManager::runOnFile(std::unique_ptr<MutableFile> &mf) {
for (auto &pass : _passes) {
pass->perform(mf);
}
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index 3a34cd3fe3f..3af0c5cba71 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -480,7 +480,7 @@ bool Resolver::resolve() {
}
this->removeCoalescedAwayAtoms();
this->linkTimeOptimize();
- this->_result.addAtoms(_atoms);
+ this->_result->addAtoms(_atoms);
return true;
}
diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp
index 6f0f4ecdde6..fcbdbe723b5 100644
--- a/lld/lib/Driver/Driver.cpp
+++ b/lld/lib/Driver/Driver.cpp
@@ -16,6 +16,8 @@
#include "lld/Core/Resolver.h"
#include "lld/ReaderWriter/Reader.h"
#include "lld/ReaderWriter/Writer.h"
+#include "lld/Passes/RoundTripNativePass.h"
+#include "lld/Passes/RoundTripYAMLPass.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
@@ -105,19 +107,25 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) {
Resolver resolver(context);
if (!resolver.resolve())
return false;
- MutableFile &merged = resolver.resultFile();
+ std::unique_ptr<MutableFile> merged = resolver.resultFile();
resolveTask.end();
// Run passes on linked atoms.
ScopedTask passTask(getDefaultDomain(), "Passes");
PassManager pm;
context.addPasses(pm);
+
+#ifndef NDEBUG
+ pm.add(std::unique_ptr<Pass>(new RoundTripNativePass(context)));
+ pm.add(std::unique_ptr<Pass>(new RoundTripYAMLPass(context)));
+#endif
+
pm.runOnFile(merged);
passTask.end();
// Give linked atoms to Writer to generate output file.
ScopedTask writeTask(getDefaultDomain(), "Write");
- if (error_code ec = context.writeFile(merged)) {
+ if (error_code ec = context.writeFile(*merged)) {
diagnostics << "Failed to write file '" << context.outputPath()
<< "': " << ec.message() << "\n";
return false;
diff --git a/lld/lib/Passes/CMakeLists.txt b/lld/lib/Passes/CMakeLists.txt
index 10759023a38..3cec05afec5 100644
--- a/lld/lib/Passes/CMakeLists.txt
+++ b/lld/lib/Passes/CMakeLists.txt
@@ -2,4 +2,8 @@ add_lld_library(lldPasses
GOTPass.cpp
StubsPass.cpp
LayoutPass.cpp
+ RoundTripNativePass.cpp
+ RoundTripYAMLPass.cpp
)
+
+target_link_libraries(lldPasses lldReaderWriter)
diff --git a/lld/lib/Passes/GOTPass.cpp b/lld/lib/Passes/GOTPass.cpp
index 1bb6e4cee4a..b9a6f73e5b1 100644
--- a/lld/lib/Passes/GOTPass.cpp
+++ b/lld/lib/Passes/GOTPass.cpp
@@ -67,12 +67,12 @@ findGOTAtom(const Atom *target,
}
} // end anonymous namespace
-void GOTPass::perform(MutableFile &mergedFile) {
+void GOTPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
// Use map so all pointers to same symbol use same GOT entry.
llvm::DenseMap<const Atom*, const DefinedAtom*> targetToGOT;
// Scan all references in all atoms.
- for(const DefinedAtom *atom : mergedFile.defined()) {
+ for (const DefinedAtom *atom : mergedFile->defined()) {
for (const Reference *ref : *atom) {
// Look at instructions accessing the GOT.
bool canBypassGOT;
@@ -102,7 +102,7 @@ void GOTPass::perform(MutableFile &mergedFile) {
// add all created GOT Atoms to master file
for (auto &it : targetToGOT) {
- mergedFile.addAtom(*it.second);
+ mergedFile->addAtom(*it.second);
}
}
}
diff --git a/lld/lib/Passes/LayoutPass.cpp b/lld/lib/Passes/LayoutPass.cpp
index b00887d6fd4..f7e73df7087 100644
--- a/lld/lib/Passes/LayoutPass.cpp
+++ b/lld/lib/Passes/LayoutPass.cpp
@@ -534,9 +534,9 @@ void LayoutPass::checkFollowonChain(MutableFile::DefinedAtomRange &range) {
#endif // #ifndef NDEBUG
/// Perform the actual pass
-void LayoutPass::perform(MutableFile &mergedFile) {
+void LayoutPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
ScopedTask task(getDefaultDomain(), "LayoutPass");
- MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
+ MutableFile::DefinedAtomRange atomRange = mergedFile->definedAtoms();
// Build follow on tables
buildFollowOnTable(atomRange);
diff --git a/lld/lib/Passes/RoundTripNativePass.cpp b/lld/lib/Passes/RoundTripNativePass.cpp
new file mode 100644
index 00000000000..fb06e5c5fae
--- /dev/null
+++ b/lld/lib/Passes/RoundTripNativePass.cpp
@@ -0,0 +1,44 @@
+//===- Passes/RoundTripNativePass.cpp - Layout atoms
+//-------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "RoundTripNativePass"
+
+#include "lld/Core/Instrumentation.h"
+#include "lld/Passes/RoundTripNativePass.h"
+#include "lld/ReaderWriter/Simple.h"
+#include "lld/ReaderWriter/Writer.h"
+
+#include "llvm/Support/Path.h"
+
+using namespace lld;
+
+/// Perform the actual pass
+void RoundTripNativePass::perform(std::unique_ptr<MutableFile> &mergedFile) {
+ ScopedTask task(getDefaultDomain(), "RoundTripNativePass");
+ std::unique_ptr<Writer> nativeWriter = createWriterNative(_context);
+ SmallString<128> tmpNativeFile;
+ // Separate the directory from the filename
+ StringRef outFile = llvm::sys::path::filename(_context.outputPath());
+ if (llvm::sys::fs::createTemporaryFile(outFile, "native", tmpNativeFile))
+ return;
+
+ nativeWriter->writeFile(*mergedFile, tmpNativeFile.str());
+ llvm::OwningPtr<llvm::MemoryBuffer> buff;
+ if (llvm::MemoryBuffer::getFileOrSTDIN(tmpNativeFile.str(), buff))
+ return;
+
+ std::unique_ptr<MemoryBuffer> mb(buff.take());
+ _context.getNativeReader().parseFile(mb, _nativeFile);
+
+ mergedFile.reset(new FileToMutable(_context, *_nativeFile[0].get()));
+
+ llvm::sys::fs::remove(tmpNativeFile.str());
+}
diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp
new file mode 100644
index 00000000000..ede55b0c55d
--- /dev/null
+++ b/lld/lib/Passes/RoundTripYAMLPass.cpp
@@ -0,0 +1,44 @@
+//===- Passes/RoundTripYAMLPass.cpp - Layout atoms
+//-------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "RoundTripYAMLPass"
+
+#include "lld/Core/Instrumentation.h"
+#include "lld/Passes/RoundTripYAMLPass.h"
+#include "lld/ReaderWriter/Simple.h"
+#include "lld/ReaderWriter/Writer.h"
+
+#include "llvm/Support/Path.h"
+
+using namespace lld;
+
+/// Perform the actual pass
+void RoundTripYAMLPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
+ ScopedTask task(getDefaultDomain(), "RoundTripYAMLPass");
+ std::unique_ptr<Writer> yamlWriter = createWriterYAML(_context);
+ SmallString<128> tmpYAMLFile;
+ // Separate the directory from the filename
+ StringRef outFile = llvm::sys::path::filename(_context.outputPath());
+ if (llvm::sys::fs::createTemporaryFile(outFile, "yaml", tmpYAMLFile))
+ return;
+
+ yamlWriter->writeFile(*mergedFile, tmpYAMLFile.str());
+ llvm::OwningPtr<llvm::MemoryBuffer> buff;
+ if (llvm::MemoryBuffer::getFileOrSTDIN(tmpYAMLFile.str(), buff))
+ return;
+
+ std::unique_ptr<MemoryBuffer> mb(buff.take());
+ _context.getYAMLReader().parseFile(mb, _yamlFile);
+
+ mergedFile.reset(new FileToMutable(_context, *_yamlFile[0].get()));
+
+ llvm::sys::fs::remove(tmpYAMLFile.str());
+}
diff --git a/lld/lib/Passes/StubsPass.cpp b/lld/lib/Passes/StubsPass.cpp
index ef3870580cb..b75f2316bcb 100644
--- a/lld/lib/Passes/StubsPass.cpp
+++ b/lld/lib/Passes/StubsPass.cpp
@@ -23,13 +23,13 @@
namespace lld {
-void StubsPass::perform(MutableFile &mergedFile) {
+void StubsPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
// Skip this pass if output format uses text relocations instead of stubs.
if ( ! this->noTextRelocs() )
return;
// Scan all references in all atoms.
- for(const DefinedAtom *atom : mergedFile.defined()) {
+ for (const DefinedAtom *atom : mergedFile->defined()) {
for (const Reference *ref : *atom) {
// Look at call-sites.
if (this->isCallSite(ref->kind()) ) {
@@ -61,6 +61,6 @@ void StubsPass::perform(MutableFile &mergedFile) {
}
// Add all created stubs and support Atoms.
- this->addStubAtoms(mergedFile);
+ this->addStubAtoms(*mergedFile);
}
}
diff --git a/lld/lib/ReaderWriter/CoreLinkingContext.cpp b/lld/lib/ReaderWriter/CoreLinkingContext.cpp
index ec8962bbce2..d6e522c5dcc 100644
--- a/lld/lib/ReaderWriter/CoreLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/CoreLinkingContext.cpp
@@ -12,6 +12,7 @@
#include "lld/Core/Pass.h"
#include "lld/Core/PassManager.h"
#include "lld/Passes/LayoutPass.h"
+#include "lld/ReaderWriter/Simple.h"
#include "llvm/ADT/ArrayRef.h"
@@ -149,10 +150,10 @@ private:
uint32_t _ordinal;
};
-class TestingPassFile : public MutableFile {
+class TestingPassFile : public SimpleFile {
public:
TestingPassFile(const LinkingContext &ctx)
- : MutableFile(ctx, "Testing pass") {}
+ : SimpleFile(ctx, "Testing pass") {}
virtual void addAtom(const Atom &atom) {
if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom))
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
index 7c918877fc2..659dcb15ad0 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
@@ -157,9 +157,9 @@ public:
///
/// After all references are handled, the atoms created during that are all
/// added to mf.
- virtual void perform(MutableFile &mf) {
+ virtual void perform(std::unique_ptr<MutableFile> &mf) {
// Process all references.
- for (const auto &atom : mf.defined())
+ for (const auto &atom : mf->defined())
for (const auto &ref : *atom)
handleReference(*atom, *ref);
@@ -167,23 +167,23 @@ public:
uint64_t ordinal = 0;
if (_PLT0) {
_PLT0->setOrdinal(ordinal++);
- mf.addAtom(*_PLT0);
+ mf->addAtom(*_PLT0);
}
for (auto &plt : _pltVector) {
plt->setOrdinal(ordinal++);
- mf.addAtom(*plt);
+ mf->addAtom(*plt);
}
if (_null) {
_null->setOrdinal(ordinal++);
- mf.addAtom(*_null);
+ mf->addAtom(*_null);
}
if (_got0) {
_got0->setOrdinal(ordinal++);
- mf.addAtom(*_got0);
+ mf->addAtom(*_got0);
}
for (auto &got : _gotVector) {
got->setOrdinal(ordinal++);
- mf.addAtom(*got);
+ mf->addAtom(*got);
}
}
diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp
index 5aeb1f95ac6..f52629db324 100644
--- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp
+++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.cpp
@@ -219,10 +219,10 @@ public:
///
/// After all references are handled, the atoms created during that are all
/// added to mf.
- virtual void perform(MutableFile &mf) {
+ virtual void perform(std::unique_ptr<MutableFile> &mf) {
ScopedTask task(getDefaultDomain(), "X86-64 GOT/PLT Pass");
// Process all references.
- for (const auto &atom : mf.defined())
+ for (const auto &atom : mf->defined())
for (const auto &ref : *atom)
handleReference(*atom, *ref);
@@ -230,29 +230,29 @@ public:
uint64_t ordinal = 0;
if (_PLT0) {
_PLT0->setOrdinal(ordinal++);
- mf.addAtom(*_PLT0);
+ mf->addAtom(*_PLT0);
}
for (auto &plt : _pltVector) {
plt->setOrdinal(ordinal++);
- mf.addAtom(*plt);
+ mf->addAtom(*plt);
}
if (_null) {
_null->setOrdinal(ordinal++);
- mf.addAtom(*_null);
+ mf->addAtom(*_null);
}
if (_PLT0) {
_got0->setOrdinal(ordinal++);
_got1->setOrdinal(ordinal++);
- mf.addAtom(*_got0);
- mf.addAtom(*_got1);
+ mf->addAtom(*_got0);
+ mf->addAtom(*_got1);
}
for (auto &got : _gotVector) {
got->setOrdinal(ordinal++);
- mf.addAtom(*got);
+ mf->addAtom(*got);
}
for (auto obj : _objectVector) {
obj->setOrdinal(ordinal++);
- mf.addAtom(*obj);
+ mf->addAtom(*obj);
}
}
diff --git a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
index f8836061a07..e3186031b87 100644
--- a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
+++ b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
@@ -60,9 +60,9 @@ class GroupedSectionsPass : public lld::Pass {
public:
GroupedSectionsPass() {}
- virtual void perform(MutableFile &mergedFile) {
- std::map<StringRef, std::vector<COFFDefinedAtom *>> sectionToHeadAtoms(
- filterHeadAtoms(mergedFile));
+ virtual void perform(std::unique_ptr<MutableFile> &mergedFile) {
+ std::map<StringRef, std::vector<COFFDefinedAtom *> > sectionToHeadAtoms(
+ filterHeadAtoms(*mergedFile));
std::vector<std::vector<COFFDefinedAtom *>> groupedAtomsList(
groupBySectionName(sectionToHeadAtoms));
for (auto &groupedAtoms : groupedAtomsList)
diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.h b/lld/lib/ReaderWriter/PECOFF/IdataPass.h
index beb9401d3ee..f56376fba2c 100644
--- a/lld/lib/ReaderWriter/PECOFF/IdataPass.h
+++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.h
@@ -252,13 +252,13 @@ class IdataPass : public lld::Pass {
public:
IdataPass(const LinkingContext &ctx) : _dummyFile(ctx) {}
- virtual void perform(MutableFile &file) {
- if (file.sharedLibrary().size() == 0)
+ virtual void perform(std::unique_ptr<MutableFile> &file) {
+ if (file->sharedLibrary().size() == 0)
return;
- Context context(file, _dummyFile);
+ Context context(*file, _dummyFile);
map<StringRef, vector<COFFSharedLibraryAtom *> > sharedAtoms =
- groupByLoadName(file);
+ groupByLoadName(*file);
for (auto i : sharedAtoms) {
StringRef loadName = i.first;
vector<COFFSharedLibraryAtom *> &atoms = i.second;
OpenPOWER on IntegriCloud