You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compiler/rustc_session/src/options.rs
+18
Original file line number
Diff line number
Diff line change
@@ -402,6 +402,7 @@ mod desc {
402
402
pubconst parse_switch_with_opt_path:&str =
403
403
"an optional path to the profiling data output directory";
404
404
pubconst parse_merge_functions:&str = "one of: `disabled`, `trampolines`, or `aliases`";
405
+
pubconst parse_symbol_mangling_plugin:&str = "configuration parameters of the hasher plugin: `hasher:<crate>[*],...[,salt=<value>][,level=1|2][,excluded=true|false]`";
405
406
pubconst parse_symbol_mangling_version:&str = "either `legacy` or `v0` (RFC 2603)";
406
407
pubconst parse_src_file_hash:&str = "either `md5` or `sha1`";
407
408
pubconst parse_relocation_model:&str =
@@ -1171,6 +1172,21 @@ mod parse {
1171
1172
true
1172
1173
}
1173
1174
1175
+
pub(crate)fnparse_symbol_mangling_plugin(
1176
+
slot:&mutSymbolManglingPlugin,
1177
+
v:Option<&str>,
1178
+
) -> bool{
1179
+
ifletSome(v) = v {
1180
+
// only support hasher
1181
+
let plugin = "hasher:";
1182
+
if v.starts_with(plugin){
1183
+
return slot.hasher_enable(&v[plugin.len()..]);
1184
+
}
1185
+
returnfalse;
1186
+
}
1187
+
true
1188
+
}
1189
+
1174
1190
pub(crate)fnparse_src_file_hash(
1175
1191
slot:&mutOption<SourceFileHashAlgorithm>,
1176
1192
v:Option<&str>,
@@ -1880,6 +1896,8 @@ written to standard error output)"),
1880
1896
"prefer dynamic linking to static linking for staticlibs (default: no)"),
Instead of defining a new mangling rule, it provides a plug-in for reprocessing mangling symbol names.
4
+
5
+
The average length of symbol names in the rust standard library is about 100 bytes, while the average length of symbol names in the C++ standard library is about 65 bytes. In some embedded environments where dynamic library are widely used, rust dynamic library symbol name space hash become one of the key bottlenecks of application. The plug-in mechanism provided here can help us eliminate this bottlenech.
6
+
7
+
The plug-in information is not written into the generated binary file. Therefore, you need to ensure that the plug-in configuration is consistent in multiple build environments. For example, the configuration parameters of the plug-in must be consistent in the build project of the dynamic library and the build project that depends on the dynamic library. Otherwise, an `undefined symbol` or `undefined version` error occurs.
8
+
9
+
The value of this parameter is in the format of `-Z symbol_mangling_plugin=<plugin name>:<plugin arguments>`. Currently only one plug-in is available: `hasher`.
10
+
11
+
## Hasher plug-in
12
+
13
+
The configuration format is `-Z symbol_mangling_plugin=hasher:<crate>[*],...[,excluded=true|false][,level=1|2][,salt=<value>]`.
14
+
15
+
In the preceding information, `<crate>` matches the name of the crate. If the name ends with `*`, the prefix is matched. The hasher plug-in only reprocesses the symbol names in (or not in, if `excluded=true`) specified crate. The hasher plug-in uses the hash value to replace the complete symbol names, compressing the symbol name space and avoid symbol conflicts.
16
+
17
+
If `level=`, the new symbol name format is `_ZN{length}{crate}.{item}.{hash32}E`. Otherwise, the new symbol name format is `_ZN{length}{crate}.{hash64}E`, which is the default format.
18
+
19
+
`salt` can specify a salt value for hash calculation, which reduces security risks caused by malicious replacement of dynamic libraries and increases security.
0 commit comments