[PATCH] D135014: [lld][ELF] Fix lazy ThinLTO index writing in thin archives

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 1 01:13:21 PDT 2022


aidengrossman created this revision.
Herald added subscribers: ormris, arphaman, steven_wu, hiraditya, arichardson, inglorion, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added subscribers: llvm-commits, StephenFan.
Herald added a project: LLVM.

Currently when the --thinlto-emit-index-files is used with LLD and a
thin archive is passed containing references to object files to link
against where the object files are in a different folder than the thin
archive and some of the archives aren't linked against (ie stay lazy),
the empty index file writer ends up trying to write to a path that
doesn't exist. This patch changes the behavior of that function to use
the path of the obj member of the BitcodeFile object rather than just
the path of the BitcodeFile object itself, which matches the behavior of
the default (non-lazy) case.

Fixes #57963

Regression test added.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135014

Files:
  lld/ELF/LTO.cpp
  lld/test/ELF/lto/thinlto-index-files-thin-archive.ll


Index: lld/test/ELF/lto/thinlto-index-files-thin-archive.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/lto/thinlto-index-files-thin-archive.ll
@@ -0,0 +1,26 @@
+; REQUIRES: x86
+
+;; Make sure that when we are linking against a thin archive in a different
+;; folder from the object files it references, bitcode files that have
+;; their ThinLTO index files written lazily (because they're not linked
+;; against) have their file paths resolved correctly. Regression test for
+;; #57963 on the issue tracker.
+; RUN: rm -rf %t.dir && mkdir %t.dir && cd %t.dir
+; RUN: mkdir test-folder-1
+; RUN: llvm-as %s -o ./test-folder-1/a.o
+; RUN: llvm-as %p/Inputs/thinlto.ll -o ./test-folder-1/b.o
+; RUN: mkdir test-folder-2
+; RUN: llvm-ar -crT ./test-folder-2/lib.a test-folder-1/a.o test-folder-1/b.o
+; RUN: ld.lld --thinlto-emit-index-files -shared ./test-folder-2/lib.a -o c
+; RUN: ls ./test-folder-2 | FileCheck %s
+
+; CHECK: lib.a(a.o
+; CHECK-NEXT: lib.a(b.o
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() {
+entry:
+  ret void
+}
Index: lld/ELF/LTO.cpp
===================================================================
--- lld/ELF/LTO.cpp
+++ lld/ELF/LTO.cpp
@@ -301,7 +301,8 @@
       continue;
     if (linkedBitCodeFiles.contains(f->getName()))
       continue;
-    std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
+    std::string path =
+        replaceThinLTOSuffix(getThinLTOOutputFile(f->obj->getName()));
     std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
     if (!os)
       continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135014.464481.patch
Type: text/x-patch
Size: 1724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221001/40b0ffaa/attachment.bin>


More information about the llvm-commits mailing list