diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp --- a/lld/ELF/LTO.cpp +++ b/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 os = openFile(path + ".thinlto.bc"); if (!os) continue; diff --git a/lld/test/ELF/lto/thinlto-index-files-thin-archive.ll b/lld/test/ELF/lto/thinlto-index-files-thin-archive.ll new file mode 100644 --- /dev/null +++ b/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 +}