Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extern_weak linkage on definition not rejected #137627

Open
matthiaskrgr opened this issue Feb 25, 2025 · 2 comments
Open

extern_weak linkage on definition not rejected #137627

matthiaskrgr opened this issue Feb 25, 2025 · 2 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. F-linkage #![feature(linkage)]` I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:

#![feature(linkage)]
#![crate_type = "rlib"]

#[linkage = "extern_weak"]
pub static EXTERN: u32 = 42;

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (617aad8c2 2025-02-24)
binary: rustc
commit-hash: 617aad8c2e8783f6df8e5d1f8bb1e4bcdc70aa7b
commit-date: 2025-02-24
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Backtrace

error: rustc interrupted by SIGILL, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x37010df) [0x7cb3fc7010df]
/usr/lib/libc.so.6(+0x3dcd0) [0x7cb3f8e4bcd0]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.20.1-rust-1.87.0-nightly(+0x8bd2096) [0x7cb3f7dd2096]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.20.1-rust-1.87.0-nightly(_ZN4llvm10AsmPrinter18emitGlobalVariableEPKNS_14GlobalVariableE+0x35a) [0x7cb3f70e40da]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.20.1-rust-1.87.0-nightly(_ZN4llvm10AsmPrinter14doFinalizationERNS_6ModuleE+0x219) [0x7cb3f70e546d]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.20.1-rust-1.87.0-nightly(_ZN4llvm13FPPassManager14doFinalizationERNS_6ModuleE+0x2a) [0x7cb3f702a2ea]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.20.1-rust-1.87.0-nightly(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x3ff) [0x7cb3f7634493]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bb8b82) [0x7cb3febb8b82]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bb86e1) [0x7cb3febb86e1]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bb5e33) [0x7cb3febb5e33]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bb5ae8) [0x7cb3febb5ae8]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(_RINvNtNtCs5JDsLVAy2fO_3std3sys9backtrace28___rust_begin_short_backtraceNCINvXs0_Cs2p9PGD2gg2l_18rustc_codegen_llvmNtB1g_18LlvmCodegenBackendNtNtNtCsjc85tVovh2m_17rustc_codegen_ssa6traits7backend19ExtraBackendMethods18spawn_named_threadNCINvNtNtB2k_4back5write10spawn_workB1O_E0uE0uEB1g_+0x2eb) [0x7cb3febb452b]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bad822) [0x7cb3febad822]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-19054624313a00ee.so(+0x5bad2ab) [0x7cb3febad2ab]
/usr/lib/libc.so.6(+0x9570a) [0x7cb3f8ea370a]
/usr/lib/libc.so.6(+0x119aac) [0x7cb3f8f27aac]

note: we would appreciate a report at https://github.com/rust-lang/rust
[1]    4158672 illegal hardware instruction  RUST_BACKTRACE=full rustc a.rs

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Feb 25, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@matthiaskrgr matthiaskrgr added A-linkage Area: linking into static, shared libraries and binaries I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-linkage #![feature(linkage)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 25, 2025
@matthiaskrgr
Copy link
Member Author

llvm bitcode

; ModuleID = 'a.c51f459b1bd73179-cgu.0'
source_filename = "a.c51f459b1bd73179-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZN1a6EXTERN17h4f3857837f588658E = extern_weak constant <{ [4 x i8] }> <{ [4 x i8] c"*\00\00\00" }>, align 4

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"RtLibUseGOT", i32 1}
!2 = !{!"rustc version 1.87.0-nightly (617aad8c2 2025-02-24)"}

@nikic nikic changed the title LLVM sigkill extern_weak linkage on definition not rejected Feb 25, 2025
@nikic
Copy link
Contributor

nikic commented Feb 25, 2025

extern_weak linkage is only legal on extern declarations (duh). The global cannot have an initializer.

This is very similar to #109681, in that Rust currently does not verify #[linkage] validity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. F-linkage #![feature(linkage)]` I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

3 participants