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