@@ -337,7 +337,12 @@ pub(crate) trait Linker {
337
337
fn debuginfo ( & mut self , strip : Strip , natvis_debugger_visualizers : & [ PathBuf ] ) ;
338
338
fn no_crt_objects ( & mut self ) ;
339
339
fn no_default_libraries ( & mut self ) ;
340
- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) ;
340
+ fn export_symbols (
341
+ & mut self ,
342
+ tmpdir : & Path ,
343
+ crate_type : CrateType ,
344
+ symbols : & [ ( String , SymbolExportKind ) ] ,
345
+ ) ;
341
346
fn subsystem ( & mut self , subsystem : & str ) ;
342
347
fn linker_plugin_lto ( & mut self ) ;
343
348
fn add_eh_frame_header ( & mut self ) { }
@@ -770,7 +775,12 @@ impl<'a> Linker for GccLinker<'a> {
770
775
}
771
776
}
772
777
773
- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) {
778
+ fn export_symbols (
779
+ & mut self ,
780
+ tmpdir : & Path ,
781
+ crate_type : CrateType ,
782
+ symbols : & [ ( String , SymbolExportKind ) ] ,
783
+ ) {
774
784
// Symbol visibility in object files typically takes care of this.
775
785
if crate_type == CrateType :: Executable {
776
786
let should_export_executable_symbols =
@@ -799,7 +809,7 @@ impl<'a> Linker for GccLinker<'a> {
799
809
// Write a plain, newline-separated list of symbols
800
810
let res: io:: Result < ( ) > = try {
801
811
let mut f = File :: create_buffered ( & path) ?;
802
- for sym in symbols {
812
+ for ( sym, _ ) in symbols {
803
813
debug ! ( " _{sym}" ) ;
804
814
writeln ! ( f, "_{sym}" ) ?;
805
815
}
@@ -814,11 +824,12 @@ impl<'a> Linker for GccLinker<'a> {
814
824
// .def file similar to MSVC one but without LIBRARY section
815
825
// because LD doesn't like when it's empty
816
826
writeln ! ( f, "EXPORTS" ) ?;
817
- for symbol in symbols {
827
+ for ( symbol, kind) in symbols {
828
+ let kind_marker = if * kind == SymbolExportKind :: Data { " DATA" } else { "" } ;
818
829
debug ! ( " _{symbol}" ) ;
819
830
// Quote the name in case it's reserved by linker in some way
820
831
// (this accounts for names with dots in particular).
821
- writeln ! ( f, " \" {symbol}\" " ) ?;
832
+ writeln ! ( f, " \" {symbol}\" {kind_marker} " ) ?;
822
833
}
823
834
} ;
824
835
if let Err ( error) = res {
@@ -831,7 +842,7 @@ impl<'a> Linker for GccLinker<'a> {
831
842
writeln ! ( f, "{{" ) ?;
832
843
if !symbols. is_empty ( ) {
833
844
writeln ! ( f, " global:" ) ?;
834
- for sym in symbols {
845
+ for ( sym, _ ) in symbols {
835
846
debug ! ( " {sym};" ) ;
836
847
writeln ! ( f, " {sym};" ) ?;
837
848
}
@@ -1098,7 +1109,12 @@ impl<'a> Linker for MsvcLinker<'a> {
1098
1109
// crates. Upstream rlibs may be linked statically to this dynamic library,
1099
1110
// in which case they may continue to transitively be used and hence need
1100
1111
// their symbols exported.
1101
- fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType , symbols : & [ String ] ) {
1112
+ fn export_symbols (
1113
+ & mut self ,
1114
+ tmpdir : & Path ,
1115
+ crate_type : CrateType ,
1116
+ symbols : & [ ( String , SymbolExportKind ) ] ,
1117
+ ) {
1102
1118
// Symbol visibility takes care of this typically
1103
1119
if crate_type == CrateType :: Executable {
1104
1120
let should_export_executable_symbols =
@@ -1116,9 +1132,10 @@ impl<'a> Linker for MsvcLinker<'a> {
1116
1132
// straight to exports.
1117
1133
writeln ! ( f, "LIBRARY" ) ?;
1118
1134
writeln ! ( f, "EXPORTS" ) ?;
1119
- for symbol in symbols {
1135
+ for ( symbol, kind) in symbols {
1136
+ let kind_marker = if * kind == SymbolExportKind :: Data { " DATA" } else { "" } ;
1120
1137
debug ! ( " _{symbol}" ) ;
1121
- writeln ! ( f, " {symbol}" ) ?;
1138
+ writeln ! ( f, " {symbol}{kind_marker} " ) ?;
1122
1139
}
1123
1140
} ;
1124
1141
if let Err ( error) = res {
@@ -1259,14 +1276,19 @@ impl<'a> Linker for EmLinker<'a> {
1259
1276
self . cc_arg ( "-nodefaultlibs" ) ;
1260
1277
}
1261
1278
1262
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
1279
+ fn export_symbols (
1280
+ & mut self ,
1281
+ _tmpdir : & Path ,
1282
+ _crate_type : CrateType ,
1283
+ symbols : & [ ( String , SymbolExportKind ) ] ,
1284
+ ) {
1263
1285
debug ! ( "EXPORTED SYMBOLS:" ) ;
1264
1286
1265
1287
self . cc_arg ( "-s" ) ;
1266
1288
1267
1289
let mut arg = OsString :: from ( "EXPORTED_FUNCTIONS=" ) ;
1268
1290
let encoded = serde_json:: to_string (
1269
- & symbols. iter ( ) . map ( |sym| "_" . to_owned ( ) + sym) . collect :: < Vec < _ > > ( ) ,
1291
+ & symbols. iter ( ) . map ( |( sym, _ ) | "_" . to_owned ( ) + sym) . collect :: < Vec < _ > > ( ) ,
1270
1292
)
1271
1293
. unwrap ( ) ;
1272
1294
debug ! ( "{encoded}" ) ;
@@ -1428,8 +1450,13 @@ impl<'a> Linker for WasmLd<'a> {
1428
1450
1429
1451
fn no_default_libraries ( & mut self ) { }
1430
1452
1431
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
1432
- for sym in symbols {
1453
+ fn export_symbols (
1454
+ & mut self ,
1455
+ _tmpdir : & Path ,
1456
+ _crate_type : CrateType ,
1457
+ symbols : & [ ( String , SymbolExportKind ) ] ,
1458
+ ) {
1459
+ for ( sym, _) in symbols {
1433
1460
self . link_args ( & [ "--export" , sym] ) ;
1434
1461
}
1435
1462
@@ -1563,7 +1590,7 @@ impl<'a> Linker for L4Bender<'a> {
1563
1590
self . cc_arg ( "-nostdlib" ) ;
1564
1591
}
1565
1592
1566
- fn export_symbols ( & mut self , _: & Path , _: CrateType , _: & [ String ] ) {
1593
+ fn export_symbols ( & mut self , _: & Path , _: CrateType , _: & [ ( String , SymbolExportKind ) ] ) {
1567
1594
// ToDo, not implemented, copy from GCC
1568
1595
self . sess . dcx ( ) . emit_warn ( errors:: L4BenderExportingSymbolsUnimplemented ) ;
1569
1596
}
@@ -1720,12 +1747,17 @@ impl<'a> Linker for AixLinker<'a> {
1720
1747
1721
1748
fn no_default_libraries ( & mut self ) { }
1722
1749
1723
- fn export_symbols ( & mut self , tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
1750
+ fn export_symbols (
1751
+ & mut self ,
1752
+ tmpdir : & Path ,
1753
+ _crate_type : CrateType ,
1754
+ symbols : & [ ( String , SymbolExportKind ) ] ,
1755
+ ) {
1724
1756
let path = tmpdir. join ( "list.exp" ) ;
1725
1757
let res: io:: Result < ( ) > = try {
1726
1758
let mut f = File :: create_buffered ( & path) ?;
1727
1759
// FIXME: use llvm-nm to generate export list.
1728
- for symbol in symbols {
1760
+ for ( symbol, _ ) in symbols {
1729
1761
debug ! ( " _{symbol}" ) ;
1730
1762
writeln ! ( f, " {symbol}" ) ?;
1731
1763
}
@@ -1769,9 +1801,12 @@ fn for_each_exported_symbols_include_dep<'tcx>(
1769
1801
}
1770
1802
}
1771
1803
1772
- pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1804
+ pub ( crate ) fn exported_symbols (
1805
+ tcx : TyCtxt < ' _ > ,
1806
+ crate_type : CrateType ,
1807
+ ) -> Vec < ( String , SymbolExportKind ) > {
1773
1808
if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
1774
- return exports. iter ( ) . map ( ToString :: to_string ) . collect ( ) ;
1809
+ return exports. iter ( ) . map ( |name| ( name . to_string ( ) , SymbolExportKind :: Text ) ) . collect ( ) ;
1775
1810
}
1776
1811
1777
1812
if let CrateType :: ProcMacro = crate_type {
@@ -1781,25 +1816,29 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
1781
1816
}
1782
1817
}
1783
1818
1784
- fn exported_symbols_for_non_proc_macro ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1819
+ fn exported_symbols_for_non_proc_macro (
1820
+ tcx : TyCtxt < ' _ > ,
1821
+ crate_type : CrateType ,
1822
+ ) -> Vec < ( String , SymbolExportKind ) > {
1785
1823
let mut symbols = Vec :: new ( ) ;
1786
1824
let export_threshold = symbol_export:: crates_export_threshold ( & [ crate_type] ) ;
1787
1825
for_each_exported_symbols_include_dep ( tcx, crate_type, |symbol, info, cnum| {
1788
1826
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
1789
1827
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
1790
1828
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
1791
1829
if info. level . is_below_threshold ( export_threshold) && !tcx. is_compiler_builtins ( cnum) {
1792
- symbols. push ( symbol_export:: exporting_symbol_name_for_instance_in_crate (
1793
- tcx, symbol, cnum,
1830
+ symbols. push ( (
1831
+ symbol_export:: exporting_symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ,
1832
+ info. kind ,
1794
1833
) ) ;
1795
- symbol_export:: extend_exported_symbols ( & mut symbols, tcx, symbol, cnum) ;
1834
+ symbol_export:: extend_exported_symbols ( & mut symbols, tcx, symbol, info , cnum) ;
1796
1835
}
1797
1836
} ) ;
1798
1837
1799
1838
symbols
1800
1839
}
1801
1840
1802
- fn exported_symbols_for_proc_macro_crate ( tcx : TyCtxt < ' _ > ) -> Vec < String > {
1841
+ fn exported_symbols_for_proc_macro_crate ( tcx : TyCtxt < ' _ > ) -> Vec < ( String , SymbolExportKind ) > {
1803
1842
// `exported_symbols` will be empty when !should_codegen.
1804
1843
if !tcx. sess . opts . output_types . should_codegen ( ) {
1805
1844
return Vec :: new ( ) ;
@@ -1809,7 +1848,10 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
1809
1848
let proc_macro_decls_name = tcx. sess . generate_proc_macro_decls_symbol ( stable_crate_id) ;
1810
1849
let metadata_symbol_name = exported_symbols:: metadata_symbol_name ( tcx) ;
1811
1850
1812
- vec ! [ proc_macro_decls_name, metadata_symbol_name]
1851
+ vec ! [
1852
+ ( proc_macro_decls_name, SymbolExportKind :: Text ) ,
1853
+ ( metadata_symbol_name, SymbolExportKind :: Text ) ,
1854
+ ]
1813
1855
}
1814
1856
1815
1857
pub ( crate ) fn linked_symbols (
@@ -1831,7 +1873,9 @@ pub(crate) fn linked_symbols(
1831
1873
|| info. used
1832
1874
{
1833
1875
symbols. push ( (
1834
- symbol_export:: linking_symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ,
1876
+ symbol_export:: linking_symbol_name_for_instance_in_crate (
1877
+ tcx, symbol, info. kind , cnum,
1878
+ ) ,
1835
1879
info. kind ,
1836
1880
) ) ;
1837
1881
}
@@ -1906,7 +1950,13 @@ impl<'a> Linker for PtxLinker<'a> {
1906
1950
1907
1951
fn ehcont_guard ( & mut self ) { }
1908
1952
1909
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , _symbols : & [ String ] ) { }
1953
+ fn export_symbols (
1954
+ & mut self ,
1955
+ _tmpdir : & Path ,
1956
+ _crate_type : CrateType ,
1957
+ _symbols : & [ ( String , SymbolExportKind ) ] ,
1958
+ ) {
1959
+ }
1910
1960
1911
1961
fn subsystem ( & mut self , _subsystem : & str ) { }
1912
1962
@@ -1975,10 +2025,15 @@ impl<'a> Linker for LlbcLinker<'a> {
1975
2025
1976
2026
fn ehcont_guard ( & mut self ) { }
1977
2027
1978
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
2028
+ fn export_symbols (
2029
+ & mut self ,
2030
+ _tmpdir : & Path ,
2031
+ _crate_type : CrateType ,
2032
+ symbols : & [ ( String , SymbolExportKind ) ] ,
2033
+ ) {
1979
2034
match _crate_type {
1980
2035
CrateType :: Cdylib => {
1981
- for sym in symbols {
2036
+ for ( sym, _ ) in symbols {
1982
2037
self . link_args ( & [ "--export-symbol" , sym] ) ;
1983
2038
}
1984
2039
}
@@ -2052,11 +2107,16 @@ impl<'a> Linker for BpfLinker<'a> {
2052
2107
2053
2108
fn ehcont_guard ( & mut self ) { }
2054
2109
2055
- fn export_symbols ( & mut self , tmpdir : & Path , _crate_type : CrateType , symbols : & [ String ] ) {
2110
+ fn export_symbols (
2111
+ & mut self ,
2112
+ tmpdir : & Path ,
2113
+ _crate_type : CrateType ,
2114
+ symbols : & [ ( String , SymbolExportKind ) ] ,
2115
+ ) {
2056
2116
let path = tmpdir. join ( "symbols" ) ;
2057
2117
let res: io:: Result < ( ) > = try {
2058
2118
let mut f = File :: create_buffered ( & path) ?;
2059
- for sym in symbols {
2119
+ for ( sym, _ ) in symbols {
2060
2120
writeln ! ( f, "{sym}" ) ?;
2061
2121
}
2062
2122
} ;
0 commit comments