#Can only get "_start" to not mangle in #[no_std], #[no_main]

10 messages · Page 1 of 1 (latest)

buoyant furnace
#

Hey y'all,
I think the title pretty much says it all. I'm messing around with assembly and rust, trying to link them together, so so I of course used #[no_mangle] and pub extern "C" fn function_name in my [no_main], [no_std] file.
Problem is, when I run objdump -s target/debug/[et cetera], I get something like

SYMBOL TABLE:
0000000000000000 l    df *ABS*    0000000000000000 4op9q508u3e7bkoe```
which is unideal. 
Then I have an idea, and try to swap function_name over to "_start", and do the same thing, getting this:

SYMBOL TABLE:
0000000000000000 l df ABS 0000000000000000 4op9q508u3e7bkoe
0000000000201120 g F .text 0000000000000004 _start```
much more ideal.
But this is still a problem, because I need the assembly to be the "_start" (indeed it already has a _start symbol), so I can't actually use _start for rust.
So, does anyone know why this works the way it does, and what I can do to fix it?
Thanks

if it helps,

#![no_std]
#![no_main]
use core::panic::PanicInfo;

#[no_mangle]
#[export_name = "_start"]
pub extern "C" fn rust_main() -> ! {
    loop {}
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}``` this is my entire `src/main.rs` file
```json
{
    "llvm-target": "x86_64-unknown-none",
    "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
    "arch": "x86_64",
    "target-endian": "little",
    "target-pointer-width": "64",
    "target-c-int-width": "32",
    "os": "none",
    "executables": true,
    "linker-flavor": "ld.lld",
    "linker": "rust-lld",
    "panic-strategy": "abort",
    "disable-redzone": true,
    "features": "-mmx,-sse,+soft-float"
}``` this is my target
#

and this is my .cargo/config.toml:

[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "x86_64-target.json"
#

also I found out that I can just specify a different entry point with the linker, but I still want to figure out the why of why it's not working

faint iron
#

I'm not sure I understood your issue right

#

but

#

with toml [build] rustflags = ["-Z", "export-executable-symbols"] in .cargo/config.toml

#

I get some exported functions: ```
✗ readelf -Ws --dyn-syms target/x86_64-target/debug/h

Symbol table '.symtab' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS 4d4jz1pdfgfokkev
2: 0000000000201180 7 FUNC LOCAL HIDDEN 2 rust_begin_unwind
3: 0000000000200120 34 OBJECT LOCAL DEFAULT 1 rustc_debug_gdb_scripts_section
4: 0000000000201150 4 FUNC GLOBAL DEFAULT 2 _start
5: 0000000000201160 1 FUNC GLOBAL DEFAULT 2 function_name
6: 0000000000201170 1 FUNC GLOBAL DEFAULT 2 function_name2```

#

I'm assuming they get deleted at some point because it thinks it can never get there

#

what I wonder is if you link directly some asm file into the rust binary, it may not get deleted

#

but who knows