about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-10 23:26:47 -0700
committerGitHub <noreply@github.com>2020-07-10 23:26:47 -0700
commitd2f8c30951581fa35bde0dbdd3260c5019b50421 (patch)
tree86833fd7f4c2bad113e785f84c86a3cb1f8b5328 /src/librustc_codegen_llvm
parent8355024ed0cda6b041bc0adb2ca17193946b6c8e (diff)
parent62cf767a4a39b47677d18110359d9e7152dc9d1c (diff)
Rollup merge of #74127 - tamird:allowlist, r=oli-obk
Avoid "whitelist"

Other terms are more inclusive and precise.
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/attributes.rs8
-rw-r--r--src/librustc_codegen_llvm/back/lto.rs57
-rw-r--r--src/librustc_codegen_llvm/llvm_util.rs57
3 files changed, 69 insertions, 53 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs
index c53a64664a6..89b548a9c5a 100644
--- a/src/librustc_codegen_llvm/attributes.rs
+++ b/src/librustc_codegen_llvm/attributes.rs
@@ -263,7 +263,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
     // Windows we end up still needing the `uwtable` attribute even if the `-C
     // panic=abort` flag is passed.
     //
-    // You can also find more info on why Windows is whitelisted here in:
+    // You can also find more info on why Windows always requires uwtables here:
     //      https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
     if cx.sess().must_emit_unwind_tables() {
         attributes::emit_uwtable(llfn, true);
@@ -343,14 +343,14 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
 }
 
 pub fn provide(providers: &mut Providers) {
-    providers.target_features_whitelist = |tcx, cnum| {
+    providers.supported_target_features = |tcx, cnum| {
         assert_eq!(cnum, LOCAL_CRATE);
         if tcx.sess.opts.actually_rustdoc {
             // rustdoc needs to be able to document functions that use all the features, so
-            // whitelist them all
+            // provide them all.
             llvm_util::all_known_features().map(|(a, b)| (a.to_string(), b)).collect()
         } else {
-            llvm_util::target_feature_whitelist(tcx.sess)
+            llvm_util::supported_target_features(tcx.sess)
                 .iter()
                 .map(|&(a, b)| (a.to_string(), b))
                 .collect()
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs
index 9764c9a102e..6b02b5e8120 100644
--- a/src/librustc_codegen_llvm/back/lto.rs
+++ b/src/librustc_codegen_llvm/back/lto.rs
@@ -62,11 +62,11 @@ fn prepare_lto(
         }
     };
     let exported_symbols = cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
-    let mut symbol_white_list = {
-        let _timer = cgcx.prof.generic_activity("LLVM_lto_generate_symbol_white_list");
+    let mut symbols_below_threshold = {
+        let _timer = cgcx.prof.generic_activity("LLVM_lto_generate_symbols_below_threshold");
         exported_symbols[&LOCAL_CRATE].iter().filter_map(symbol_filter).collect::<Vec<CString>>()
     };
-    info!("{} symbols to preserve in this crate", symbol_white_list.len());
+    info!("{} symbols to preserve in this crate", symbols_below_threshold.len());
 
     // If we're performing LTO for the entire crate graph, then for each of our
     // upstream dependencies, find the corresponding rlib and load the bitcode
@@ -102,8 +102,10 @@ fn prepare_lto(
             let exported_symbols =
                 cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
             {
-                let _timer = cgcx.prof.generic_activity("LLVM_lto_generate_symbol_white_list");
-                symbol_white_list.extend(exported_symbols[&cnum].iter().filter_map(symbol_filter));
+                let _timer =
+                    cgcx.prof.generic_activity("LLVM_lto_generate_symbols_below_threshold");
+                symbols_below_threshold
+                    .extend(exported_symbols[&cnum].iter().filter_map(symbol_filter));
             }
 
             let archive = ArchiveRO::open(&path).expect("wanted an rlib");
@@ -124,7 +126,7 @@ fn prepare_lto(
         }
     }
 
-    Ok((symbol_white_list, upstream_modules))
+    Ok((symbols_below_threshold, upstream_modules))
 }
 
 fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], String> {
@@ -155,9 +157,17 @@ pub(crate) fn run_fat(
     cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
 ) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> {
     let diag_handler = cgcx.create_diag_handler();
-    let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
-    let symbol_white_list = symbol_white_list.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
-    fat_lto(cgcx, &diag_handler, modules, cached_modules, upstream_modules, &symbol_white_list)
+    let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
+    let symbols_below_threshold =
+        symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
+    fat_lto(
+        cgcx,
+        &diag_handler,
+        modules,
+        cached_modules,
+        upstream_modules,
+        &symbols_below_threshold,
+    )
 }
 
 /// Performs thin LTO by performing necessary global analysis and returning two
@@ -169,15 +179,23 @@ pub(crate) fn run_thin(
     cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
 ) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
     let diag_handler = cgcx.create_diag_handler();
-    let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
-    let symbol_white_list = symbol_white_list.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
+    let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
+    let symbols_below_threshold =
+        symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
     if cgcx.opts.cg.linker_plugin_lto.enabled() {
         unreachable!(
             "We should never reach this case if the LTO step \
                       is deferred to the linker"
         );
     }
-    thin_lto(cgcx, &diag_handler, modules, upstream_modules, cached_modules, &symbol_white_list)
+    thin_lto(
+        cgcx,
+        &diag_handler,
+        modules,
+        upstream_modules,
+        cached_modules,
+        &symbols_below_threshold,
+    )
 }
 
 pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
@@ -192,7 +210,7 @@ fn fat_lto(
     modules: Vec<FatLTOInput<LlvmCodegenBackend>>,
     cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
     mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
-    symbol_white_list: &[*const libc::c_char],
+    symbols_below_threshold: &[*const libc::c_char],
 ) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> {
     let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_build_monolithic_module");
     info!("going for a fat lto");
@@ -306,14 +324,13 @@ fn fat_lto(
         drop(linker);
         save_temp_bitcode(&cgcx, &module, "lto.input");
 
-        // Internalize everything that *isn't* in our whitelist to help strip out
-        // more modules and such
+        // Internalize everything below threshold to help strip out more modules and such.
         unsafe {
-            let ptr = symbol_white_list.as_ptr();
+            let ptr = symbols_below_threshold.as_ptr();
             llvm::LLVMRustRunRestrictionPass(
                 llmod,
                 ptr as *const *const libc::c_char,
-                symbol_white_list.len() as libc::size_t,
+                symbols_below_threshold.len() as libc::size_t,
             );
             save_temp_bitcode(&cgcx, &module, "lto.after-restriction");
         }
@@ -395,7 +412,7 @@ fn thin_lto(
     modules: Vec<(String, ThinBuffer)>,
     serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
     cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
-    symbol_white_list: &[*const libc::c_char],
+    symbols_below_threshold: &[*const libc::c_char],
 ) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
     let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
     unsafe {
@@ -463,8 +480,8 @@ fn thin_lto(
         let data = llvm::LLVMRustCreateThinLTOData(
             thin_modules.as_ptr(),
             thin_modules.len() as u32,
-            symbol_white_list.as_ptr(),
-            symbol_white_list.len() as u32,
+            symbols_below_threshold.as_ptr(),
+            symbols_below_threshold.len() as u32,
         )
         .ok_or_else(|| write::llvm_err(&diag_handler, "failed to prepare thin LTO context"))?;
 
diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs
index 2e2ce154410..b631c10334c 100644
--- a/src/librustc_codegen_llvm/llvm_util.rs
+++ b/src/librustc_codegen_llvm/llvm_util.rs
@@ -139,7 +139,7 @@ pub fn time_trace_profiler_finish(file_name: &str) {
 // to LLVM or the feature detection code will walk past the end of the feature
 // array, leading to crashes.
 
-const ARM_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("aclass", Some(sym::arm_target_feature)),
     ("mclass", Some(sym::arm_target_feature)),
     ("rclass", Some(sym::arm_target_feature)),
@@ -162,7 +162,7 @@ const ARM_WHITELIST: &[(&str, Option<Symbol>)] = &[
     ("thumb-mode", Some(sym::arm_target_feature)),
 ];
 
-const AARCH64_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("fp", Some(sym::aarch64_target_feature)),
     ("neon", Some(sym::aarch64_target_feature)),
     ("sve", Some(sym::aarch64_target_feature)),
@@ -180,7 +180,7 @@ const AARCH64_WHITELIST: &[(&str, Option<Symbol>)] = &[
     ("v8.3a", Some(sym::aarch64_target_feature)),
 ];
 
-const X86_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("adx", Some(sym::adx_target_feature)),
     ("aes", None),
     ("avx", None),
@@ -224,12 +224,12 @@ const X86_WHITELIST: &[(&str, Option<Symbol>)] = &[
     ("xsaves", None),
 ];
 
-const HEXAGON_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const HEXAGON_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("hvx", Some(sym::hexagon_target_feature)),
     ("hvx-length128b", Some(sym::hexagon_target_feature)),
 ];
 
-const POWERPC_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const POWERPC_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("altivec", Some(sym::powerpc_target_feature)),
     ("power8-altivec", Some(sym::powerpc_target_feature)),
     ("power9-altivec", Some(sym::powerpc_target_feature)),
@@ -238,10 +238,10 @@ const POWERPC_WHITELIST: &[(&str, Option<Symbol>)] = &[
     ("vsx", Some(sym::powerpc_target_feature)),
 ];
 
-const MIPS_WHITELIST: &[(&str, Option<Symbol>)] =
+const MIPS_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] =
     &[("fp64", Some(sym::mips_target_feature)), ("msa", Some(sym::mips_target_feature))];
 
-const RISCV_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("m", Some(sym::riscv_target_feature)),
     ("a", Some(sym::riscv_target_feature)),
     ("c", Some(sym::riscv_target_feature)),
@@ -250,7 +250,7 @@ const RISCV_WHITELIST: &[(&str, Option<Symbol>)] = &[
     ("e", Some(sym::riscv_target_feature)),
 ];
 
-const WASM_WHITELIST: &[(&str, Option<Symbol>)] = &[
+const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
     ("simd128", Some(sym::wasm_target_feature)),
     ("atomics", Some(sym::wasm_target_feature)),
     ("nontrapping-fptoint", Some(sym::wasm_target_feature)),
@@ -259,19 +259,18 @@ const WASM_WHITELIST: &[(&str, Option<Symbol>)] = &[
 /// When rustdoc is running, provide a list of all known features so that all their respective
 /// primitives may be documented.
 ///
-/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this
-/// iterator!
+/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
 pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol>)> {
-    ARM_WHITELIST
-        .iter()
+    std::iter::empty()
+        .chain(ARM_ALLOWED_FEATURES.iter())
+        .chain(AARCH64_ALLOWED_FEATURES.iter())
+        .chain(X86_ALLOWED_FEATURES.iter())
+        .chain(HEXAGON_ALLOWED_FEATURES.iter())
+        .chain(POWERPC_ALLOWED_FEATURES.iter())
+        .chain(MIPS_ALLOWED_FEATURES.iter())
+        .chain(RISCV_ALLOWED_FEATURES.iter())
+        .chain(WASM_ALLOWED_FEATURES.iter())
         .cloned()
-        .chain(AARCH64_WHITELIST.iter().cloned())
-        .chain(X86_WHITELIST.iter().cloned())
-        .chain(HEXAGON_WHITELIST.iter().cloned())
-        .chain(POWERPC_WHITELIST.iter().cloned())
-        .chain(MIPS_WHITELIST.iter().cloned())
-        .chain(RISCV_WHITELIST.iter().cloned())
-        .chain(WASM_WHITELIST.iter().cloned())
 }
 
 pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
@@ -289,7 +288,7 @@ pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
 
 pub fn target_features(sess: &Session) -> Vec<Symbol> {
     let target_machine = create_informational_target_machine(sess);
-    target_feature_whitelist(sess)
+    supported_target_features(sess)
         .iter()
         .filter_map(|&(feature, gate)| {
             if UnstableFeatures::from_environment().is_nightly_build() || gate.is_none() {
@@ -307,16 +306,16 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
         .collect()
 }
 
-pub fn target_feature_whitelist(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
+pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
     match &*sess.target.target.arch {
-        "arm" => ARM_WHITELIST,
-        "aarch64" => AARCH64_WHITELIST,
-        "x86" | "x86_64" => X86_WHITELIST,
-        "hexagon" => HEXAGON_WHITELIST,
-        "mips" | "mips64" => MIPS_WHITELIST,
-        "powerpc" | "powerpc64" => POWERPC_WHITELIST,
-        "riscv32" | "riscv64" => RISCV_WHITELIST,
-        "wasm32" => WASM_WHITELIST,
+        "arm" => ARM_ALLOWED_FEATURES,
+        "aarch64" => AARCH64_ALLOWED_FEATURES,
+        "x86" | "x86_64" => X86_ALLOWED_FEATURES,
+        "hexagon" => HEXAGON_ALLOWED_FEATURES,
+        "mips" | "mips64" => MIPS_ALLOWED_FEATURES,
+        "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
+        "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
+        "wasm32" => WASM_ALLOWED_FEATURES,
         _ => &[],
     }
 }