Skip to content

Commit a10fd61

Browse files
authored
Fix more flag inheritance (#1380)
1 parent 3a4a86d commit a10fd61

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

src/flags.rs

+33-25
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub(crate) struct RustcCodegenFlags<'a> {
1616
relocation_model: Option<&'a str>,
1717
embed_bitcode: Option<bool>,
1818
force_frame_pointers: Option<bool>,
19-
link_dead_code: Option<bool>,
2019
no_redzone: Option<bool>,
2120
soft_float: Option<bool>,
2221
}
@@ -138,8 +137,6 @@ impl<'this> RustcCodegenFlags<'this> {
138137
"-Cforce-frame-pointers" => {
139138
self.force_frame_pointers = value.map_or(Some(true), arg_to_bool)
140139
}
141-
// https://doc.rust-lang.org/rustc/codegen-options/index.html#link-dead-code
142-
"-Clink-dead-code" => self.link_dead_code = value.map_or(Some(true), arg_to_bool),
143140
// https://doc.rust-lang.org/rustc/codegen-options/index.html#no-redzone
144141
"-Cno-redzone" => self.no_redzone = value.map_or(Some(true), arg_to_bool),
145142
// https://doc.rust-lang.org/rustc/codegen-options/index.html#soft-float
@@ -180,42 +177,40 @@ impl<'this> RustcCodegenFlags<'this> {
180177
// Flags shared between clang and gnu
181178
if clang_or_gnu {
182179
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mbranch-protection
180+
// https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-mbranch-protection (Aarch64)
181+
// https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#index-mbranch-protection-1 (ARM)
182+
// https://developer.arm.com/documentation/101754/0619/armclang-Reference/armclang-Command-line-Options/-mbranch-protection
183183
if let Some(value) = self.branch_protection {
184184
push_if_supported(
185185
format!("-mbranch-protection={}", value.replace(",", "+")).into(),
186186
);
187187
}
188188
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mcmodel
189+
// https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html (several archs, search for `-mcmodel=`).
190+
// FIXME(madsmtm): Parse the model, to make sure we pass the correct value (depending on arch).
189191
if let Some(value) = self.code_model {
190192
push_if_supported(format!("-mcmodel={value}").into());
191193
}
192194
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-vectorize
195+
// https://gcc.gnu.org/onlinedocs/gnat_ugn/Vectorization-of-loops.html
193196
if self.no_vectorize_loops {
194197
push_if_supported("-fno-vectorize".into());
195198
}
196199
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-slp-vectorize
200+
// https://gcc.gnu.org/onlinedocs/gnat_ugn/Vectorization-of-loops.html
197201
if self.no_vectorize_slp {
198202
push_if_supported("-fno-slp-vectorize".into());
199203
}
200-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mguard
201-
if let Some(value) = self.control_flow_guard {
202-
let cc_val = match value {
203-
"y" | "yes" | "on" | "true" | "checks" => Some("cf"),
204-
"nochecks" => Some("cf-nochecks"),
205-
"n" | "no" | "off" | "false" => Some("none"),
206-
_ => None,
207-
};
208-
if let Some(cc_val) = cc_val {
209-
push_if_supported(format!("-mguard={cc_val}").into());
210-
}
211-
}
212-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIC
213-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIE
214-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mdynamic-no-pic
215204
if let Some(value) = self.relocation_model {
216205
let cc_flag = match value {
206+
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIC
207+
// https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fPIC
217208
"pic" => Some("-fPIC"),
209+
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIE
210+
// https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fPIE
218211
"pie" => Some("-fPIE"),
212+
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mdynamic-no-pic
213+
// https://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html#index-mdynamic-no-pic
219214
"dynamic-no-pic" => Some("-mdynamic-no-pic"),
220215
_ => None,
221216
};
@@ -225,6 +220,7 @@ impl<'this> RustcCodegenFlags<'this> {
225220
}
226221
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-omit-frame-pointer
227222
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fomit-frame-pointer
223+
// https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fomit-frame-pointer
228224
if let Some(value) = self.force_frame_pointers {
229225
let cc_flag = if value {
230226
"-fno-omit-frame-pointer"
@@ -233,23 +229,24 @@ impl<'this> RustcCodegenFlags<'this> {
233229
};
234230
push_if_supported(cc_flag.into());
235231
}
236-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-dead_strip
237-
if let Some(false) = self.link_dead_code {
238-
push_if_supported("-dead_strip".into());
239-
}
240232
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-red-zone
233+
// https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mno-red-zone
241234
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mred-zone
235+
// https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mred-zone
242236
if let Some(value) = self.no_redzone {
243237
let cc_flag = if value { "-mno-red-zone" } else { "-mred-zone" };
244238
push_if_supported(cc_flag.into());
245239
}
246240
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-msoft-float
247-
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-soft-float
241+
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mhard-float
242+
// https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html (several archs, search for `-msoft-float`).
243+
// https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html (several archs, search for `-mhard-float`).
248244
if let Some(value) = self.soft_float {
249245
let cc_flag = if value {
250246
"-msoft-float"
251247
} else {
252-
"-mno-soft-float"
248+
// Do not use -mno-soft-float, that's basically just an alias for -mno-implicit-float.
249+
"-mhard-float"
253250
};
254251
push_if_supported(cc_flag.into());
255252
}
@@ -287,6 +284,18 @@ impl<'this> RustcCodegenFlags<'this> {
287284
push_if_supported(format!("-flto={cc_val}").into());
288285
}
289286
}
287+
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mguard
288+
if let Some(value) = self.control_flow_guard {
289+
let cc_val = match value {
290+
"y" | "yes" | "on" | "true" | "checks" => Some("cf"),
291+
"nochecks" => Some("cf-nochecks"),
292+
"n" | "no" | "off" | "false" => Some("none"),
293+
_ => None,
294+
};
295+
if let Some(cc_val) = cc_val {
296+
push_if_supported(format!("-mguard={cc_val}").into());
297+
}
298+
}
290299
}
291300
ToolFamily::Gnu { .. } => {}
292301
ToolFamily::Msvc { .. } => {
@@ -478,7 +487,6 @@ mod tests {
478487
control_flow_guard: Some("yes"),
479488
embed_bitcode: Some(false),
480489
force_frame_pointers: Some(true),
481-
link_dead_code: Some(true),
482490
lto: Some("false"),
483491
no_redzone: Some(true),
484492
no_vectorize_loops: true,

0 commit comments

Comments
 (0)