Skip to content

Dynamic library generates functions with no meaningful assembly.  #125299

Closed
@pirocks

Description

@pirocks

I tried this code(compiling in release mode):

use std::mem::transmute;

#[no_mangle]
pub unsafe extern "system" fn foo_bar_baz(ptr: i64) -> i8 {
    let ptr: *mut i8 = transmute(ptr);
    ptr.read()
}

in with the following Cargo.toml:

[package]
name = "repro_dynamic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]

I expected to see this happen:
I expected a dynamic executable with a function labelled foo_bar_baz in it.

Instead, this happened:

I get a label for the function foo_bar_baz, but it is an undefined instruction only. On older rust versions I get the expected assembly.

I have a much larger project which is affected by this, and it seems to be broadly the same, affects many no_mangle unsafe extern functions(but not all such functions, not really clear as to what the deciding factor is but probably has something to do with function body).

$ objdump -D target/release/librepro_dynamic.so | grep -C 25 foo_bar_baz
00000000000126c0 <frame_dummy>:
   126c0:       f3 0f 1e fa             endbr64 
   126c4:       e9 77 ff ff ff          jmp    12640 <register_tm_clones>
   126c9:       cc                      int3   
   126ca:       cc                      int3   
   126cb:       cc                      int3   
   126cc:       cc                      int3   
   126cd:       cc                      int3   
   126ce:       cc                      int3   
   126cf:       cc                      int3   

00000000000126d0 <foo_bar_baz>:
   126d0:       0f 0b                   ud2    
   126d2:       cc                      int3   
   126d3:       cc                      int3   
   126d4:       cc                      int3   
   126d5:       cc                      int3   
   126d6:       cc                      int3   
   126d7:       cc                      int3   
   126d8:       cc                      int3   
   126d9:       cc                      int3   
   126da:       cc                      int3   
   126db:       cc                      int3   
   126dc:       cc                      int3   
   126dd:       cc                      int3   
   126de:       cc                      int3   
   126df:       cc                      int3   

00000000000126e0 <__rust_alloc>:
   126e0:       e9 bb 9b 01 00          jmp    2c2a0 <__rdl_alloc>
   126e5:       cc                      int3   
   126e6:       cc                      int3   
   126e7:       cc                      int3   
   126e8:       cc                      int3   
   126e9:       cc                      int3   

Meta

Repros in latest stable and nightly. cargo-rustc-bisect says:

Regression in 317d14a56cb8c748bf0e2f2afff89c2249ab4423

rustc --version --verbose:

francis@francis-desktop::~/RustroverProjects/repro$ rustc --version --verbose
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Edit:
Clarified that I was compiling in release mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions