@@ -3,6 +3,8 @@ use super::command::Command;
3
3
use super :: symbol_export;
4
4
use rustc_span:: symbol:: sym;
5
5
6
+ use rustc_data_structures:: fx:: FxHashMap ;
7
+ use std:: env;
6
8
use std:: ffi:: { OsStr , OsString } ;
7
9
use std:: fs:: { self , File } ;
8
10
use std:: io:: prelude:: * ;
@@ -78,11 +80,7 @@ impl LinkerInfo {
78
80
}
79
81
80
82
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 >
86
84
} ,
87
85
LinkerFlavor :: Lld ( LldFlavor :: Wasm ) => {
88
86
Box :: new ( WasmLd :: new ( cmd, sess, self ) ) as Box < dyn Linker >
@@ -1364,9 +1362,11 @@ impl<'a> Linker for L4Bender<'a> {
1364
1362
fn pgo_gen ( & mut self ) { }
1365
1363
1366
1364
fn debuginfo ( & mut self ) {
1367
- // for documentation, see GccLinker.debuginfo()
1368
1365
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.
1370
1370
match self . sess . opts . debugging_opts . strip_debuginfo_if_disabled {
1371
1371
Some ( true ) => { self . cmd . arg ( "-S" ) ; } ,
1372
1372
_ => { } ,
@@ -1407,6 +1407,47 @@ impl<'a> Linker for L4Bender<'a> {
1407
1407
}
1408
1408
1409
1409
impl < ' 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
+
1410
1451
fn hint_static ( & mut self ) {
1411
1452
if !self . hinted_static {
1412
1453
self . cmd . arg ( "-static" ) ;
0 commit comments