@@ -126,7 +126,6 @@ pub fn get_linker<'a>(
126
126
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
127
127
// to the linker args construction.
128
128
assert ! ( cmd. get_args( ) . is_empty( ) || sess. target. vendor == "uwp" ) ;
129
-
130
129
match flavor {
131
130
LinkerFlavor :: Lld ( LldFlavor :: Link ) | LinkerFlavor :: Msvc => {
132
131
Box :: new ( MsvcLinker { cmd, sess } ) as Box < dyn Linker >
@@ -149,6 +148,8 @@ pub fn get_linker<'a>(
149
148
LinkerFlavor :: PtxLinker => Box :: new ( PtxLinker { cmd, sess } ) as Box < dyn Linker > ,
150
149
151
150
LinkerFlavor :: BpfLinker => Box :: new ( BpfLinker { cmd, sess } ) as Box < dyn Linker > ,
151
+
152
+ LinkerFlavor :: L4Bender => Box :: new ( L4Bender :: new ( cmd, sess) ) as Box < dyn Linker > ,
152
153
}
153
154
}
154
155
@@ -1355,6 +1356,157 @@ impl<'a> Linker for WasmLd<'a> {
1355
1356
}
1356
1357
}
1357
1358
1359
+ /// Linker shepherd script for L4Re (Fiasco)
1360
+ pub struct L4Bender < ' a > {
1361
+ cmd : Command ,
1362
+ sess : & ' a Session ,
1363
+ hinted_static : bool ,
1364
+ }
1365
+
1366
+ impl < ' a > Linker for L4Bender < ' a > {
1367
+ fn link_dylib ( & mut self , _lib : Symbol , _verbatim : bool , _as_needed : bool ) {
1368
+ bug ! ( "dylibs are not supported on L4Re" ) ;
1369
+ }
1370
+ fn link_staticlib ( & mut self , lib : Symbol , _verbatim : bool ) {
1371
+ self . hint_static ( ) ;
1372
+ self . cmd . arg ( format ! ( "-PC{}" , lib) ) ;
1373
+ }
1374
+ fn link_rlib ( & mut self , lib : & Path ) {
1375
+ self . hint_static ( ) ;
1376
+ self . cmd . arg ( lib) ;
1377
+ }
1378
+ fn include_path ( & mut self , path : & Path ) {
1379
+ self . cmd . arg ( "-L" ) . arg ( path) ;
1380
+ }
1381
+ fn framework_path ( & mut self , _: & Path ) {
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
+
1405
+ fn cmd ( & mut self ) -> & mut Command {
1406
+ & mut self . cmd
1407
+ }
1408
+
1409
+ fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1410
+
1411
+ fn link_rust_dylib ( & mut self , _: Symbol , _: & Path ) {
1412
+ panic ! ( "Rust dylibs not supported" ) ;
1413
+ }
1414
+
1415
+ fn link_framework ( & mut self , _framework : Symbol , _as_needed : bool ) {
1416
+ bug ! ( "frameworks not supported on L4Re" ) ;
1417
+ }
1418
+
1419
+ fn link_whole_staticlib ( & mut self , lib : Symbol , _verbatim : bool , _search_path : & [ PathBuf ] ) {
1420
+ self . hint_static ( ) ;
1421
+ self . cmd . arg ( "--whole-archive" ) . arg ( format ! ( "-l{}" , lib) ) ;
1422
+ self . cmd . arg ( "--no-whole-archive" ) ;
1423
+ }
1424
+
1425
+ fn link_whole_rlib ( & mut self , lib : & Path ) {
1426
+ self . hint_static ( ) ;
1427
+ self . cmd . arg ( "--whole-archive" ) . arg ( lib) . arg ( "--no-whole-archive" ) ;
1428
+ }
1429
+
1430
+ fn gc_sections ( & mut self , keep_metadata : bool ) {
1431
+ if !keep_metadata {
1432
+ self . cmd . arg ( "--gc-sections" ) ;
1433
+ }
1434
+ }
1435
+
1436
+ fn no_gc_sections ( & mut self ) {
1437
+ self . cmd . arg ( "--no-gc-sections" ) ;
1438
+ }
1439
+
1440
+ fn optimize ( & mut self ) {
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
+ }
1448
+ }
1449
+
1450
+ fn pgo_gen ( & mut self ) { }
1451
+
1452
+ fn debuginfo ( & mut self , strip : Strip ) {
1453
+ match strip {
1454
+ Strip :: None => { }
1455
+ Strip :: Debuginfo => {
1456
+ self . cmd ( ) . arg ( "--strip-debug" ) ;
1457
+ }
1458
+ Strip :: Symbols => {
1459
+ self . cmd ( ) . arg ( "--strip-all" ) ;
1460
+ }
1461
+ }
1462
+ }
1463
+
1464
+ fn no_default_libraries ( & mut self ) {
1465
+ self . cmd . arg ( "-nostdlib" ) ;
1466
+ }
1467
+
1468
+ fn export_symbols ( & mut self , _: & Path , _: CrateType , _: & [ String ] ) {
1469
+ // ToDo, not implemented, copy from GCC
1470
+ self . sess . warn ( "exporting symbols not implemented yet for L4Bender" ) ;
1471
+ return ;
1472
+ }
1473
+
1474
+ fn subsystem ( & mut self , subsystem : & str ) {
1475
+ self . cmd . arg ( & format ! ( "--subsystem {}" , subsystem) ) ;
1476
+ }
1477
+
1478
+ fn reset_per_library_state ( & mut self ) {
1479
+ self . hint_static ( ) ; // Reset to default before returning the composed command line.
1480
+ }
1481
+
1482
+ fn group_start ( & mut self ) {
1483
+ self . cmd . arg ( "--start-group" ) ;
1484
+ }
1485
+
1486
+ fn group_end ( & mut self ) {
1487
+ self . cmd . arg ( "--end-group" ) ;
1488
+ }
1489
+
1490
+ fn linker_plugin_lto ( & mut self ) { }
1491
+
1492
+ fn control_flow_guard ( & mut self ) { }
1493
+
1494
+ fn no_crt_objects ( & mut self ) { }
1495
+ }
1496
+
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 }
1500
+ }
1501
+
1502
+ fn hint_static ( & mut self ) {
1503
+ if !self . hinted_static {
1504
+ self . cmd . arg ( "-static" ) ;
1505
+ self . hinted_static = true ;
1506
+ }
1507
+ }
1508
+ }
1509
+
1358
1510
pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1359
1511
if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
1360
1512
return exports. clone ( ) ;
0 commit comments