Clang无法正确调用LLD

发布于 2025-01-25 04:00:36 字数 2835 浏览 3 评论 0原文

我准备了两个非常简单的C文件,Main.C和test.c,并使用以下命令来编译它们:
clang -target = aarch64 -c main.c
clang -target = aarch64 -c test.c

但是当我使用命令clang -target = aarch64 -fuse-ld = lld -v main.o test.o ,它实际上是调用“/usr/bin/gcc” -fuse-ld = lld

root@6ab3fca322b6:/home/home/example#clang -target = aarch64 -fuse -ld = lld = lld = lld -v main.o test.o
Clang版本13.0.0
目标:Aarch64
线程模型:POSIX
installeddir:/usr/local/bin
“/usr/bin/gcc” -fuse-ld = lld -o a.out main.o test.o
ld.lld:错误:main.o与ELF64-X86-64
不兼容 ld.lld:错误:test.o与ELF64-x86-64
不兼容 collect2:错误:ld返回1退出状态
clang -13:错误:Linker(通过GCC)命令失败,出口代码1(使用-v查看调用)

但是如果我手动调用ld.lld,一切都没有问题,只是关于警告“找不到输入符号_start;”。
ld.lld main.o test.o

我也尝试删除标志 - target = aarch64 ,它仍然失败: root@6ab3fca322b6:/ home/示例#clang -v main.o test.o
Clang版本13.0.0
目标:x86_64-Inninnown-linux-gnu
线程模型:POSIX
installeddir:/usr/local/bin
找到候选GCC安装:/usr/lib/gcc/x86_64-linux-gnu/9
选定的GCC安装:/usr/lib/gcc/x86_64-linux-gnu/9
候选人Multilib:。;@m64
候选Multilib:32;@M32
候选人Multilib:x32;@mx32
选定的Multilib:。;@M64
“/usr/bin/ld” -z relro -hash-style = gnu -eh-frame-hdr -m elf_x86_64 -dynamic-linker/lib64/ld-linux-x86-x86-64.so.2-- o a.out/lib/x86_64-linux-gnu/crt1.o/lib/x86_64-linux-gnu/crti.o/usr/lib/gcc/gcc/x86_64-linux-gnu/9/crtbegin.o-crtbegin.o -l/usr /lib/gcc/x86_64-linux-gnu/9 -l/usr/lib/lib/x86_64-linux-gnu/9 /../../../../../../../../ lib64 -l/lib/x86_64-linux -gnu -l/lib /../ lib64 -l/usr/lib/x86_64 -linux -gnu -l/usr/lib /../ lib64 -l/usr/usr/local/bin /../ lib -l/lib -l/ lib -l/usr/lib main.o test.o -lgcc -As -as -as -as -lgcc_s -no -as -as -needed -lc -lgcc -lgcc -as -as -as -as -as -as -lgcc_s -no -as -as -as -as -no -as -need/usr/usr/ lib/gcc/x86_64-linux-gnu/9/crtend.o/lib/x86_64-linux-gnu/crtn.o
ld:错误:main.o与ELF64-x86-64
不兼容 ld:错误:test.o与ELF64-X86-64
不兼容 clang -13:错误:Linker命令因出口代码1失败(使用-V查看调用)

我的soft链接to/usr/bin/ld to/usr/bin/bin/ld.lld,但是我不知道为什么它会添加一些我不指定的标志,例如-z relro -hash-style = gnu -eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64 /lib64 / ld-linux-x86-64.so.2

所以我的问题是:

  1. 为什么clang -target = aarch64 -fuse-ld = lld无法调用ld.lld?
  2. 为什么clang可以调用/usr/bin/ld,但添加一些未指定的标志?
  3. 对于Aarch64,这是正确调用ld.lld的正确方法?

我正在使用Clang和LLD 13.0.0。

最好的问候,
西蒙

I prepare two very simple c files, main.c and test.c, and use the below command to compile them:
clang --target=aarch64 -c main.c
clang --target=aarch64 -c test.c

But when I use the command clang --target=aarch64 -fuse-ld=lld -v main.o test.o, it actually invoke "/usr/bin/gcc" -fuse-ld=lld

root@6ab3fca322b6:/home/example# clang --target=aarch64 -fuse-ld=lld -v main.o test.o
clang version 13.0.0
Target: aarch64
Thread model: posix
InstalledDir: /usr/local/bin
"/usr/bin/gcc" -fuse-ld=lld -o a.out main.o test.o
ld.lld: error: main.o is incompatible with elf64-x86-64
ld.lld: error: test.o is incompatible with elf64-x86-64
collect2: error: ld returned 1 exit status
clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

But if I manually invoke ld.lld, everything there is no problem just a warning about "cannot find entry symbol _start;".
ld.lld main.o test.o

Also I try to remove the flag --target=aarch64, it still failed:
root@6ab3fca322b6:/home/example# clang -v main.o test.o
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/x86_64-linux-gnu/crt1.o /lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/local/bin/../lib -L/lib -L/usr/lib main.o test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o /lib/x86_64-linux-gnu/crtn.o
ld: error: main.o is incompatible with elf64-x86-64
ld: error: test.o is incompatible with elf64-x86-64
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

I have soft linked the /usr/bin/ld to /usr/bin/ld.lld, but I don't know why it adds some many flags which I don't specify, e.g., -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2

So my questions are:

  1. why clang --target=aarch64 -fuse-ld=lld can't invoke ld.lld?
  2. why clang can invoke /usr/bin/ld but add some many unspecified flags?
  3. For aarch64, which is the correct way to make clang correctly invoke ld.lld?

I am using clang and lld 13.0.0.

Best Regards,
Simon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文