riscv: Fix ELF header flags · rust-lang/rust@138a1d2 (original) (raw)
File tree
1 file changed
lines changed
- compiler/rustc_codegen_ssa/src/back
1 file changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -165,11 +165,23 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static | ||
165 | 165 | }; |
166 | 166 | e_flags |
167 | 167 | } |
168 | -Architecture::Riscv64 if sess.target.options.features.contains("+d") => { | |
169 | -// copied from `riscv64-linux-gnu-gcc foo.c -c`, note though | |
170 | -// that the `+d` target feature represents whether the double | |
171 | -// float abi is enabled. | |
172 | -let e_flags = elf::EF_RISCV_RVC | elf::EF_RISCV_FLOAT_ABI_DOUBLE; | |
168 | +Architecture::Riscv32 | Architecture::Riscv64 => { | |
169 | +// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc | |
170 | +let mut e_flags: u32 = 0x0; | |
171 | +let features = &sess.target.options.features; | |
172 | +// Check if compressed is enabled | |
173 | +if features.contains("+c") { | |
174 | + e_flags |= elf::EF_RISCV_RVC; | |
175 | +} | |
176 | + | |
177 | +// Select the appropriate floating-point ABI | |
178 | +if features.contains("+d") { | |
179 | + e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE; | |
180 | +} else if features.contains("+f") { | |
181 | + e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE; | |
182 | +} else { | |
183 | + e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT; | |
184 | +} | |
173 | 185 | e_flags |
174 | 186 | } |
175 | 187 | _ => 0, |