Skip to content

Commit 9e6d2da

Browse files
committed
Reduce dependence on the target name
The target name can be anything with custom target specs. Matching on fields inside the target spec is much more robust than matching on the target name.
1 parent 7028d93 commit 9e6d2da

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

compiler/rustc_codegen_gcc/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
146146

147147
// Wasm statics with custom link sections get special treatment as they
148148
// go into custom sections of the wasm executable.
149-
if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") {
149+
if self.tcx.sess.target.is_like_wasm {
150150
if let Some(_section) = attrs.link_section {
151151
unimplemented!();
152152
}

compiler/rustc_codegen_llvm/src/back/write.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -945,23 +945,10 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
945945
asm
946946
}
947947

948-
fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
949-
let triple = cgcx.opts.target_triple.tuple();
950-
triple.contains("-ios")
951-
|| triple.contains("-darwin")
952-
|| triple.contains("-tvos")
953-
|| triple.contains("-watchos")
954-
|| triple.contains("-visionos")
955-
}
956-
957-
fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
958-
cgcx.opts.target_triple.tuple().contains("-aix")
959-
}
960-
961948
pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr {
962-
if target_is_apple(cgcx) {
949+
if cgcx.target_is_like_osx {
963950
c"__LLVM,__bitcode"
964-
} else if target_is_aix(cgcx) {
951+
} else if cgcx.target_is_like_aix {
965952
c".ipa"
966953
} else {
967954
c".llvmbc"
@@ -1028,10 +1015,12 @@ unsafe fn embed_bitcode(
10281015
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
10291016
// and COFF we emit the sections using module level inline assembly for that
10301017
// reason (see issue #90326 for historical background).
1031-
let is_aix = target_is_aix(cgcx);
1032-
let is_apple = target_is_apple(cgcx);
10331018
unsafe {
1034-
if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") {
1019+
if cgcx.target_is_like_osx
1020+
|| cgcx.target_is_like_aix
1021+
|| cgcx.target_arch == "wasm32"
1022+
|| cgcx.target_arch == "wasm64"
1023+
{
10351024
// We don't need custom section flags, create LLVM globals.
10361025
let llconst = common::bytes_in_context(llcx, bitcode);
10371026
let llglobal = llvm::LLVMAddGlobal(
@@ -1052,9 +1041,9 @@ unsafe fn embed_bitcode(
10521041
c"rustc.embedded.cmdline".as_ptr(),
10531042
);
10541043
llvm::LLVMSetInitializer(llglobal, llconst);
1055-
let section = if is_apple {
1044+
let section = if cgcx.target_is_like_osx {
10561045
c"__LLVM,__cmdline"
1057-
} else if is_aix {
1046+
} else if cgcx.target_is_like_aix {
10581047
c".info"
10591048
} else {
10601049
c".llvmcmd"

compiler/rustc_codegen_ssa/src/back/link.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ pub fn link_binary(
8585
}
8686

8787
if invalid_output_for_target(sess, crate_type) {
88-
bug!(
89-
"invalid output type `{:?}` for target os `{}`",
90-
crate_type,
91-
sess.opts.target_triple
92-
);
88+
bug!("invalid output type `{:?}` for target `{}`", crate_type, sess.opts.target_triple);
9389
}
9490

9591
sess.time("link_binary_check_files_are_writeable", || {
@@ -996,6 +992,7 @@ fn link_natively(
996992
&& (code < 1000 || code > 9999)
997993
{
998994
let is_vs_installed = windows_registry::find_vs_version().is_ok();
995+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
999996
let has_linker = windows_registry::find_tool(
1000997
sess.opts.target_triple.tuple(),
1001998
"link.exe",

compiler/rustc_codegen_ssa/src/back/linker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) fn get_linker<'a>(
4747
self_contained: bool,
4848
target_cpu: &'a str,
4949
) -> Box<dyn Linker + 'a> {
50+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
5051
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");
5152

5253
// If our linker looks like a batch script on Windows then to execute this

compiler/rustc_codegen_ssa/src/back/write.rs

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ pub struct CodegenContext<B: WriteBackendMethods> {
345345
pub is_pe_coff: bool,
346346
pub target_can_use_split_dwarf: bool,
347347
pub target_arch: String,
348+
pub target_is_like_osx: bool,
349+
pub target_is_like_aix: bool,
348350
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
349351
pub split_dwarf_kind: rustc_session::config::SplitDwarfKind,
350352

@@ -1195,6 +1197,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
11951197
is_pe_coff: tcx.sess.target.is_like_windows,
11961198
target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(),
11971199
target_arch: tcx.sess.target.arch.to_string(),
1200+
target_is_like_osx: tcx.sess.target.is_like_osx,
1201+
target_is_like_aix: tcx.sess.target.is_like_aix,
11981202
split_debuginfo: tcx.sess.split_debuginfo(),
11991203
split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind,
12001204
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,

0 commit comments

Comments
 (0)