|
| 1 | +# `linker-flavor` |
| 2 | + |
| 3 | +The tracking issue for this feature is: None |
| 4 | + |
| 5 | +------------------------ |
| 6 | + |
| 7 | +Every `rustc` target defaults to some linker. For example, Linux targets default |
| 8 | +to gcc. In some cases, you may want to override the default; you can do that |
| 9 | +with the unstable CLI argument: `-Z linker-flavor`. |
| 10 | + |
| 11 | +Here how you would use this flag to link a Rust binary for the |
| 12 | +`thumbv7m-none-eabi` using LLD instead of GCC. |
| 13 | + |
| 14 | +``` text |
| 15 | +$ xargo rustc --target thumbv7m-none-eabi -- \ |
| 16 | + -C linker=ld.lld \ |
| 17 | + -Z linker-flavor=ld \ |
| 18 | + -Z print-link-args | tr ' ' '\n' |
| 19 | +"ld.lld" |
| 20 | +"-L" |
| 21 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" |
| 22 | +"$PWD/target/thumbv7m-none-eabi/debug/deps/app-512e9dbf385f233c.0.o" |
| 23 | +"-o" |
| 24 | +"$PWD/target/thumbv7m-none-eabi/debug/deps/app-512e9dbf385f233c" |
| 25 | +"--gc-sections" |
| 26 | +"-L" |
| 27 | +"$PWD/target/thumbv7m-none-eabi/debug/deps" |
| 28 | +"-L" |
| 29 | +"$PWD/target/debug/deps" |
| 30 | +"-L" |
| 31 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" |
| 32 | +"-Bstatic" |
| 33 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib/libcore-e1ccb7dfb1cb9ebb.rlib" |
| 34 | +"-Bdynamic" |
| 35 | +``` |
| 36 | + |
| 37 | +Whereas the default is: |
| 38 | + |
| 39 | +``` |
| 40 | +$ xargo rustc --target thumbv7m-none-eabi -- \ |
| 41 | + -C link-arg=-nostartfiles \ |
| 42 | + -Z print-link-args | tr ' ' '\n' |
| 43 | +"arm-none-eabi-gcc" |
| 44 | +"-L" |
| 45 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" |
| 46 | +"$PWD/target/thumbv7m-none-eabi/debug/deps/app-961e39416baa38d9.0.o" |
| 47 | +"-o" |
| 48 | +"$PWD/target/thumbv7m-none-eabi/debug/deps/app-961e39416baa38d9" |
| 49 | +"-Wl,--gc-sections" |
| 50 | +"-nodefaultlibs" |
| 51 | +"-L" |
| 52 | +"$PWD/target/thumbv7m-none-eabi/debug/deps" |
| 53 | +"-L" |
| 54 | +"$PWD/target/debug/deps" |
| 55 | +"-L" |
| 56 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" |
| 57 | +"-Wl,-Bstatic" |
| 58 | +"$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib/libcore-e1ccb7dfb1cb9ebb.rlib" |
| 59 | +"-nostartfiles" |
| 60 | +"-Wl,-Bdynamic" |
| 61 | +``` |
0 commit comments