Skip to content

Commit e721d99

Browse files
fix(rust): sanitize export names for PGO compatibility
Replace ':' and '#' characters with underscores in export names to make them compatible with native ELF linkers during PGO builds. Fixes #1509
1 parent e5c8ce6 commit e721d99

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

crates/rust/src/interface.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::bindgen::{FunctionBindgen, POINTER_SIZE_EXPRESSION};
22
use crate::{
3-
ConstructorReturnType, FnSig, Identifier, InterfaceName, Ownership, RuntimeItem, RustFlagsRepr,
4-
RustWasm, TypeGeneration, classify_constructor_return_type, full_wit_type_name, int_repr,
5-
to_rust_ident, to_upper_camel_case, wasm_type,
3+
classify_constructor_return_type, full_wit_type_name, int_repr, to_rust_ident,
4+
to_upper_camel_case, wasm_type, ConstructorReturnType, FnSig, Identifier, InterfaceName,
5+
Ownership, RuntimeItem, RustFlagsRepr, RustWasm, TypeGeneration,
66
};
77
use anyhow::Result;
88
use heck::*;
@@ -11,7 +11,7 @@ use std::fmt::Write as _;
1111
use std::mem;
1212
use wit_bindgen_core::abi::{self, AbiVariant, LiftLower};
1313
use wit_bindgen_core::{
14-
AnonymousTypeGenerator, Source, TypeInfo, dealias, uwrite, uwriteln, wit_parser::*,
14+
dealias, uwrite, uwriteln, wit_parser::*, AnonymousTypeGenerator, Source, TypeInfo,
1515
};
1616

1717
pub struct InterfaceGenerator<'a> {
@@ -303,6 +303,7 @@ macro_rules! {macro_name} {{
303303
unreachable!()
304304
}
305305
};
306+
let module = module.replace(':', "_").replace('#', "_");
306307
let camel = name.to_upper_camel_case();
307308
uwriteln!(
308309
self.src,
@@ -1215,6 +1216,7 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
12151216
};
12161217
let export_prefix = self.r#gen.opts.export_prefix.as_deref().unwrap_or("");
12171218
let export_name = func.legacy_core_export_name(wasm_module_export_name.as_deref());
1219+
let export_name = export_name.replace(':', "_").replace('#', "_");
12181220
let export_name = if async_ {
12191221
format!("[async-lift]{export_name}")
12201222
} else {

0 commit comments

Comments
 (0)