[ThinLTO] Adding architecture name into saved object filename
Summary: For ThinLTOCodegenerator, it has an option to save the object file outputs into a directory which is essential for debug info. Tools like lldb and dsymutil will look for these object files for debug info. On Darwin platform, you can link fat binaries with one single clang driver invocation like: $ clang -arch x86_64 -arch i386 -Wl,-object_path_lto,$TMPDIR ... Unfornately, the output object files for one architecture is going to overwrite the previous ones and one architecture slice will end up with no debug info. One example for this is to turn on ThinLTO for sanitizer dylibs in compiler-rt project. To fix the issue, add the name for the architecture into the name of the output object file. rdar://problem/35482935 Reviewers: tejohnson, bd1976llvm, dexonsmith, JDevlieghere Reviewed By: dexonsmith Subscribers: mehdi_amini, aprantl, inglorion, eraman, hiraditya, jkorous, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60924 llvm-svn: 359508
This commit is contained in:
parent
5f789bafa1
commit
6c9f6fd11b
|
@ -287,6 +287,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void optimize(Module &Module);
|
void optimize(Module &Module);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write temporary object file to SavedObjectDirectoryPath, write symlink
|
||||||
|
* to Cache directory if needed. Returns the path to the generated file in
|
||||||
|
* SavedObjectsDirectoryPath.
|
||||||
|
*/
|
||||||
|
std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
|
||||||
|
const MemoryBuffer &OutputBuffer);
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -815,11 +815,13 @@ void ThinLTOCodeGenerator::optimize(Module &TheModule) {
|
||||||
/// Write out the generated object file, either from CacheEntryPath or from
|
/// Write out the generated object file, either from CacheEntryPath or from
|
||||||
/// OutputBuffer, preferring hard-link when possible.
|
/// OutputBuffer, preferring hard-link when possible.
|
||||||
/// Returns the path to the generated file in SavedObjectsDirectoryPath.
|
/// Returns the path to the generated file in SavedObjectsDirectoryPath.
|
||||||
static std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
|
std::string
|
||||||
StringRef SavedObjectsDirectoryPath,
|
ThinLTOCodeGenerator::writeGeneratedObject(int count, StringRef CacheEntryPath,
|
||||||
const MemoryBuffer &OutputBuffer) {
|
const MemoryBuffer &OutputBuffer) {
|
||||||
|
auto ArchName = TMBuilder.TheTriple.getArchName();
|
||||||
SmallString<128> OutputPath(SavedObjectsDirectoryPath);
|
SmallString<128> OutputPath(SavedObjectsDirectoryPath);
|
||||||
llvm::sys::path::append(OutputPath, Twine(count) + ".thinlto.o");
|
llvm::sys::path::append(OutputPath,
|
||||||
|
Twine(count) + "." + ArchName + ".thinlto.o");
|
||||||
OutputPath.c_str(); // Ensure the string is null terminated.
|
OutputPath.c_str(); // Ensure the string is null terminated.
|
||||||
if (sys::fs::exists(OutputPath))
|
if (sys::fs::exists(OutputPath))
|
||||||
sys::fs::remove(OutputPath);
|
sys::fs::remove(OutputPath);
|
||||||
|
@ -882,8 +884,8 @@ void ThinLTOCodeGenerator::run() {
|
||||||
if (SavedObjectsDirectoryPath.empty())
|
if (SavedObjectsDirectoryPath.empty())
|
||||||
ProducedBinaries[count] = std::move(OutputBuffer);
|
ProducedBinaries[count] = std::move(OutputBuffer);
|
||||||
else
|
else
|
||||||
ProducedBinaryFiles[count] = writeGeneratedObject(
|
ProducedBinaryFiles[count] =
|
||||||
count, "", SavedObjectsDirectoryPath, *OutputBuffer);
|
writeGeneratedObject(count, "", *OutputBuffer);
|
||||||
}, count++);
|
}, count++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1006,8 +1008,7 @@ void ThinLTOCodeGenerator::run() {
|
||||||
ProducedBinaries[count] = std::move(ErrOrBuffer.get());
|
ProducedBinaries[count] = std::move(ErrOrBuffer.get());
|
||||||
else
|
else
|
||||||
ProducedBinaryFiles[count] = writeGeneratedObject(
|
ProducedBinaryFiles[count] = writeGeneratedObject(
|
||||||
count, CacheEntryPath, SavedObjectsDirectoryPath,
|
count, CacheEntryPath, *ErrOrBuffer.get());
|
||||||
*ErrOrBuffer.get());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1065,7 @@ void ThinLTOCodeGenerator::run() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProducedBinaryFiles[count] = writeGeneratedObject(
|
ProducedBinaryFiles[count] = writeGeneratedObject(
|
||||||
count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
|
count, CacheEntryPath, *OutputBuffer);
|
||||||
}, IndexCount);
|
}, IndexCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
; RUN: ls %t.thin.out | count 2
|
; RUN: ls %t.thin.out | count 2
|
||||||
; RUN: ls %t.cache | count 3
|
; RUN: ls %t.cache | count 3
|
||||||
|
|
||||||
|
; Check the name of object in directory has arch name included.
|
||||||
|
; RUN: ls %t.thin.out | grep x86_64.thinlto.o | count 2
|
||||||
|
|
||||||
|
|
||||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-apple-macosx10.11.0"
|
target triple = "x86_64-apple-macosx10.11.0"
|
||||||
|
|
Loading…
Reference in New Issue