diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2022-09-28 10:42:30 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2022-09-28 10:42:30 -0700 |
| commit | 3c3bf76ce0cc9e569e04a242dfdc447131e21db9 (patch) | |
| tree | d5e3c7bf8dd3b8dd9173d0060ee9dfad0ef99d1c /compiler/rustc_codegen_llvm/src/context.rs | |
| parent | 09ae7846a272a500ff7145255f0de5556c0b8949 (diff) | |
| download | rust-3c3bf76ce0cc9e569e04a242dfdc447131e21db9.tar.gz rust-3c3bf76ce0cc9e569e04a242dfdc447131e21db9.zip | |
Declare `main` as visibility hidden on targets that default to hidden.
On targets with `default_hidden_visibility` set, which is currrently just WebAssembly, declare the generated `main` function with visibility hidden. This makes it consistent with clang's WebAssembly target, where `main` is just a user function that gets the same visibility as any other user function, which is hidden on WebAssembly unless explicitly overridden. This will help simplify use cases which in the future may want to automatically wasm-export all visibility-"default" symbols. `main` isn't intended to be wasm-exported, and marking it hidden prevents it from being wasm-exported in that scenario.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/context.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 67ffc7cb951..6aeb56eb5ad 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -528,7 +528,12 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { llfn } else { let fty = self.type_variadic_func(&[], self.type_i32()); - let llfn = self.declare_cfn(name, llvm::UnnamedAddr::Global, fty); + let llfn = self.declare_cfn( + name, + llvm::UnnamedAddr::Global, + llvm::Visibility::Default, + fty, + ); let target_cpu = attributes::target_cpu_attr(self); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[target_cpu]); llfn @@ -585,7 +590,13 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> { if self.get_declared_value("main").is_none() { - Some(self.declare_cfn("main", llvm::UnnamedAddr::Global, fn_type)) + let visibility = if self.sess().target.default_hidden_visibility { + llvm::Visibility::Hidden + } else { + llvm::Visibility::Default + }; + + Some(self.declare_cfn("main", llvm::UnnamedAddr::Global, visibility, fn_type)) } else { // If the symbol already exists, it is an error: for example, the user wrote // #[no_mangle] extern "C" fn main(..) {..} @@ -615,7 +626,7 @@ impl<'ll> CodegenCx<'ll, '_> { } else { self.type_variadic_func(&[], ret) }; - let f = self.declare_cfn(name, llvm::UnnamedAddr::No, fn_ty); + let f = self.declare_cfn(name, llvm::UnnamedAddr::No, llvm::Visibility::Default, fn_ty); self.intrinsics.borrow_mut().insert(name, (fn_ty, f)); (fn_ty, f) } |
