[PATCH] D96931: [LTO] Discard non-prevailing defined symbols in module-level assembly
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 9 11:32:01 PST 2021
MaskRay added a subscriber: nickdesaulniers.
MaskRay added a comment.
The regular LTO precodegen bitcode file `%to1.0.5.precodegen.bc` is
module asm ".weak foo"
module asm "\09 .equ foo,bar"
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (i32)* @bar to i8*)], section "llvm.metadata"
; Function Attrs: norecurse nounwind readnone willreturn
define dso_local i32 @foo(i32 %0) local_unnamed_addr #0 {
%2 = add nsw i32 %0, 2
ret i32 %2
}
; Function Attrs: norecurse nounwind readnone willreturn
define internal i32 @bar(i32 %0) #0 {
%2 = add nsw i32 %0, 1
ret i32 %2
}
The module-level inline asm is emitted before the functions. The call tree is roughly:
AsmPrinter::doInitialization
emitInlineAsm (AsmPrinter.cpp:319)
(void)Parser->Run(/*NoInitialTextSection*/ true, (AsmPrinterInlineAsm.cpp:124)
...
MCELFStreamer::emitSymbolAttribute (set binding to STB_WEAK)
AsmPrinter::emitFunctionBody
AsmPrinter::emitFunctionHeader
AsmPrinter::emitLinkage
MCELFStreamer::emitSymbolAttribute (`error: ... changed binding to STB_GLOBAL`)
A more elegant solution is to let the `MCELFStreamer` ignore non-prevailing definitions during `emitInlineAsm`.
If that is complex to implement, @pcc having this short-term solution may be useful depending on how urgent @nickdesaulniers wants https://github.com/ClangBuiltLinux/linux/issues/1269 to be fixed.
In https://github.com/ClangBuiltLinux/linux/issues/1269#issuecomment-786963047 , @nickdesaulniers mentioned the binding can change from STB_GLOBAL to STB_WEAK, then STB_WEAK to STB_GLOBAL.
I am curious how that can happen:
LTO vmlinux.o
__ia32_compat_sys_sysctl: binding: 1
__ia32_compat_sys_sysctl: binding: 2
__ia32_compat_sys_sysctl: binding: 2
<unknown>:0: error: __ia32_compat_sys_sysctl changed binding to STB_GLOBAL
__ia32_compat_sys_sysctl: binding: 1
LLVM ERROR: Error parsing inline asm
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96931/new/
https://reviews.llvm.org/D96931
More information about the llvm-commits
mailing list