【问题标题】:How can I link files compiled with clang -flto using lld?如何使用 lld 链接使用 clang -flto 编译的文件?
【发布时间】:2015-08-26 22:19:00
【问题描述】:

我正在尝试使用 llvm-lld 链接已使用 -flto 编译的对象。

我在路径调用 lld 中有 ld,并提供了所有参数。 我创建了一个简单的 C++ 程序,用 clang++ 编译:

#include <stdio.h>
int main() {
    printf("Goodbye cruel world\n");
    return 0;
}

没有 -flto 标志我得到一个可执行文件,使用 -flto 我得到这个错误:

warning: ignoring unknown argument: -plugin
warning: ignoring unknown argument: -plugin-opt=mcpu=x86-64
Cannot open /tmp/a-f1a2a7.o: Exec format error
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)

这是传递给链接器的参数,我看到使用 -flto 提供的插件参数包括此插件选项,但似乎不受支持。

--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../.. -L/mnt/data/tmp/dev/llvm/prev/bin/../lib -L/lib -L/usr/lib -plugin /mnt/data/tmp/dev/llvm/prev/bin/../lib/LLVMgold.so -plugin-opt=mcpu=x86-64 /tmp/a-f1a2a7.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crtn.o

有没有办法让 lld 链接这段代码?

【问题讨论】:

    标签: clang llvm lld


    【解决方案1】:

    是的,您可以使用通过插件支持 LTO 的 gold-linker 来实现:

    Here is the instructions how to build and run it

    【讨论】:

    • 所以插件会被lld或者binutil的ld使用(相信编译插件的时候需要指定binutil的headers的路径)?
    • 黄金不是 lld。我错过了什么吗?
    猜你喜欢
    • 2021-03-19
    • 2012-01-19
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    相关资源
    最近更新 更多