[PATCH] D60924: [ThinLTO] Adding architecture name into saved object filename

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 14:31:59 PDT 2019


steven_wu created this revision.
steven_wu added reviewers: tejohnson, bd1976llvm, dexonsmith.
Herald added subscribers: dang, jkorous, hiraditya, eraman, inglorion, aprantl, mehdi_amini.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60924

Files:
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp


Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -817,9 +817,11 @@
 /// Returns the path to the generated file in SavedObjectsDirectoryPath.
 static std::string writeGeneratedObject(int count, StringRef CacheEntryPath,
                                         StringRef SavedObjectsDirectoryPath,
-                                        const MemoryBuffer &OutputBuffer) {
+                                        const MemoryBuffer &OutputBuffer,
+                                        StringRef ArchName) {
   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.
   if (sys::fs::exists(OutputPath))
     sys::fs::remove(OutputPath);
@@ -883,7 +885,8 @@
           ProducedBinaries[count] = std::move(OutputBuffer);
         else
           ProducedBinaryFiles[count] = writeGeneratedObject(
-              count, "", SavedObjectsDirectoryPath, *OutputBuffer);
+              count, "", SavedObjectsDirectoryPath, *OutputBuffer,
+              TMBuilder.TheTriple.getArchName());
       }, count++);
     }
 
@@ -1007,7 +1010,7 @@
             else
               ProducedBinaryFiles[count] = writeGeneratedObject(
                   count, CacheEntryPath, SavedObjectsDirectoryPath,
-                  *ErrOrBuffer.get());
+                  *ErrOrBuffer.get(), TMBuilder.TheTriple.getArchName());
             return;
           }
         }
@@ -1064,7 +1067,8 @@
           return;
         }
         ProducedBinaryFiles[count] = writeGeneratedObject(
-            count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
+            count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer,
+            TMBuilder.TheTriple.getArchName());
       }, IndexCount);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60924.195918.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190419/0fc89f4d/attachment.bin>


More information about the llvm-commits mailing list