Skip to content

Commit 0af99c9

Browse files
authored
Rollup merge of #97633 - mkroening:object-osabi, r=petrochenkov
Session object: Set OS/ABI Closes #97535. This depends on * gimli-rs/object#438 This adapts LLVM's behavior of [`MCELFObjectTargetWriter::getOSABI`](https://github.com/llvm/llvm-project/blob/8c8a2679a20f621994fa904bcfc68775e7345edc/llvm/include/llvm/MC/MCELFObjectWriter.h#L72-L86).
2 parents 2c6feb5 + 21625e5 commit 0af99c9

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

Cargo.lock

+14-1
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ version = "0.12.0"
17131713
source = "registry+https://github.com/rust-lang/crates.io-index"
17141714
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
17151715
dependencies = [
1716+
"ahash",
17161717
"compiler_builtins",
17171718
"rustc-std-workspace-alloc",
17181719
"rustc-std-workspace-core",
@@ -2571,6 +2572,18 @@ dependencies = [
25712572
"memchr",
25722573
]
25732574

2575+
[[package]]
2576+
name = "object"
2577+
version = "0.29.0"
2578+
source = "registry+https://github.com/rust-lang/crates.io-index"
2579+
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
2580+
dependencies = [
2581+
"crc32fast",
2582+
"hashbrown 0.12.0",
2583+
"indexmap",
2584+
"memchr",
2585+
]
2586+
25742587
[[package]]
25752588
name = "odht"
25762589
version = "0.3.1"
@@ -3720,7 +3733,7 @@ dependencies = [
37203733
"itertools",
37213734
"jobserver",
37223735
"libc",
3723-
"object 0.28.4",
3736+
"object 0.29.0",
37243737
"pathdiff",
37253738
"regex",
37263739
"rustc_apfloat",

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ rustc_target = { path = "../rustc_target" }
4242
rustc_session = { path = "../rustc_session" }
4343

4444
[dependencies.object]
45-
version = "0.28.4"
45+
version = "0.29.0"
4646
default-features = false
4747
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"]

compiler/rustc_codegen_ssa/src/back/metadata.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
130130
};
131131

132132
let mut file = write::Object::new(binary_format, architecture, endianness);
133-
match architecture {
133+
let e_flags = match architecture {
134134
Architecture::Mips => {
135135
let arch = match sess.target.options.cpu.as_ref() {
136136
"mips1" => elf::EF_MIPS_ARCH_1,
@@ -149,7 +149,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
149149
if sess.target.options.cpu.contains("r6") {
150150
e_flags |= elf::EF_MIPS_NAN2008;
151151
}
152-
file.flags = FileFlags::Elf { e_flags };
152+
e_flags
153153
}
154154
Architecture::Mips64 => {
155155
// copied from `mips64el-linux-gnuabi64-gcc foo.c -c`
@@ -160,17 +160,26 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
160160
} else {
161161
elf::EF_MIPS_ARCH_64R2
162162
};
163-
file.flags = FileFlags::Elf { e_flags };
163+
e_flags
164164
}
165165
Architecture::Riscv64 if sess.target.options.features.contains("+d") => {
166166
// copied from `riscv64-linux-gnu-gcc foo.c -c`, note though
167167
// that the `+d` target feature represents whether the double
168168
// float abi is enabled.
169169
let e_flags = elf::EF_RISCV_RVC | elf::EF_RISCV_FLOAT_ABI_DOUBLE;
170-
file.flags = FileFlags::Elf { e_flags };
170+
e_flags
171171
}
172-
_ => {}
172+
_ => 0,
173+
};
174+
// adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`
175+
let os_abi = match sess.target.options.os.as_ref() {
176+
"hermit" => elf::ELFOSABI_STANDALONE,
177+
"freebsd" => elf::ELFOSABI_FREEBSD,
178+
"solaris" => elf::ELFOSABI_SOLARIS,
179+
_ => elf::ELFOSABI_NONE,
173180
};
181+
let abi_version = 0;
182+
file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
174183
Some(file)
175184
}
176185

0 commit comments

Comments
 (0)