origin icon indicating copy to clipboard operation
origin copied to clipboard

`-nostartfiles` not found

Open DasLixou opened this issue 10 months ago • 12 comments

I'm doing something wrong but don't know what. I'm trying to replicate tiny-hello example but get this error:

error: linking with `rust-lld` failed: exit status: 1
  = note: rust-lld: error: unknown argument '-nostartfiles'

When I remove the

println!("cargo:rustc-link-arg=-nostartfiles");

from the build.rs, the resulting binary has no .text section at all.

I'm compiling with nightly and use origin = { version = "0.24.0", default-features = false, features = ["origin-start", "nightly"] }.

Thanks for your help :)

DasLixou avatar Feb 25 '25 18:02 DasLixou

What target are you using?

sunfishcode avatar Feb 25 '25 20:02 sunfishcode

x86_64-unknown-linux-none

DasLixou avatar Feb 25 '25 20:02 DasLixou

Origin currently assumes it's using the x86_64-unknown-linux-gnu target (and similar targets for other architectures). It disables the actual glibc implementation (that's what that -nostartfiles flag is for) and uses its own implementations.

In theory it should be possible to support the x86_64-unknown-linux-none target in origin; it just hasn't been done yet.

sunfishcode avatar Feb 25 '25 21:02 sunfishcode

Hmmm looking at the code for a bit, I don't understand why it didn't generate any code with the none Target and without the linker flag...

DasLixou avatar Feb 26 '25 21:02 DasLixou

I don't know.

sunfishcode avatar Feb 26 '25 22:02 sunfishcode

You could try adding -e _start as argument. Also check if there were any linker warnings. A rustc PR to show linker warnings by default was recently merged, so make sure you have a new enough nightly.

bjorn3 avatar Feb 26 '25 23:02 bjorn3

You could try adding -e _start as argument. Also check if there were any linker warnings. A rustc PR to show linker warnings by default was recently merged, so make sure you have a new enough nightly.

No linker errors, -e _start also sadly didn't help :c (yes, I updated and run the latest nightly from 02-26)

DasLixou avatar Feb 27 '25 17:02 DasLixou

Weird, even with cargo +nightly r --target x86_64-unknown-linux-gnu --release and -nostartfiles it doesn't generate any code in .text section...

DasLixou avatar Feb 27 '25 17:02 DasLixou

Okay, I tried everything and... found a solution! I don't know why it works or why it's needed, but the only thing I had to write is an explicit extern crate origin; at the top of the file.... can anybody explain this to me?

DasLixou avatar Feb 27 '25 17:02 DasLixou

And now my console gets flooded with errors of not found types for -none target

DasLixou avatar Feb 27 '25 18:02 DasLixou

I don't know why it works or why it's needed, but the only thing I had to write is an explicit extern crate origin; at the top of the file.... can anybody explain this to me?

Right, without extern crate origin;, use origin as _; or some other reference to origin in the source code, rustc will not load origin as dependency and thus not link it.

And now my console gets flooded with errors of not found types for -none target

You are building origin with the std feature disabled?

bjorn3 avatar Feb 27 '25 18:02 bjorn3

I suspect so, yeah. The errors seem to come from not knowing types without the gnu impl

DasLixou avatar Feb 27 '25 20:02 DasLixou