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