From 9c776cfa42fb384671272c39fd5d7dbb946780d4 Mon Sep 17 00:00:00 2001 From: Matt Schulte Date: Tue, 17 Sep 2024 14:15:14 -0700 Subject: [PATCH] disable pic for targets that end in `-none` This fixes #1211 --- src/lib.rs | 1 + tests/test.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e96382868..2a7e3a11f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1983,6 +1983,7 @@ impl Build { if self.pic.unwrap_or( !target.contains("windows") && !target.contains("-none-") + && !target.ends_with("-none") && !target.contains("uefi"), ) { cmd.push_cc_arg("-fPIC".into()); diff --git a/tests/test.rs b/tests/test.rs index 5f31f3eb7..9d5ce508e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -269,6 +269,20 @@ fn gnu_x86_64_no_plt() { test.cmd(0).must_have("-fno-plt"); } +#[test] +fn gnu_aarch64_none_no_pic() { + for target in &["aarch64-unknown-none-gnu", "aarch64-unknown-none"] { + let test = Test::gnu(); + test.gcc() + .target(&target) + .host(&target) + .file("foo.c") + .compile("foo"); + + test.cmd(0).must_not_have("-fPIC"); + } +} + #[test] fn gnu_set_stdlib() { reset_env();