diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2579,6 +2579,7 @@ // // 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); @@ -2594,6 +2595,14 @@ if (skipLinkedOutput) return; + { + 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]); + } + } + // compileBitcodeFiles may have produced lto.tmp object files. After this, no // more file will be added. auto newObjectFiles = makeArrayRef(objectFiles).slice(numObjsBeforeLTO); diff --git a/lld/test/ELF/deplibs-lto.s b/lld/test/ELF/deplibs-lto.s new file mode 100644 --- /dev/null +++ b/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",@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" }