简体   繁体   English

使用clang编译源代码时,LLVM中的选项“-Wl”是什么意思?

[英]What is the meaning of the option "-Wl" in LLVM while using clang to compile the source code?

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.我猜想使用选项“-Wl”可能会将选项后面的指令传输到linker。但我不知道该选项的含义。

Who can give me some solution or information?谁能给我一些解决方案或信息?

(I find anything about "-Wl" in llvm doc ( https://llvm.org/ )). (我在 llvm doc ( https://llvm.org/ ) 中找到了关于“-Wl”的任何信息)。

Clang's -Wl option is documented in its command line docs here: https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-wl-args Clang 的-Wl选项记录在其命令行文档中: https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-wl-args

-Wl,<args>

Pass the comma separated arguments in args to the linker.将 args 中的逗号分隔 arguments 传递给 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 的文档,因为 Clang 的-Wl选项的工作方式与 GCC 的完全相同(可能是链接到另一个 SO 问题的注释的含义)。 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 GCC 的标志记录在此处: 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.将选项作为选项传递给 linker。如果选项包含逗号,则在逗号处拆分为多个选项。 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.例如,-Wl,-Map,output.map 将 -Map output.map 传递给 linker。当使用 GNU linker 时,您也可以通过 -Wl,-Map=7.8682.4输出获得相同的效果

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.请注意,此选项仅在以实际调用 linker 的方式使用 Clang(或 GCC)时有效。如果您使用clang -c source.c -c表示 linker 将不会被调用,因此-Wl不会做任何事情。 You need to ask Clang to link an executable (or something else) like clang -o program -c source.c .您需要请求 Clang 链接可执行文件(或其他文件),例如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.您可以看到 Clang 如何调用 linker 并使用-v标志将任何选项传递给它。 For example, on macOS:例如,在 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.您可以在 output 的最后一行看到 linker 的调用,其中传递了-dead_strip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM