[PATCH] D127885: [LTO] Parse input files added after LTO codegen.

Daniel Thornburgh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 16:17:49 PDT 2022


mysterymath created this revision.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
Herald added a subscriber: StephenFan.
mysterymath updated this revision to Diff 437362.
mysterymath added a comment.
Herald added subscribers: ormris, steven_wu, hiraditya.
mysterymath updated this revision to Diff 437364.
mysterymath updated this revision to Diff 437387.
mysterymath updated this revision to Diff 437389.
mysterymath updated this revision to Diff 437392.
mysterymath updated this revision to Diff 437393.
mysterymath retitled this revision from "Candidate fix." to "[LTO] Parse input files added after LTO codegen.".
mysterymath edited the summary of this revision.
mysterymath added reviewers: phosek, mcgrathr.
Herald added a subscriber: inglorion.
mysterymath published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add test case.


mysterymath added a comment.

Fix requires.


mysterymath added a comment.

Add comment.


mysterymath added a comment.

Move parse loop earlier.


mysterymath added a comment.

Update description.


mysterymath added a comment.

Expand the summary.


LTO codegen can add symbol references resolved by object files with
.deplibs sections. These object files will be added to the link by
symbol resolution, but parseFile() will never be called on the object
file, so the .deplibs will never be resolved. This can lead to undefined
references.

This change adds a second round of parseFile() calls to handle any input
files added to the link after LTO codegen. This resolves the .deplibs
sections mentioned above, as well as any further input files this adds
to the link.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127885

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/deplibs-lto.s


Index: lld/test/ELF/deplibs-lto.s
===================================================================
--- /dev/null
+++ lld/test/ELF/deplibs-lto.s
@@ -0,0 +1,42 @@
+# REQUIRES: aarch64
+
+# RUN: rm -rf %t.inputs %t.dir
+# RUN: mkdir -p %t.inputs %t.dir
+# RUN: split-file %s %t.inputs
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %t.inputs/deplibs.s -o %tdeplibs.o
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %t.inputs/foo.s -o %tfoo.o
+# RUN: llvm-as %t.inputs/lto.ll -o %t.o
+# RUN: llvm-ar rc %t.dir/libdeplibs.a %tdeplibs.o
+# RUN: llvm-ar rc %t.dir/libfoo.a %tfoo.o
+
+# LTO can emit libcalls that are resolved using libraries that contain .deplibs.
+# Such libraries must be handled as if they were input files, and any referenced
+# deplibs must be added to the link. Otherwise, symbols in the library may go
+# undefined.
+
+# RUN: ld.lld %t.o -u a -o /dev/null -L %t.dir -ldeplibs --trace 2>&1 | \
+# RUN:   FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=LIBA-DIR
+
+# LIBA-DIR:      [[OBJ]]
+# LIBA-DIR-NEXT: [[DIR]]{{[\\/]}}libdeplibs.a
+# LIBA-DIR-NEXT: [[DIR]]{{[\\/]}}libfoo.a
+
+#--- foo.s
+.global foo
+foo:
+#--- deplibs.s
+.global __aarch64_ldadd4_relax
+__aarch64_ldadd4_relax:
+    b foo
+.section ".deplibs","MS", at llvm_dependent_libraries,1
+    .asciz "foo"
+#--- lto.ll
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64"
+
+define void @a(i32* nocapture %0) #0 {
+  %2 = atomicrmw add i32* %0, i32 1 monotonic, align 4
+  ret void
+}
+
+attributes #0 = { "target-features"="+outline-atomics" }
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -2579,9 +2579,21 @@
   //
   // With this the symbol table should be complete. After this, no new names
   // except a few linker-synthesized ones will be added to the symbol table.
+  const size_t numFilesBeforeLTO = files.size();
   const size_t numObjsBeforeLTO = objectFiles.size();
   invokeELFT(compileBitcodeFiles, skipLinkedOutput);
 
+  // Adding the LTO object file to the link may have added additional input
+  // files to the link, e.g. if a builtin libcall was resolved using an object
+  // file with deplibs.
+  {
+    llvm::TimeTraceScope timeScope("Parse input files");
+    for (size_t i = numFilesBeforeLTO; i < files.size(); ++i) {
+      llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
+      parseFile(files[i]);
+    }
+  }
+
   // Symbol resolution finished. Report backward reference problems,
   // --print-archive-stats=, and --why-extract=.
   reportBackrefs();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127885.437393.patch
Type: text/x-patch
Size: 2636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/e402fee0/attachment-0001.bin>


More information about the llvm-commits mailing list