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

Passing function argument to new inline asm causes link-time errors #72484

Closed
roblabla opened this issue May 23, 2020 · 0 comments · Fixed by #72521
Closed

Passing function argument to new inline asm causes link-time errors #72484

roblabla opened this issue May 23, 2020 · 0 comments · Fixed by #72521
Assignees
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@roblabla
Copy link
Contributor

#![feature(asm)]
fn main() {
    unsafe { asm!("call {}", sym test); }
}
extern fn test() {}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4c66087def8876f1661239ca3b06c976

I expected to see this happen: Compiles and runs properly.

Instead, this happened:

Compiling playground v0.0.1 (/playground)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/playground/target/debug/deps/playground-61e6f3655c9a6266.playground.emtqmcym-cgu.0.rcgu.o" "-o" "/playground/target/debug/deps/playground-61e6f3655c9a6266" "/playground/target/debug/deps/playground-61e6f3655c9a6266.5cim9a2phvmas1o7.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/playground/target/debug/deps" "-L" "/playground/target/debug/build/backtrace-sys-2c2318cf76eaa6fb/out" "-L" "/playground/target/debug/build/libsqlite3-sys-9220e77262ec64eb/out" "-L" "/playground/target/debug/build/ring-4d36d8941c8a810b/out" "-L" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-265ff16c7b6b86f9.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e1b9e36b805e60e6.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-cad809dd31a6a599.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8df8fedea90a4f43.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-80ea260fe87a3015.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-07193842d2b8653a.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-455fbbd57f0ec4a9.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-af3c39aa14f4a8e2.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-d9a2bda701b5264b.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ac41f78688451395.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-0465b718f70412d8.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-428d15b56101bdc7.rlib" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-941f7f6bc622e313.rlib" "-Wl,--end-group" "/playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-a1755b3e88842f5d.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
  = note: /playground/target/debug/deps/playground-61e6f3655c9a6266.playground.emtqmcym-cgu.0.rcgu.o: In function `playground::main':
          /playground/src/main.rs:3: undefined reference to `playground::test'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

Meta

rustc --version --verbose: 1.45.0-nightly (2020-05-21 9310e3b)

@roblabla roblabla added the C-bug Category: This is a bug. label May 23, 2020
@Amanieu Amanieu added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) labels May 23, 2020
@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 23, 2020
@Amanieu Amanieu self-assigned this May 23, 2020
RalfJung added a commit to RalfJung/rust that referenced this issue May 30, 2020
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items

Fixes rust-lang#72484
@bors bors closed this as completed in 3ed1e79 May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants