@@ -3,7 +3,6 @@ use super::command::Command;
33use super :: symbol_export;
44use rustc_span:: symbol:: sym;
55
6- use std:: env;
76use std:: ffi:: { OsStr , OsString } ;
87use std:: fs:: { self , File } ;
98use std:: io:: prelude:: * ;
@@ -150,9 +149,7 @@ pub fn get_linker<'a>(
150149
151150 LinkerFlavor :: BpfLinker => Box :: new ( BpfLinker { cmd, sess } ) as Box < dyn Linker > ,
152151
153- LinkerFlavor :: L4Bender => {
154- Box :: new ( L4Bender :: new ( cmd, sess) ) as Box < dyn Linker >
155- } ,
152+ LinkerFlavor :: L4Bender => Box :: new ( L4Bender :: new ( cmd, sess) ) as Box < dyn Linker > ,
156153 }
157154}
158155
@@ -1367,10 +1364,10 @@ pub struct L4Bender<'a> {
13671364}
13681365
13691366impl < ' a > Linker for L4Bender < ' a > {
1370- fn link_dylib ( & mut self , _lib : Symbol ) {
1371- panic ! ( "dylibs not supported yet" )
1367+ fn link_dylib ( & mut self , _lib : Symbol , _verbatim : bool , _as_needed : bool ) {
1368+ bug ! ( "dylibs are not supported on L4Re" ) ;
13721369 }
1373- fn link_staticlib ( & mut self , lib : Symbol ) {
1370+ fn link_staticlib ( & mut self , lib : Symbol , _verbatim : bool ) {
13741371 self . hint_static ( ) ;
13751372 self . cmd . arg ( format ! ( "-PC{}" , lib) ) ;
13761373 }
@@ -1382,36 +1379,44 @@ impl<'a> Linker for L4Bender<'a> {
13821379 self . cmd . arg ( "-L" ) . arg ( path) ;
13831380 }
13841381 fn framework_path ( & mut self , _: & Path ) {
1385- bug ! ( "Frameworks are not supported on L4Re!" ) ;
1386- }
1387- fn output_filename ( & mut self , path : & Path ) { self . cmd . arg ( "-o" ) . arg ( path) ; }
1388- fn add_object ( & mut self , path : & Path ) { self . cmd . arg ( path) ; }
1389- // not sure about pie on L4Re
1390- fn position_independent_executable ( & mut self ) { }
1391- fn no_position_independent_executable ( & mut self ) { }
1392- fn full_relro ( & mut self ) { self . cmd . arg ( "-z,relro,-z,now" ) ; }
1393- fn partial_relro ( & mut self ) { self . cmd . arg ( "-z,relro" ) ; }
1394- fn no_relro ( & mut self ) { self . cmd . arg ( "-z,norelro" ) ; }
1395- fn build_static_executable ( & mut self ) { self . cmd . arg ( "-static" ) ; }
1382+ bug ! ( "frameworks are not supported on L4Re" ) ;
1383+ }
1384+ fn output_filename ( & mut self , path : & Path ) {
1385+ self . cmd . arg ( "-o" ) . arg ( path) ;
1386+ }
1387+
1388+ fn add_object ( & mut self , path : & Path ) {
1389+ self . cmd . arg ( path) ;
1390+ }
1391+
1392+ fn full_relro ( & mut self ) {
1393+ self . cmd . arg ( "-zrelro" ) ;
1394+ self . cmd . arg ( "-znow" ) ;
1395+ }
1396+
1397+ fn partial_relro ( & mut self ) {
1398+ self . cmd . arg ( "-zrelro" ) ;
1399+ }
1400+
1401+ fn no_relro ( & mut self ) {
1402+ self . cmd . arg ( "-znorelro" ) ;
1403+ }
1404+
13961405 fn cmd ( & mut self ) -> & mut Command {
13971406 & mut self . cmd
13981407 }
13991408
1409+ fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1410+
14001411 fn link_rust_dylib ( & mut self , _: Symbol , _: & Path ) {
14011412 panic ! ( "Rust dylibs not supported" ) ;
14021413 }
14031414
1404- fn link_framework ( & mut self , _ : Symbol ) {
1405- bug ! ( "Frameworks not supported on L4Re. " ) ;
1415+ fn link_framework ( & mut self , _framework : Symbol , _as_needed : bool ) {
1416+ bug ! ( "frameworks not supported on L4Re" ) ;
14061417 }
14071418
1408- // Here we explicitly ask that the entire archive is included into the
1409- // result artifact. For more details see #15460, but the gist is that
1410- // the linker will strip away any unused objects in the archive if we
1411- // don't otherwise explicitly reference them. This can occur for
1412- // libraries which are just providing bindings, libraries with generic
1413- // functions, etc.
1414- fn link_whole_staticlib ( & mut self , lib : Symbol , _: & [ PathBuf ] ) {
1419+ fn link_whole_staticlib ( & mut self , lib : Symbol , _verbatim : bool , _search_path : & [ PathBuf ] ) {
14151420 self . hint_static ( ) ;
14161421 self . cmd . arg ( "--whole-archive" ) . arg ( format ! ( "-l{}" , lib) ) ;
14171422 self . cmd . arg ( "--no-whole-archive" ) ;
@@ -1428,17 +1433,28 @@ impl<'a> Linker for L4Bender<'a> {
14281433 }
14291434 }
14301435
1436+ fn no_gc_sections ( & mut self ) {
1437+ self . cmd . arg ( "--no-gc-sections" ) ;
1438+ }
1439+
14311440 fn optimize ( & mut self ) {
1432- self . cmd . arg ( "-O2" ) ;
1441+ // GNU-style linkers support optimization with -O. GNU ld doesn't
1442+ // need a numeric argument, but other linkers do.
1443+ if self . sess . opts . optimize == config:: OptLevel :: Default
1444+ || self . sess . opts . optimize == config:: OptLevel :: Aggressive
1445+ {
1446+ self . cmd . arg ( "-O1" ) ;
1447+ }
14331448 }
14341449
1435- fn pgo_gen ( & mut self ) { }
1450+ fn pgo_gen ( & mut self ) { }
14361451
14371452 fn debuginfo ( & mut self , strip : Strip ) {
14381453 match strip {
14391454 Strip :: None => { }
14401455 Strip :: Debuginfo => {
1441- self . cmd ( ) . arg ( "--strip-debug" ) ; }
1456+ self . cmd ( ) . arg ( "--strip-debug" ) ;
1457+ }
14421458 Strip :: Symbols => {
14431459 self . cmd ( ) . arg ( "--strip-all" ) ;
14441460 }
@@ -1449,72 +1465,38 @@ impl<'a> Linker for L4Bender<'a> {
14491465 self . cmd . arg ( "-nostdlib" ) ;
14501466 }
14511467
1452- fn build_dylib ( & mut self , _: & Path ) {
1453- bug ! ( "not implemented" ) ;
1454- }
1455-
1456- fn export_symbols ( & mut self , _: & Path , _: CrateType ) {
1468+ fn export_symbols ( & mut self , _: & Path , _: CrateType , _: & [ String ] ) {
14571469 // ToDo, not implemented, copy from GCC
1470+ self . sess . warn ( "exporting symbols not implemented yet for L4Bender" ) ;
14581471 return ;
14591472 }
14601473
14611474 fn subsystem ( & mut self , subsystem : & str ) {
1462- self . cmd . arg ( & format ! ( "--subsystem, {}" , subsystem) ) ;
1475+ self . cmd . arg ( & format ! ( "--subsystem {}" , subsystem) ) ;
14631476 }
14641477
1465- fn finalize ( & mut self ) {
1478+ fn reset_per_library_state ( & mut self ) {
14661479 self . hint_static ( ) ; // Reset to default before returning the composed command line.
14671480 }
14681481
1469- fn group_start ( & mut self ) { self . cmd . arg ( "--start-group" ) ; }
1470- fn group_end ( & mut self ) { self . cmd . arg ( "--end-group" ) ; }
1471- fn linker_plugin_lto ( & mut self ) {
1472- // do nothing
1473- }
1474- fn control_flow_guard ( & mut self ) {
1475- self . sess . warn ( "Windows Control Flow Guard is not supported by this linker." ) ;
1482+ fn group_start ( & mut self ) {
1483+ self . cmd . arg ( "--start-group" ) ;
14761484 }
14771485
1478- fn no_crt_objects ( & mut self ) { }
1479- }
1486+ fn group_end ( & mut self ) {
1487+ self . cmd . arg ( "--end-group" ) ;
1488+ }
14801489
1481- impl < ' a > L4Bender < ' a > {
1482- pub fn new ( mut cmd : Command , sess : & ' a Session ) -> L4Bender < ' a > {
1483- if let Ok ( l4bender_args) = env:: var ( "L4_BENDER_ARGS" ) {
1484- L4Bender :: split_cmd_args ( & mut cmd, & l4bender_args) ;
1485- }
1490+ fn linker_plugin_lto ( & mut self ) { }
14861491
1487- cmd . arg ( "--" ) ; // separate direct l4-bender args from linker args
1492+ fn control_flow_guard ( & mut self ) { }
14881493
1489- L4Bender {
1490- cmd : cmd,
1491- sess : sess,
1492- hinted_static : false ,
1493- }
1494- }
1494+ fn no_crt_objects ( & mut self ) { }
1495+ }
14951496
1496- /// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to
1497- /// completely understand shell, but should instead allow passing arguments like
1498- /// `-Dlinker="ld -m x86_64"`, and a copy without quotes, but spaces preserved, is added as an
1499- /// argument to the given Command. This means that constructs as \" are not understood, so
1500- /// quote wisely.
1501- fn split_cmd_args ( cmd : & mut Command , shell_args : & str ) {
1502- let mut arg = String :: new ( ) ;
1503- let mut quoted = false ;
1504- for character in shell_args. chars ( ) {
1505- match character {
1506- ' ' if !quoted => {
1507- cmd. arg ( & arg) ;
1508- arg. clear ( ) ;
1509- } ,
1510- '"' | '\'' => quoted = !quoted,
1511- _ => arg. push ( character) ,
1512- } ;
1513- }
1514- if arg. len ( ) > 0 {
1515- cmd. arg ( & arg) ;
1516- arg. clear ( ) ;
1517- }
1497+ impl < ' a > L4Bender < ' a > {
1498+ pub fn new ( cmd : Command , sess : & ' a Session ) -> L4Bender < ' a > {
1499+ L4Bender { cmd : cmd, sess : sess, hinted_static : false }
15181500 }
15191501
15201502 fn hint_static ( & mut self ) {
0 commit comments