1 |
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs |
2 |
index 638b2a7b5a9f..79d4ecf4cb91 100644 |
3 |
--- a/compiler/rustc_codegen_ssa/src/back/link.rs |
4 |
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs |
5 |
@@ -763,7 +763,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( |
6 |
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie") |
7 |
{ |
8 |
info!("linker output: {:?}", out); |
9 |
- warn!("Linker does not support -no-pie command line option. Retrying without."); |
10 |
+ info!("Linker does not support -no-pie command line option. Retrying without."); |
11 |
for arg in cmd.take_args() { |
12 |
if arg.to_string_lossy() != "-no-pie" { |
13 |
cmd.arg(arg); |
14 |
@@ -782,7 +782,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( |
15 |
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie") |
16 |
{ |
17 |
info!("linker output: {:?}", out); |
18 |
- warn!( |
19 |
+ info!( |
20 |
"Linker does not support -static-pie command line option. Retrying with -static instead." |
21 |
); |
22 |
// Mirror `add_(pre,post)_link_objects` to replace CRT objects. |
23 |
@@ -1507,15 +1507,14 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
24 |
} |
25 |
|
26 |
fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind { |
27 |
- let kind = match (crate_type, sess.crt_static(Some(crate_type)), sess.relocation_model()) { |
28 |
+ // Only use PIE if explicitly specified. |
29 |
+ let explicit_pic = |
30 |
+ matches!(sess.opts.cg.relocation_model, Some(RelocModel::Pic | RelocModel::Pie)); |
31 |
+ let kind = match (crate_type, sess.crt_static(Some(crate_type)), explicit_pic) { |
32 |
(CrateType::Executable, _, _) if sess.is_wasi_reactor() => LinkOutputKind::WasiReactorExe, |
33 |
- (CrateType::Executable, false, RelocModel::Pic | RelocModel::Pie) => { |
34 |
- LinkOutputKind::DynamicPicExe |
35 |
- } |
36 |
+ (CrateType::Executable, false, true) => LinkOutputKind::DynamicPicExe, |
37 |
(CrateType::Executable, false, _) => LinkOutputKind::DynamicNoPicExe, |
38 |
- (CrateType::Executable, true, RelocModel::Pic | RelocModel::Pie) => { |
39 |
- LinkOutputKind::StaticPicExe |
40 |
- } |
41 |
+ (CrateType::Executable, true, true) => LinkOutputKind::StaticPicExe, |
42 |
(CrateType::Executable, true, _) => LinkOutputKind::StaticNoPicExe, |
43 |
(_, true, _) => LinkOutputKind::StaticDylib, |
44 |
(_, false, _) => LinkOutputKind::DynamicDylib, |