@@ -84,6 +84,10 @@ impl LinkerInfo {
8484 LinkerFlavor :: PtxLinker => {
8585 Box :: new ( PtxLinker { cmd, sess, info : self } ) as Box < dyn Linker >
8686 }
87+
88+ LinkerFlavor :: BpfLinker => {
89+ Box :: new ( BpfLinker { cmd, sess, info : self } ) as Box < dyn Linker >
90+ }
8791 }
8892 }
8993}
@@ -1431,3 +1435,128 @@ impl<'a> Linker for PtxLinker<'a> {
14311435
14321436 fn linker_plugin_lto ( & mut self ) { }
14331437}
1438+
1439+ pub struct BpfLinker < ' a > {
1440+ cmd : Command ,
1441+ sess : & ' a Session ,
1442+ info : & ' a LinkerInfo ,
1443+ }
1444+
1445+ impl < ' a > Linker for BpfLinker < ' a > {
1446+ fn cmd ( & mut self ) -> & mut Command {
1447+ & mut self . cmd
1448+ }
1449+
1450+ fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1451+
1452+ fn link_rlib ( & mut self , path : & Path ) {
1453+ self . cmd . arg ( path) ;
1454+ }
1455+
1456+ fn link_whole_rlib ( & mut self , path : & Path ) {
1457+ self . cmd . arg ( path) ;
1458+ }
1459+
1460+ fn include_path ( & mut self , path : & Path ) {
1461+ self . cmd . arg ( "-L" ) . arg ( path) ;
1462+ }
1463+
1464+ fn debuginfo ( & mut self , _strip : Strip ) {
1465+ self . cmd . arg ( "--debug" ) ;
1466+ }
1467+
1468+ fn add_object ( & mut self , path : & Path ) {
1469+ self . cmd . arg ( path) ;
1470+ }
1471+
1472+ fn optimize ( & mut self ) {
1473+ self . cmd . arg ( match self . sess . opts . optimize {
1474+ OptLevel :: No => "-O0" ,
1475+ OptLevel :: Less => "-O1" ,
1476+ OptLevel :: Default => "-O2" ,
1477+ OptLevel :: Aggressive => "-O3" ,
1478+ OptLevel :: Size => "-Os" ,
1479+ OptLevel :: SizeMin => "-Oz" ,
1480+ } ) ;
1481+ }
1482+
1483+ fn output_filename ( & mut self , path : & Path ) {
1484+ self . cmd . arg ( "-o" ) . arg ( path) ;
1485+ }
1486+
1487+ fn finalize ( & mut self ) {
1488+ self . cmd . arg ( "--cpu" ) . arg ( match self . sess . opts . cg . target_cpu {
1489+ Some ( ref s) => s,
1490+ None => & self . sess . target . options . cpu ,
1491+ } ) ;
1492+ self . cmd . arg ( "--cpu-features" ) . arg ( match & self . sess . opts . cg . target_feature {
1493+ feat if !feat. is_empty ( ) => feat,
1494+ _ => & self . sess . target . options . features ,
1495+ } ) ;
1496+ }
1497+
1498+ fn link_dylib ( & mut self , _lib : Symbol , _verbatim : bool , _as_needed : bool ) {
1499+ panic ! ( "external dylibs not supported" )
1500+ }
1501+
1502+ fn link_rust_dylib ( & mut self , _lib : Symbol , _path : & Path ) {
1503+ panic ! ( "external dylibs not supported" )
1504+ }
1505+
1506+ fn link_staticlib ( & mut self , _lib : Symbol , _verbatim : bool ) {
1507+ panic ! ( "staticlibs not supported" )
1508+ }
1509+
1510+ fn link_whole_staticlib ( & mut self , _lib : Symbol , _verbatim : bool , _search_path : & [ PathBuf ] ) {
1511+ panic ! ( "staticlibs not supported" )
1512+ }
1513+
1514+ fn framework_path ( & mut self , _path : & Path ) {
1515+ panic ! ( "frameworks not supported" )
1516+ }
1517+
1518+ fn link_framework ( & mut self , _framework : Symbol , _as_needed : bool ) {
1519+ panic ! ( "frameworks not supported" )
1520+ }
1521+
1522+ fn full_relro ( & mut self ) { }
1523+
1524+ fn partial_relro ( & mut self ) { }
1525+
1526+ fn no_relro ( & mut self ) { }
1527+
1528+ fn gc_sections ( & mut self , _keep_metadata : bool ) { }
1529+
1530+ fn no_gc_sections ( & mut self ) { }
1531+
1532+ fn pgo_gen ( & mut self ) { }
1533+
1534+ fn no_crt_objects ( & mut self ) { }
1535+
1536+ fn no_default_libraries ( & mut self ) { }
1537+
1538+ fn control_flow_guard ( & mut self ) { }
1539+
1540+ fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) {
1541+ let path = tmpdir. join ( "symbols" ) ;
1542+ let res: io:: Result < ( ) > = try {
1543+ let mut f = BufWriter :: new ( File :: create ( & path) ?) ;
1544+ for sym in self . info . exports [ & crate_type] . iter ( ) {
1545+ writeln ! ( f, "{}" , sym) ?;
1546+ }
1547+ } ;
1548+ if let Err ( e) = res {
1549+ self . sess . fatal ( & format ! ( "failed to write symbols file: {}" , e) ) ;
1550+ } else {
1551+ self . cmd . arg ( "--export-symbols" ) . arg ( & path) ;
1552+ }
1553+ }
1554+
1555+ fn subsystem ( & mut self , _subsystem : & str ) { }
1556+
1557+ fn group_start ( & mut self ) { }
1558+
1559+ fn group_end ( & mut self ) { }
1560+
1561+ fn linker_plugin_lto ( & mut self ) { }
1562+ }
0 commit comments