@@ -3,7 +3,6 @@ use super::command::Command;
3
3
use super :: symbol_export;
4
4
use rustc_span:: symbol:: sym;
5
5
6
- use std:: env;
7
6
use std:: ffi:: { OsStr , OsString } ;
8
7
use std:: fs:: { self , File } ;
9
8
use std:: io:: prelude:: * ;
@@ -150,9 +149,7 @@ pub fn get_linker<'a>(
150
149
151
150
LinkerFlavor :: BpfLinker => Box :: new ( BpfLinker { cmd, sess } ) as Box < dyn Linker > ,
152
151
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 > ,
156
153
}
157
154
}
158
155
@@ -1367,10 +1364,10 @@ pub struct L4Bender<'a> {
1367
1364
}
1368
1365
1369
1366
impl < ' 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" ) ;
1372
1369
}
1373
- fn link_staticlib ( & mut self , lib : Symbol ) {
1370
+ fn link_staticlib ( & mut self , lib : Symbol , _verbatim : bool ) {
1374
1371
self . hint_static ( ) ;
1375
1372
self . cmd . arg ( format ! ( "-PC{}" , lib) ) ;
1376
1373
}
@@ -1382,36 +1379,44 @@ impl<'a> Linker for L4Bender<'a> {
1382
1379
self . cmd . arg ( "-L" ) . arg ( path) ;
1383
1380
}
1384
1381
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
+
1396
1405
fn cmd ( & mut self ) -> & mut Command {
1397
1406
& mut self . cmd
1398
1407
}
1399
1408
1409
+ fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1410
+
1400
1411
fn link_rust_dylib ( & mut self , _: Symbol , _: & Path ) {
1401
1412
panic ! ( "Rust dylibs not supported" ) ;
1402
1413
}
1403
1414
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" ) ;
1406
1417
}
1407
1418
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 ] ) {
1415
1420
self . hint_static ( ) ;
1416
1421
self . cmd . arg ( "--whole-archive" ) . arg ( format ! ( "-l{}" , lib) ) ;
1417
1422
self . cmd . arg ( "--no-whole-archive" ) ;
@@ -1428,17 +1433,28 @@ impl<'a> Linker for L4Bender<'a> {
1428
1433
}
1429
1434
}
1430
1435
1436
+ fn no_gc_sections ( & mut self ) {
1437
+ self . cmd . arg ( "--no-gc-sections" ) ;
1438
+ }
1439
+
1431
1440
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
+ }
1433
1448
}
1434
1449
1435
- fn pgo_gen ( & mut self ) { }
1450
+ fn pgo_gen ( & mut self ) { }
1436
1451
1437
1452
fn debuginfo ( & mut self , strip : Strip ) {
1438
1453
match strip {
1439
1454
Strip :: None => { }
1440
1455
Strip :: Debuginfo => {
1441
- self . cmd ( ) . arg ( "--strip-debug" ) ; }
1456
+ self . cmd ( ) . arg ( "--strip-debug" ) ;
1457
+ }
1442
1458
Strip :: Symbols => {
1443
1459
self . cmd ( ) . arg ( "--strip-all" ) ;
1444
1460
}
@@ -1449,72 +1465,38 @@ impl<'a> Linker for L4Bender<'a> {
1449
1465
self . cmd . arg ( "-nostdlib" ) ;
1450
1466
}
1451
1467
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 ] ) {
1457
1469
// ToDo, not implemented, copy from GCC
1470
+ self . sess . warn ( "exporting symbols not implemented yet for L4Bender" ) ;
1458
1471
return ;
1459
1472
}
1460
1473
1461
1474
fn subsystem ( & mut self , subsystem : & str ) {
1462
- self . cmd . arg ( & format ! ( "--subsystem, {}" , subsystem) ) ;
1475
+ self . cmd . arg ( & format ! ( "--subsystem {}" , subsystem) ) ;
1463
1476
}
1464
1477
1465
- fn finalize ( & mut self ) {
1478
+ fn reset_per_library_state ( & mut self ) {
1466
1479
self . hint_static ( ) ; // Reset to default before returning the composed command line.
1467
1480
}
1468
1481
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" ) ;
1476
1484
}
1477
1485
1478
- fn no_crt_objects ( & mut self ) { }
1479
- }
1486
+ fn group_end ( & mut self ) {
1487
+ self . cmd . arg ( "--end-group" ) ;
1488
+ }
1480
1489
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 ) { }
1486
1491
1487
- cmd . arg ( "--" ) ; // separate direct l4-bender args from linker args
1492
+ fn control_flow_guard ( & mut self ) { }
1488
1493
1489
- L4Bender {
1490
- cmd : cmd,
1491
- sess : sess,
1492
- hinted_static : false ,
1493
- }
1494
- }
1494
+ fn no_crt_objects ( & mut self ) { }
1495
+ }
1495
1496
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 }
1518
1500
}
1519
1501
1520
1502
fn hint_static ( & mut self ) {
0 commit comments