Skip to content

Commit 21625e5

Browse files
committed
Session object: Set OS/ABI
This adapts LLVM's behavior of MCELFObjectTargetWriter::getOSABI [1]. [1]: https://github.com/llvm/llvm-project/blob/8c8a2679a20f621994fa904bcfc68775e7345edc/llvm/include/llvm/MC/MCELFObjectWriter.h#L72-L86
1 parent f7d12b4 commit 21625e5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Cargo.lock

+14-1
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ version = "0.12.0"
16881688
source = "registry+https://github.com/rust-lang/crates.io-index"
16891689
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
16901690
dependencies = [
1691+
"ahash",
16911692
"compiler_builtins",
16921693
"rustc-std-workspace-alloc",
16931694
"rustc-std-workspace-core",
@@ -2539,6 +2540,18 @@ dependencies = [
25392540
"memchr",
25402541
]
25412542

2543+
[[package]]
2544+
name = "object"
2545+
version = "0.29.0"
2546+
source = "registry+https://github.com/rust-lang/crates.io-index"
2547+
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
2548+
dependencies = [
2549+
"crc32fast",
2550+
"hashbrown 0.12.0",
2551+
"indexmap",
2552+
"memchr",
2553+
]
2554+
25422555
[[package]]
25432556
name = "odht"
25442557
version = "0.3.1"
@@ -3664,7 +3677,7 @@ dependencies = [
36643677
"itertools",
36653678
"jobserver",
36663679
"libc",
3667-
"object 0.28.4",
3680+
"object 0.29.0",
36683681
"pathdiff",
36693682
"regex",
36703683
"rustc_apfloat",

compiler/rustc_codegen_ssa/Cargo.toml

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

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

compiler/rustc_codegen_ssa/src/back/metadata.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
171171
}
172172
_ => 0,
173173
};
174-
file.flags = FileFlags::Elf { e_flags };
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,
180+
};
181+
let abi_version = 0;
182+
file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
175183
Some(file)
176184
}
177185

0 commit comments

Comments
 (0)