-
Notifications
You must be signed in to change notification settings - Fork 451
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
Rework riscv -march and -mabi detection #796
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2361,29 +2361,42 @@ impl Build { | |
let mut parts = target.split('-'); | ||
if let Some(arch) = parts.next() { | ||
let arch = &arch[5..]; | ||
|
||
// Assume that "rv{arch}" is a valid RISC-V ISA string. | ||
// The compiler would error out otherwise, and we fix | ||
// that later. | ||
cmd.args.push(format!("-march=rv{arch}").into()); | ||
|
||
// Detect single-letter extensions from `arch`, assuming | ||
// no version numbers and canonical order | ||
let single_letter = arch | ||
.split(['_', 'z', 's']) | ||
.next() | ||
// The arch string starts with 32 or 64 | ||
.expect("arch string cannot be empty"); | ||
|
||
NobodyXu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let riscv_implements = |ext| single_letter.contains(ext); | ||
|
||
// Detect ABI to select based on de facto standard | ||
|
||
let float_abi = if riscv_implements("g") || riscv_implements("d") { | ||
// Implements "d" (double-float), use double-float ABI | ||
"d" | ||
} else if riscv_implements("f") { | ||
// Implements "f" (single-float), use single-float ABI | ||
"f" | ||
} else { | ||
// No floating support, use soft-float ABI | ||
"" | ||
}; | ||
|
||
if arch.starts_with("64") { | ||
if target.contains("linux") | ||
| target.contains("freebsd") | ||
| target.contains("netbsd") | ||
| target.contains("linux") | ||
{ | ||
cmd.args.push(("-march=rv64gc").into()); | ||
cmd.args.push("-mabi=lp64d".into()); | ||
} else { | ||
cmd.args.push(("-march=rv".to_owned() + arch).into()); | ||
cmd.args.push("-mabi=lp64".into()); | ||
} | ||
} else if arch.starts_with("32") { | ||
if target.contains("linux") { | ||
cmd.args.push(("-march=rv32gc").into()); | ||
cmd.args.push("-mabi=ilp32d".into()); | ||
} else { | ||
cmd.args.push(("-march=rv".to_owned() + arch).into()); | ||
cmd.args.push("-mabi=ilp32".into()); | ||
} | ||
cmd.args.push(format!("-mabi=lp64{float_abi}").into()); | ||
} else { | ||
cmd.args.push("-mcmodel=medany".into()); | ||
cmd.args.push(format!("-mabi=ilp32{float_abi}").into()); | ||
} | ||
|
||
cmd.args.push("-mcmodel=medany".into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag is pushed unconditionally now and it was conditional before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that there was no reason to make this conditional in the first place and everything uses |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm bit confused on this, I checked the riscv targets rust supported and doesn't find any z, s or underscore in after the prefix "riscv" .
What is this trying to detect?
Is there any new target which contains z, s or underscore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't know how else to address the fact that isa string parsing is "fragile" #796 (comment)
in case in the future we add extensions like
zsomething
the arch string could look likeriscv64imaczsomething
orriscv64imac_zsomething
and we don't want to match on theg
ofzsomething
i don't think there's any easy way to say how the rust project will decide to name future riscv architectures, but if you're okay with this being "fragile" i can remove this part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to chim in here, to give an idea about how for example the riscv-esp-elf-gcc sees target definitions, it looks something like the following:
this above is part of the output of
./riscv32-esp-elf-gcc -dumpspecs
and presumably it looks similar on other gcc based variants.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so it's non-standard rust target used in riscv-esp-elf-gcc?
If it is non-standard then it would indeed makes more sense to pass them as environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean by non-standard rust target, but our target descriptions are similar on how the other riscv targets on the rust site are being expressed.
But as dramforever mentions downstream gcc & clang is more complicated matter. Mapping to thouse means that there are possible different ISA versions that can be associated with. Rust target names in its current form lag that expressiveness if i see it correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider any target not in rustup or maintainer by the rust officially to be a non-standard one.
I heard of cargo plugins for esp and I think it sets the cflags and etc to work?
Would it makes sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it might make sense to summarize the situation:
riscv{32,64}
.f
means hardware f32,d
means hardware f64, andg
is abbreviation ofimafd
g
/d
orf
-mabi
is to use the "maximum" supported hard float ABIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have a crate to extract some riscv target information from nightly rust.
I wonder if we could get this from it as well?
https://github.com/rust-lang/cc-rs/blob/main/dev-tools/gen-target-info/src/main.rs