-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Rename target.abi to target.cfg_abi and enum-ify llvm_abiname
#153857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RalfJung
wants to merge
4
commits into
rust-lang:main
Choose a base branch
from
RalfJung:cfg-abi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+843
−492
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c4fb58f
target specs: tighten checks for llvm_abiname and llvm_floatabi, and …
RalfJung 2662303
mips: require LLVM ABI to be explicitly set, but also allow n32
RalfJung 3acf328
target specs: rename abi to cfg_abi
RalfJung 1e14fb1
enum-ify llvm_abiname
RalfJung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ use rustc_metadata::fs::METADATA_FILENAME; | |
| use rustc_middle::bug; | ||
| use rustc_session::Session; | ||
| use rustc_span::sym; | ||
| use rustc_target::spec::{Abi, Os, RelocModel, Target, ef_avr_arch}; | ||
| use rustc_target::spec::{CfgAbi, LlvmAbi, Os, RelocModel, Target, ef_avr_arch}; | ||
| use tracing::debug; | ||
|
|
||
| use super::apple; | ||
|
|
@@ -294,18 +294,13 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { | |
| _ => elf::EF_MIPS_ARCH_64R2, | ||
| }; | ||
|
|
||
| // If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS, | ||
| // which is the only "true" 32-bit option that LLVM supports. | ||
| match sess.target.options.llvm_abiname.as_ref() { | ||
| "o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32, | ||
| "n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2, | ||
| "n64" if !is_32bit => {} | ||
| "" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32, | ||
| "" => sess.dcx().fatal("LLVM ABI must be specified for 64-bit MIPS targets"), | ||
| s if is_32bit => { | ||
| sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 32-bit MIPS target", s)) | ||
| } | ||
| s => sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 64-bit MIPS target", s)), | ||
| // Use the explicitly given ABI. | ||
| match &sess.target.options.llvm_abiname { | ||
| LlvmAbi::O32 if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32, | ||
| LlvmAbi::N32 if !is_32bit => e_flags |= elf::EF_MIPS_ABI2, | ||
| LlvmAbi::N64 if !is_32bit => {} | ||
| // The rest is invalid (which is already ensured by the target spec check). | ||
| s => bug!("invalid LLVM ABI `{}` for MIPS target", s), | ||
| }; | ||
|
|
||
| if sess.target.options.relocation_model != RelocModel::Static { | ||
|
|
@@ -341,12 +336,12 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { | |
|
|
||
| // Set the appropriate flag based on ABI | ||
| // This needs to match LLVM `RISCVELFStreamer.cpp` | ||
| match &*sess.target.llvm_abiname { | ||
| "ilp32" | "lp64" => (), | ||
| "ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE, | ||
| "ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE, | ||
| match &sess.target.llvm_abiname { | ||
| LlvmAbi::Ilp32 | LlvmAbi::Lp64 => (), | ||
| LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE, | ||
| LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE, | ||
| // Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI. | ||
| "ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE, | ||
| LlvmAbi::Ilp32e | LlvmAbi::Lp64e => e_flags |= elf::EF_RISCV_RVE, | ||
| _ => bug!("unknown RISC-V ABI name"), | ||
| } | ||
|
|
||
|
|
@@ -358,10 +353,10 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { | |
|
|
||
| // Set the appropriate flag based on ABI | ||
| // This needs to match LLVM `LoongArchELFStreamer.cpp` | ||
| match &*sess.target.llvm_abiname { | ||
| "ilp32s" | "lp64s" => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT, | ||
| "ilp32f" | "lp64f" => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT, | ||
| "ilp32d" | "lp64d" => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT, | ||
| match &sess.target.llvm_abiname { | ||
| LlvmAbi::Ilp32s | LlvmAbi::Lp64s => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT, | ||
| LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT, | ||
| LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT, | ||
| _ => bug!("unknown LoongArch ABI name"), | ||
| } | ||
|
|
||
|
|
@@ -377,7 +372,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { | |
| } | ||
| } | ||
| Architecture::Csky => { | ||
| if matches!(sess.target.options.abi, Abi::AbiV2) { | ||
| if matches!(sess.target.options.cfg_abi, CfgAbi::AbiV2) { | ||
| elf::EF_CSKY_ABIV2 | ||
| } else { | ||
| elf::EF_CSKY_ABIV1 | ||
|
|
@@ -388,14 +383,14 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { | |
| const EF_PPC64_ABI_ELF_V1: u32 = 1; | ||
| const EF_PPC64_ABI_ELF_V2: u32 = 2; | ||
|
|
||
| match sess.target.options.llvm_abiname.as_ref() { | ||
| match sess.target.options.llvm_abiname { | ||
| // If the flags do not correctly indicate the ABI, | ||
| // linkers such as ld.lld assume that the ppc64 object files are always ELFv2 | ||
| // which leads to broken binaries if ELFv1 is used for the object files. | ||
| "elfv1" => EF_PPC64_ABI_ELF_V1, | ||
| "elfv2" => EF_PPC64_ABI_ELF_V2, | ||
| "" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => { | ||
| bug!("No ABI specified for this PPC64 ELF target"); | ||
| LlvmAbi::ElfV1 => EF_PPC64_ABI_ELF_V1, | ||
| LlvmAbi::ElfV2 => EF_PPC64_ABI_ELF_V2, | ||
| _ if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ElfV1 and ElfV2 are the only allowed ABI names here so we can error on everything else. |
||
| bug!("invalid ABI specified for this PPC64 ELF target"); | ||
| } | ||
| // Fall back | ||
| _ => EF_PPC64_ABI_UNKNOWN, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We force all riscv targets to set an ABI so no check for an empty ABI name is needed here.