aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-07-22 22:20:18 +0000
committerDevang Patel <dpatel@apple.com>2008-07-22 22:20:18 +0000
commit38bcec13e89b33fd6b0553ec47667744c54fbb7b (patch)
treea1710ddf80fec89b92d6a2584daa628eaec70f3c
parentace3c17798d49245593cd9d2312a68e1ebafae56 (diff)
Quit early, if unable to reproduce error using original input files.
Quit, if unable to fix error when linker input files are all native object files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53935 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/lto-bugpoint/LTOBugPoint.cpp81
-rw-r--r--tools/lto-bugpoint/LTOBugPoint.h6
2 files changed, 86 insertions, 1 deletions
diff --git a/tools/lto-bugpoint/LTOBugPoint.cpp b/tools/lto-bugpoint/LTOBugPoint.cpp
index 7b01407465..d54b28d251 100644
--- a/tools/lto-bugpoint/LTOBugPoint.cpp
+++ b/tools/lto-bugpoint/LTOBugPoint.cpp
@@ -58,7 +58,13 @@ bool
LTOBugPoint::findTroubleMakers(SmallVector<std::string, 4> &TroubleMakers,
std::string &Script) {
- // First, build native object files set.
+ // Reproduce original error.
+ if (!relinkProgram(LinkerInputFiles) || !reproduceProgramError(Script)) {
+ ErrMsg += " Unable to reproduce original error!";
+ return false;
+ }
+
+ // Build native object files set.
bool bitcodeFileSeen = false;
unsigned Size = LinkerInputFiles.size();
for (unsigned I = 0; I < Size; ++I) {
@@ -84,6 +90,17 @@ LTOBugPoint::findTroubleMakers(SmallVector<std::string, 4> &TroubleMakers,
return false;
}
+ // Try to reproduce error using native object files first. If the error
+ // occurs then this is not a LTO error.
+ if (!relinkProgram(NativeInputFiles)) {
+ ErrMsg += " Unable to link the program using all native object files!";
+ return false;
+ }
+ if (reproduceProgramError(Script) == true) {
+ ErrMsg += " Unable to fix program error using all native object files!";
+ return false;
+ }
+
return true;
}
@@ -246,3 +263,65 @@ bool LTOBugPoint::getNativeObjectFile(std::string &FileName) {
AsmFile.eraseFromDisk();
return true;
}
+
+/// relinkProgram - Relink program. Return false if linking fails.
+bool LTOBugPoint::relinkProgram(llvm::SmallVector<std::string, 16> &InFiles) {
+ if (InFiles.empty())
+ return false;
+
+ // Atleast three options: linker path, -o and output file name.
+ if (LinkerOptions.size() < 3)
+ return false;
+
+ const sys::Path linker = sys::Program::FindProgramByName(LinkerOptions[0]);
+ if (linker.isEmpty()) {
+ ErrMsg = "can't locate linker";
+ return false;
+ }
+
+ std::vector<const char*> Args;
+ for (unsigned i = 0, e = LinkerOptions.size(); i < e; ++i)
+ Args.push_back(LinkerOptions[i].c_str());
+
+ for (unsigned i = 0, e = InFiles.size(); i < e; ++i)
+ Args.push_back(InFiles[i].c_str());
+
+ Args.push_back(0);
+
+ if (sys::Program::ExecuteAndWait(linker, &Args[0], 0, 0, 0, 0, &ErrMsg)) {
+ ErrMsg += "error while linking program";
+ return false;
+ }
+
+ return true;
+}
+
+/// reproduceProgramError - Validate program using user provided script.
+/// Return true if program error is reproduced.
+bool LTOBugPoint::reproduceProgramError(std::string &Script) {
+
+ const sys::Path validator = sys::Program::FindProgramByName(Script);
+ if (validator.isEmpty()) {
+ ErrMsg = "can't locate validation script";
+ return false;
+ }
+
+ std::vector<const char*> Args;
+ Args.push_back(Script.c_str());
+ Args.push_back(0);
+
+ int result =
+ sys::Program::ExecuteAndWait(validator, &Args[0], 0, 0, 0, 0, &ErrMsg);
+
+ // Validation scrip returns non-zero if the error is reproduced.
+ if (result > 0)
+ // Able to reproduce program error.
+ return true;
+
+ else if (result < 0)
+ // error occured while running validation script. ErrMsg contains error
+ // description.
+ return false;
+
+ return false;
+}
diff --git a/tools/lto-bugpoint/LTOBugPoint.h b/tools/lto-bugpoint/LTOBugPoint.h
index 7634357915..5f1b5cce2b 100644
--- a/tools/lto-bugpoint/LTOBugPoint.h
+++ b/tools/lto-bugpoint/LTOBugPoint.h
@@ -57,4 +57,10 @@ private:
/// assembleBitcode - Generate assembly code from the module. Return false
/// in case of an error.
bool assembleBitcode(llvm::Module *M, const char *AsmFileName);
+
+ /// relinkProgram - Relink program. Return false if linking fails.
+ bool relinkProgram(llvm::SmallVector<std::string, 16> &InputFiles);
+
+ /// reproduceProgramError - Validate program using user provided script.
+ bool reproduceProgramError(std::string &Script);
};