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/declare.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/declare.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/declare.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 0f663a26732..21c466ddc24 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -32,6 +32,7 @@ fn declare_raw_fn<'ll>( name: &str, callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr, + visibility: llvm::Visibility, ty: &'ll Type, ) -> &'ll Value { debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty); @@ -41,6 +42,7 @@ fn declare_raw_fn<'ll>( llvm::SetFunctionCallConv(llfn, callconv); llvm::SetUnnamedAddress(llfn, unnamed); + llvm::SetVisibility(llfn, visibility); let mut attrs = SmallVec::<[_; 4]>::new(); @@ -76,9 +78,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { &self, name: &str, unnamed: llvm::UnnamedAddr, + visibility: llvm::Visibility, fn_type: &'ll Type, ) -> &'ll Value { - declare_raw_fn(self, name, llvm::CCallConv, unnamed, fn_type) + declare_raw_fn(self, name, llvm::CCallConv, unnamed, visibility, fn_type) } /// Declare a Rust function. @@ -95,6 +98,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name, fn_abi.llvm_cconv(), llvm::UnnamedAddr::Global, + llvm::Visibility::Default, fn_abi.llvm_type(self), ); fn_abi.apply_attrs_llfn(self, llfn); |
