riscv: Fix ELF header flags
The previous version added both `EF_RISCV_FLOAT_ABI_DOUBLE` and `EF_RISCV_RVC` if the "D" extension was enabled on riscv64 targets. riscv32 targets were not accounted for. This patch changes this so that: - Only add `EF_RISCV_RVC` if the "C" extension is enabled - Add `EF_RISCV_FLOAT_ABI_SINGLE` if the "F" extension is enabled and the "D" extension is not - Add these ELF flags for riscv32 as well
This commit is contained in:
parent
a377893da2
commit
138a1d26b5
1 changed files with 17 additions and 5 deletions
|
@ -165,11 +165,23 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
|
||||||
};
|
};
|
||||||
e_flags
|
e_flags
|
||||||
}
|
}
|
||||||
Architecture::Riscv64 if sess.target.options.features.contains("+d") => {
|
Architecture::Riscv32 | Architecture::Riscv64 => {
|
||||||
// copied from `riscv64-linux-gnu-gcc foo.c -c`, note though
|
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
|
||||||
// that the `+d` target feature represents whether the double
|
let mut e_flags: u32 = 0x0;
|
||||||
// float abi is enabled.
|
let features = &sess.target.options.features;
|
||||||
let e_flags = elf::EF_RISCV_RVC | elf::EF_RISCV_FLOAT_ABI_DOUBLE;
|
// Check if compressed is enabled
|
||||||
|
if features.contains("+c") {
|
||||||
|
e_flags |= elf::EF_RISCV_RVC;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select the appropriate floating-point ABI
|
||||||
|
if features.contains("+d") {
|
||||||
|
e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE;
|
||||||
|
} else if features.contains("+f") {
|
||||||
|
e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE;
|
||||||
|
} else {
|
||||||
|
e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT;
|
||||||
|
}
|
||||||
e_flags
|
e_flags
|
||||||
}
|
}
|
||||||
_ => 0,
|
_ => 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue