Skip to content

Commit b3cbf7c

Browse files
committed
Auto merge of rust-lang#111694 - Amanieu:no-assume-bdynamic, r=petrochenkov
Don't assume that `-Bdynamic` is the default linker mode In particular this is false when passing `-static` or `-static-pie` to the linker, which changes the default to `-Bstatic`. This PR ensures we explicitly initialize the correct mode when we first need it.
2 parents 70db836 + c2f0313 commit b3cbf7c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub fn get_linker<'a>(
144144
cmd,
145145
sess,
146146
target_cpu,
147-
hinted_static: false,
147+
hinted_static: None,
148148
is_ld: cc == Cc::No,
149149
is_gnu: flavor.is_gnu(),
150150
}) as Box<dyn Linker>,
@@ -214,7 +214,7 @@ pub struct GccLinker<'a> {
214214
cmd: Command,
215215
sess: &'a Session,
216216
target_cpu: &'a str,
217-
hinted_static: bool, // Keeps track of the current hinting mode.
217+
hinted_static: Option<bool>, // Keeps track of the current hinting mode.
218218
// Link as ld
219219
is_ld: bool,
220220
is_gnu: bool,
@@ -275,19 +275,19 @@ impl<'a> GccLinker<'a> {
275275
if !self.takes_hints() {
276276
return;
277277
}
278-
if !self.hinted_static {
278+
if self.hinted_static != Some(true) {
279279
self.linker_arg("-Bstatic");
280-
self.hinted_static = true;
280+
self.hinted_static = Some(true);
281281
}
282282
}
283283

284284
fn hint_dynamic(&mut self) {
285285
if !self.takes_hints() {
286286
return;
287287
}
288-
if self.hinted_static {
288+
if self.hinted_static != Some(false) {
289289
self.linker_arg("-Bdynamic");
290-
self.hinted_static = false;
290+
self.hinted_static = Some(false);
291291
}
292292
}
293293

@@ -1484,25 +1484,25 @@ impl<'a> L4Bender<'a> {
14841484
pub struct AixLinker<'a> {
14851485
cmd: Command,
14861486
sess: &'a Session,
1487-
hinted_static: bool,
1487+
hinted_static: Option<bool>,
14881488
}
14891489

14901490
impl<'a> AixLinker<'a> {
14911491
pub fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
1492-
AixLinker { cmd: cmd, sess: sess, hinted_static: false }
1492+
AixLinker { cmd: cmd, sess: sess, hinted_static: None }
14931493
}
14941494

14951495
fn hint_static(&mut self) {
1496-
if !self.hinted_static {
1496+
if self.hinted_static != Some(true) {
14971497
self.cmd.arg("-bstatic");
1498-
self.hinted_static = true;
1498+
self.hinted_static = Some(true);
14991499
}
15001500
}
15011501

15021502
fn hint_dynamic(&mut self) {
1503-
if self.hinted_static {
1503+
if self.hinted_static != Some(false) {
15041504
self.cmd.arg("-bdynamic");
1505-
self.hinted_static = false;
1505+
self.hinted_static = Some(false);
15061506
}
15071507
}
15081508

0 commit comments

Comments
 (0)