0

I guess that using the option "-Wl" may transmit the instruction next the option to linker. But i don't know the meaning of the option.

Who can give me some solution or information?

(I find anything about "-Wl" in llvm doc (https://llvm.org/)).

Danny
  • 1

1 Answers1

0

Clang's -Wl option is documented in its command line docs here: https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-wl-args

-Wl,<args>

Pass the comma separated arguments in args to the linker.

For more details, you caan look at GCC's documentation as Clang's -Wl option works the exact same as GCC's (likely the meaning of the comment linking to another SO question). GCC's flag is documented here: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Link-Options.html#Link-Options:~:text=command%2Dline%20options.-,%2DWl%2Coption,-Pass%20option%20as

-Wl,option

Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this syntax to pass an argument to the option. For example, -Wl,-Map,output.map passes -Map output.map to the linker. When using the GNU linker, you can also get the same effect with -Wl,-Map=output.map.

Note that this option will only have an effect when using Clang (or GCC) in a way that actually invokes the linker. If you use clang -c source.c the -c means the linker won't be invoked, and so -Wl won't do anything. You need to ask Clang to link an executable (or something else) like clang -o program -c source.c.

You can see how Clang is invoking the linker and passing any options to it using the -v flag. For example, on macOS:

> clang -v -Wl,-dead_strip -o program source.c
Homebrew clang version 15.0.6
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
 "/opt/homebrew/Cellar/llvm/15.0.6/bin/clang-15" -cc1 -triple arm64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name source.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +crc -target-feature +lse -target-feature +rdm -target-feature +crypto -target-feature +dotprod -target-feature +fp-armv8 -target-feature +neon -target-feature +fp16fml -target-feature +ras -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 820.1 -v -fcoverage-compilation-dir=/Users/chandlerc -resource-dir /opt/homebrew/Cellar/llvm/15.0.6/lib/clang/15.0.6 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/15.0.6/lib/clang/15.0.6/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include -fdebug-compilation-dir=/Users/chandlerc -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/zf/q19yfy9x307372t2ql26l5zc0028bd/T/source-936fab.o -x c source.c
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target arm64-apple-darwin21.6.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/Cellar/llvm/15.0.6/lib/clang/15.0.6/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -lto_library /opt/homebrew/Cellar/llvm/15.0.6/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 12.0.0 12.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -o program -dead_strip /var/folders/zf/q19yfy9x307372t2ql26l5zc0028bd/T/source-936fab.o -lSystem /opt/homebrew/Cellar/llvm/15.0.6/lib/clang/15.0.6/lib/darwin/libclang_rt.osx.a

You can see on the last line of the output the invocation of the linker where -dead_strip is passed.

Chandler Carruth
  • 3,011
  • 1
  • 18
  • 26