In #190876 we now have functions in ValueAsMetadata (!inline_history metadata). This has caused undefined symbol linker errors in some ThinLTO builds. The following is what's going on: @f in module A is getting imported from module A to module B, and it has a call with !inline_history pointing to @g in module A, so a declaration for @g is also imported into module B. But @g gets internalized in module A, causing the undefined symbol error at link time due to memprof's ICP in module B creating a call to @g since we can ICP a call to any declaration. To avoid pulling in a function declaration that may be wrong, simply drop !inline_history metadata when importing functions. They aren't necessary for correctness, they only prevent inlining explosion in some recursive edge cases. Worst case is we do another round of inlining through mutually recursive functions and then stop again due to newly added !inline_history metadata, which should be fine; the inlining explosion typically happens because we keep inlining through mutually recursive functions.
22 lines
812 B
LLVM
22 lines
812 B
LLVM
; Test to ensure that we don't import !inline_history metadata on calls since
|
|
; doing so may end up importing other function declarations in a way that isn't
|
|
; tracked by ThinLTO, breaking IR semantics.
|
|
|
|
; RUN: opt -module-summary %s -o %t.bc
|
|
; RUN: opt -module-summary %p/Inputs/inline-history.ll -o %t2.bc
|
|
; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
|
|
; RUN: opt -passes=function-import -summary-file %t3.thinlto.bc %t.bc -S | FileCheck %s --implicit-check-not=inline_history
|
|
|
|
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 @caller() {
|
|
call void @imported_func()
|
|
ret void
|
|
}
|
|
|
|
declare void @imported_func()
|
|
|
|
; CHECK: define available_externally void @imported_func()
|
|
; CHECK-NEXT: call void @another_func()
|