Skip to content
This repository was archived by the owner on Oct 24, 2019. It is now read-only.

Commit 59470d4

Browse files
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359508 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3d677cf commit 59470d4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ class ThinLTOCodeGenerator {
299299
*/
300300
void optimize(Module &Module);
301301

302+
/**
303+
* Write temporary object file to SavedObjectDirectoryPath, write symlink
304+
* to Cache directory if needed. Returns the path to the generated file in
305+
* SavedObjectsDirectoryPath.
306+
*/
307+
std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
308+
const MemoryBuffer &OutputBuffer);
302309
/**@}*/
303310

304311
private:

lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,13 @@ void ThinLTOCodeGenerator::optimize(Module &TheModule) {
777777
/// Write out the generated object file, either from CacheEntryPath or from
778778
/// OutputBuffer, preferring hard-link when possible.
779779
/// Returns the path to the generated file in SavedObjectsDirectoryPath.
780-
static std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
781-
StringRef SavedObjectsDirectoryPath,
782-
const MemoryBuffer &OutputBuffer) {
780+
std::string
781+
ThinLTOCodeGenerator::writeGeneratedObject(int count, StringRef CacheEntryPath,
782+
const MemoryBuffer &OutputBuffer) {
783+
auto ArchName = TMBuilder.TheTriple.getArchName();
783784
SmallString<128> OutputPath(SavedObjectsDirectoryPath);
784-
llvm::sys::path::append(OutputPath, Twine(count) + ".thinlto.o");
785+
llvm::sys::path::append(OutputPath,
786+
Twine(count) + "." + ArchName + ".thinlto.o");
785787
OutputPath.c_str(); // Ensure the string is null terminated.
786788
if (sys::fs::exists(OutputPath))
787789
sys::fs::remove(OutputPath);
@@ -845,8 +847,8 @@ void ThinLTOCodeGenerator::run() {
845847
if (SavedObjectsDirectoryPath.empty())
846848
ProducedBinaries[count] = std::move(OutputBuffer);
847849
else
848-
ProducedBinaryFiles[count] = writeGeneratedObject(
849-
count, "", SavedObjectsDirectoryPath, *OutputBuffer);
850+
ProducedBinaryFiles[count] =
851+
writeGeneratedObject(count, "", *OutputBuffer);
850852
}, count++);
851853
}
852854

@@ -963,8 +965,7 @@ void ThinLTOCodeGenerator::run() {
963965
ProducedBinaries[count] = std::move(ErrOrBuffer.get());
964966
else
965967
ProducedBinaryFiles[count] = writeGeneratedObject(
966-
count, CacheEntryPath, SavedObjectsDirectoryPath,
967-
*ErrOrBuffer.get());
968+
count, CacheEntryPath, *ErrOrBuffer.get());
968969
return;
969970
}
970971
}
@@ -1021,7 +1022,7 @@ void ThinLTOCodeGenerator::run() {
10211022
return;
10221023
}
10231024
ProducedBinaryFiles[count] = writeGeneratedObject(
1024-
count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
1025+
count, CacheEntryPath, *OutputBuffer);
10251026
}, IndexCount);
10261027
}
10271028
}

test/ThinLTO/X86/save_objects.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
; RUN: ls %t.thin.out | count 2
2121
; RUN: ls %t.cache | count 3
2222

23+
; Check the name of object in directory has arch name included.
24+
; RUN: ls %t.thin.out | grep x86_64.thinlto.o | count 2
25+
2326

2427
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2528
target triple = "x86_64-apple-macosx10.11.0"

0 commit comments

Comments
 (0)