@@ -3,6 +3,8 @@ use super::command::Command;
33use super :: symbol_export;
44use rustc_span:: symbol:: sym;
55
6+ use rustc_data_structures:: fx:: FxHashMap ;
7+ use std:: env;
68use std:: ffi:: { OsStr , OsString } ;
79use std:: fs:: { self , File } ;
810use std:: io:: prelude:: * ;
@@ -78,11 +80,7 @@ impl LinkerInfo {
7880 }
7981
8082 LinkerFlavor :: L4Bender => {
81- Box :: new ( L4Bender {
82- cmd,
83- sess,
84- hinted_static : false ,
85- } ) as Box < dyn Linker >
83+ Box :: new ( L4Bender :: new ( cmd, sess) ) as Box < dyn Linker >
8684 } ,
8785 LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => {
8886 Box :: new ( WasmLd :: new ( cmd, sess, self ) ) as Box < dyn Linker >
@@ -1364,9 +1362,11 @@ impl<'a> Linker for L4Bender<'a> {
13641362 fn pgo_gen ( & mut self ) { }
13651363
13661364 fn debuginfo ( & mut self ) {
1367- // for documentation, see GccLinker.debuginfo()
13681365 match self . sess . opts . debuginfo {
1369- DebugInfoLevel :: NoDebugInfo => {
1366+ DebugInfo :: None => {
1367+ // If we are building without debuginfo enabled and we were called with
1368+ // `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
1369+ // found when linking to get rid of symbols from libstd.
13701370 match self . sess . opts . debugging_opts . strip_debuginfo_if_disabled {
13711371 Some ( true ) => { self . cmd . arg ( "-S" ) ; } ,
13721372 _ => { } ,
@@ -1407,6 +1407,47 @@ impl<'a> Linker for L4Bender<'a> {
14071407}
14081408
14091409impl < ' a > L4Bender < ' a > {
1410+ pub fn new ( mut cmd : Command , sess : & ' a Session ) -> L4Bender < ' a > {
1411+ if let Ok ( l4bender_args) = env:: var ( "L4_BENDER_ARGS" ) {
1412+ L4Bender :: split_cmd_args ( & mut cmd, & l4bender_args) ;
1413+ }
1414+
1415+ cmd. arg ( "--" ) ; // separate direct l4-bender args from linker args
1416+
1417+ if let Ok ( l4_ld_opts) = env:: var ( "L4_LD_OPTIONS" ) {
1418+ L4Bender :: split_cmd_args ( & mut cmd, & l4_ld_opts) ;
1419+ }
1420+
1421+ L4Bender { cmd : cmd,
1422+ sess : sess,
1423+ hinted_static : false ,
1424+ }
1425+ }
1426+
1427+ /// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to
1428+ /// completely understand shell, but should instead allow passing arguments like
1429+ /// `-Dlinker="ld -m x86_64"`, and a copy without quotes, but spaces preserved, is added as an
1430+ /// argument to the given Command. This means that constructs as \" are not understood, so
1431+ /// quote wisely.
1432+ fn split_cmd_args ( cmd : & mut Command , shell_args : & str ) {
1433+ let mut arg = String :: new ( ) ;
1434+ let mut quoted = false ;
1435+ for character in shell_args. chars ( ) {
1436+ match character {
1437+ ' ' if !quoted => {
1438+ cmd. arg ( & arg) ;
1439+ arg. clear ( ) ;
1440+ } ,
1441+ '"' | '\'' => quoted = !quoted,
1442+ _ => arg. push ( character) ,
1443+ } ;
1444+ if arg. len ( ) > 0 {
1445+ cmd. arg ( & arg) ;
1446+ arg. clear ( ) ;
1447+ }
1448+ }
1449+ }
1450+
14101451 fn hint_static ( & mut self ) {
14111452 if !self . hinted_static {
14121453 self . cmd . arg ( "-static" ) ;
0 commit comments