[PATCH] D56046: Output ELF files after ThinLTO is run.

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 4 15:28:56 PST 2019


void updated this revision to Diff 180332.
void added a comment.

Implement Rui's suggestion for how to output the ELF files.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56046/new/

https://reviews.llvm.org/D56046

Files:
  ELF/LTO.cpp
  test/ELF/lto/Inputs/obj-path.ll
  test/ELF/lto/obj-path.ll


Index: test/ELF/lto/obj-path.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/obj-path.ll
@@ -0,0 +1,33 @@
+; REQUIRES: x86
+
+; RUN: opt -module-summary %s -o %t1.o
+; RUN: opt -module-summary %p/Inputs/obj-path.ll -o %t2.o
+
+; Test to ensure that obj-path creates the ELF file.
+; RUN: rm -f %t4.o
+; RUN: ld.lld --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3
+; RUN: llvm-readobj -t %t3 | FileCheck %s
+; RUN: llvm-readobj -h %t4.o1 | FileCheck -check-prefix=ELF %s
+; RUN: llvm-readobj -h %t4.o2 | FileCheck -check-prefix=ELF %s
+; RUN: llvm-nm %t4.o1 2>&1 | FileCheck %s -check-prefix=SYMBOLS
+; RUN: llvm-nm %t4.o2 2>&1 | FileCheck %p/Inputs/obj-path.ll -check-prefix=SYMBOLS
+
+; CHECK:      Name: g
+; CHECK-NEXT: Value: 0x1010
+; CHECK:      Name: f
+; CHECK-NEXT: Value: 0x1000
+
+; SYMBOLS: T f
+
+; ELF: Format: ELF64-x86-64
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @g(...)
+
+define void @f() {
+entry:
+  call void (...) @g()
+  ret void
+}
Index: test/ELF/lto/Inputs/obj-path.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/Inputs/obj-path.ll
@@ -0,0 +1,10 @@
+; SYMBOLS: T g
+
+; ELF: Format: ELF64-x86-64
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @g() {
+entry:
+  ret void
+}
Index: ELF/LTO.cpp
===================================================================
--- ELF/LTO.cpp
+++ ELF/LTO.cpp
@@ -275,20 +275,23 @@
   if (!Config->ThinLTOCacheDir.empty())
     pruneCache(Config->ThinLTOCacheDir, Config->ThinLTOCachePolicy);
 
-  std::vector<InputFile *> Ret;
-  for (unsigned I = 0; I != MaxTasks; ++I) {
-    if (Buf[I].empty())
-      continue;
-    if (Config->SaveTemps) {
-      if (I == 0)
-        saveBuffer(Buf[I], Config->OutputFile + ".lto.o");
-      else
-        saveBuffer(Buf[I], Config->OutputFile + Twine(I) + ".lto.o");
-    }
-    InputFile *Obj = createObjectFile(MemoryBufferRef(Buf[I], "lto.tmp"));
-    Ret.push_back(Obj);
+  if (!Config->LTOObjPath.empty()) {
+    saveBuffer(Buf[0], Config->LTOObjPath);
+    for (unsigned I = 1; I != MaxTasks; ++I)
+      saveBuffer(Buf[I], Config->LTOObjPath + Twine(I));
+  }
+
+  if (Config->SaveTemps) {
+    saveBuffer(Buf[0], Config->OutputFile + ".lto.o");
+    for (unsigned I = 1; I != MaxTasks; ++I)
+      saveBuffer(Buf[I], Config->OutputFile + Twine(I) + ".lto.o");
   }
 
+  std::vector<InputFile *> Ret;
+  for (unsigned I = 0; I != MaxTasks; ++I)
+    if (!Buf[I].empty())
+      Ret.push_back(createObjectFile(MemoryBufferRef(Buf[I], "lto.tmp")));
+
   for (std::unique_ptr<MemoryBuffer> &File : Files)
     if (File)
       Ret.push_back(createObjectFile(*File));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56046.180332.patch
Type: text/x-patch
Size: 2841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190104/5d5ad280/attachment.bin>


More information about the llvm-commits mailing list