Skip to content

Commit 718ea90

Browse files
committed
Don't export main on WebAssembly.
On `default_hidden_visibility = true` platforms, which is currently just WebAssembly, don't automatically export `main`. On such platforms, `main` in C defaults to being hidden, and therefore not automatically exported.
1 parent 09ae784 commit 718ea90

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,22 @@ fn exported_symbols_provider_local<'tcx>(
179179
.map(|(&def_id, &info)| (ExportedSymbol::NonGeneric(def_id), info))
180180
.collect();
181181

182-
if tcx.entry_fn(()).is_some() {
183-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
182+
// Export `main`, on platforms where it has "default" visibility. On platforms
183+
// where C functions are "hidden", `main` is "hidden" too, which means we aren't
184+
// expected to export it.
185+
if !tcx.sess.target.default_hidden_visibility {
186+
if tcx.entry_fn(()).is_some() {
187+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
184188

185-
symbols.push((
186-
exported_symbol,
187-
SymbolExportInfo {
188-
level: SymbolExportLevel::C,
189-
kind: SymbolExportKind::Text,
190-
used: false,
191-
},
192-
));
189+
symbols.push((
190+
exported_symbol,
191+
SymbolExportInfo {
192+
level: SymbolExportLevel::C,
193+
kind: SymbolExportKind::Text,
194+
used: false,
195+
},
196+
));
197+
}
193198
}
194199

195200
if tcx.allocator_kind(()).is_some() {

0 commit comments

Comments
 (0)