From 21625e573036b6af90e71046d817fd7c74fa1f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jun 2022 00:16:00 +0200 Subject: [PATCH] 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 --- Cargo.lock | 15 ++++++++++++++- compiler/rustc_codegen_ssa/Cargo.toml | 2 +- compiler/rustc_codegen_ssa/src/back/metadata.rs | 10 +++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c066d1b0a5b..35819572fb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,6 +1688,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" dependencies = [ + "ahash", "compiler_builtins", "rustc-std-workspace-alloc", "rustc-std-workspace-core", @@ -2539,6 +2540,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "crc32fast", + "hashbrown 0.12.0", + "indexmap", + "memchr", +] + [[package]] name = "odht" version = "0.3.1" @@ -3664,7 +3677,7 @@ dependencies = [ "itertools", "jobserver", "libc", - "object 0.28.4", + "object 0.29.0", "pathdiff", "regex", "rustc_apfloat", diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index 93b10a07e44..8a3464286a4 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -41,6 +41,6 @@ rustc_target = { path = "../rustc_target" } rustc_session = { path = "../rustc_session" } [dependencies.object] -version = "0.28.4" +version = "0.29.0" default-features = false features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"] diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 4c330c5906a..3dd607adee5 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -171,7 +171,15 @@ pub(crate) fn create_object_file(sess: &Session) -> Option 0, }; - file.flags = FileFlags::Elf { e_flags }; + // adapted from LLVM's `MCELFObjectTargetWriter::getOSABI` + let os_abi = match sess.target.options.os.as_ref() { + "hermit" => elf::ELFOSABI_STANDALONE, + "freebsd" => elf::ELFOSABI_FREEBSD, + "solaris" => elf::ELFOSABI_SOLARIS, + _ => elf::ELFOSABI_NONE, + }; + let abi_version = 0; + file.flags = FileFlags::Elf { os_abi, abi_version, e_flags }; Some(file) }