|
|
0257e6 |
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
|
|
|
0257e6 |
index dcce1d45298c..5c11f7276f26 100644
|
|
|
0257e6 |
--- a/src/librustc_codegen_ssa/back/link.rs
|
|
|
0257e6 |
+++ b/src/librustc_codegen_ssa/back/link.rs
|
|
|
0257e6 |
@@ -1184,10 +1184,12 @@ fn exec_linker(
|
|
|
0257e6 |
}
|
|
|
0257e6 |
|
|
|
0257e6 |
fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
|
|
|
0257e6 |
- let kind = match (crate_type, sess.crt_static(Some(crate_type)), sess.relocation_model()) {
|
|
|
0257e6 |
- (CrateType::Executable, false, RelocModel::Pic) => LinkOutputKind::DynamicPicExe,
|
|
|
0257e6 |
+ // Only use PIE if explicity specified.
|
|
|
0257e6 |
+ let explicit_pic = matches!(sess.opts.cg.relocation_model, Some(RelocModel::Pic));
|
|
|
0257e6 |
+ let kind = match (crate_type, sess.crt_static(Some(crate_type)), explicit_pic) {
|
|
|
0257e6 |
+ (CrateType::Executable, false, true) => LinkOutputKind::DynamicPicExe,
|
|
|
0257e6 |
(CrateType::Executable, false, _) => LinkOutputKind::DynamicNoPicExe,
|
|
|
0257e6 |
- (CrateType::Executable, true, RelocModel::Pic) => LinkOutputKind::StaticPicExe,
|
|
|
0257e6 |
+ (CrateType::Executable, true, true) => LinkOutputKind::StaticPicExe,
|
|
|
0257e6 |
(CrateType::Executable, true, _) => LinkOutputKind::StaticNoPicExe,
|
|
|
0257e6 |
(_, true, _) => LinkOutputKind::StaticDylib,
|
|
|
0257e6 |
(_, false, _) => LinkOutputKind::DynamicDylib,
|