[PATCH] D66767: Add binary filename to the bitcode filename when using -thinlto-index-only

Amy Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 14:00:05 PDT 2019


akhuang created this revision.
akhuang added reviewers: inglorion, rnk.
Herald added subscribers: llvm-commits, arphaman, dexonsmith, steven_wu, mehdi_amini.
Herald added a project: LLVM.

Append binary name to the bitcode filename when using thin archives. This is to make the filenames more unique when doing distributed thinLTO and an object is compiled to multiple binaries.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66767

Files:
  lld/COFF/InputFiles.cpp
  lld/test/COFF/thinlto-archives.ll


Index: lld/test/COFF/thinlto-archives.ll
===================================================================
--- lld/test/COFF/thinlto-archives.ll
+++ lld/test/COFF/thinlto-archives.ll
@@ -9,7 +9,14 @@
 ; RUN: lld-link -out:%T/thinlto-archives/main.exe -entry:main \
 ; RUN:     -lldsavetemps -subsystem:console %T/thinlto-archives/main.obj \
 ; RUN:     %T/thinlto-archives/a.lib %T/thinlto-archives/b.lib
-; RUN: FileCheck %s < %T/thinlto-archives/main.exe.resolution.txt
+; RUN: FileCheck %s < %T/thinlto-archives/main.exe.resolution.txt \
+; RUN:     --check-prefix=CHECK
+; RUN: lld-link -out:%T/thinlto-archives/main2.exe -entry:main \
+; RUN:     -lldsavetemps -subsystem:console %T/thinlto-archives/main.obj \
+; RUN:     %T/thinlto-archives/a.lib %T/thinlto-archives/b.lib \
+; RUN:     -thinlto-index-only
+; RUN: FileCheck %s < %T/thinlto-archives/main2.exe.resolution.txt \
+; RUN:     --check-prefix=THINLTO
 
 ; CHECK: {{/thinlto-archives/main.obj$}}
 ; CHECK: {{^-r=.*/thinlto-archives/main.obj,main,px$}}
@@ -18,6 +25,13 @@
 ; CHECK-NEXT: {{/thinlto-archives/b.libbar.obj[0-9]+$}}
 ; CHECK-NEXT: {{^-r=.*/thinlto-archives/b.libbar.obj[0-9]+,bar,p$}}
 
+; THINLTO: {{/thinlto-archives/main.obj$}}
+; THINLTO: {{^-r=.*/thinlto-archives/main.obj,main,px$}}
+; THINLTO: {{/thinlto-archives/a.libbar.obj[0-9]+.main2.exe$}}
+; THINLTO-NEXT: {{^-r=.*/thinlto-archives/a.libbar.obj[0-9]+.main2.exe,foo,p$}}
+; THINLTO-NEXT: {{/thinlto-archives/b.libbar.obj[0-9]+.main2.exe$}}
+; THINLTO-NEXT: {{^-r=.*/thinlto-archives/b.libbar.obj[0-9]+.main2.exe,bar,p$}}
+
 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-pc-windows-msvc"
 
Index: lld/COFF/InputFiles.cpp
===================================================================
--- lld/COFF/InputFiles.cpp
+++ lld/COFF/InputFiles.cpp
@@ -791,11 +791,15 @@
   // causes a collision which result in only one of the objects being taken
   // into consideration at LTO time (which very likely causes undefined
   // symbols later in the link stage). So we append file offset to make
-  // filename unique.
-  MemoryBufferRef mbref(
-      mb.getBuffer(),
-      saver.save(archiveName + path +
-                 (archiveName.empty() ? "" : utostr(offsetInArchive))));
+  // filename unique. We also append the name of the output binary in case
+  // the object is compiled into multiple binaries.
+  StringRef binaryName = sys::path::filename(config->outputFile);
+  StringRef name =
+      archiveName.empty()
+          ? saver.save(path)
+          : saver.save(archiveName + path + utostr(offsetInArchive) +
+                       (config->thinLTOIndexOnly ? "." + binaryName : ""));
+  MemoryBufferRef mbref(mb.getBuffer(), name);
 
   obj = check(lto::InputFile::create(mbref));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66767.217237.patch
Type: text/x-patch
Size: 2778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190826/4241f49b/attachment.bin>


More information about the llvm-commits mailing list