我有一个简单的 HelloWorld.c 程序(所以,我把它放在这里),我正在尝试使用启用 LTO 的 clang 版本 3.3 构建它会引发奇怪的错误。我正在cmake
使用-DCMAKE_TOOLCHAIN_FILE
. 我可以在没有 的情况下成功构建和链接该程序-flto
,但我需要能够使用此限定符。该工具链适用于 TileGX(因此需要保持在 clang 版本 3.3)。所以这是我的环境:
Ubuntu 16.04
cmake Version 3.9.4
I built the TileGX toolchain on 16.04, as well as 14.04
I build clang Version 3.3 on 16.04 (can't build it on 14.04)
这是我的CMakeLists.txt
文件:
cmake_minimum_required (VERSION 3.9)
project (HelloWorld)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v -flto -static")
add_executable(HelloWorld HelloWorld.c)
我添加了-v
标志,所以看看铿锵声中发生了什么。
尝试链接的 clang 的输出是(重新格式化以便于阅读):
clang version 3.3
Target: tilegx-unknown-linux-gnu
Thread model: posix
./toolchains/univ_tilegx/usr/bin/tilegx-unknown-linux-gnu-ld -m elf64tilegx \
-static -o HelloWorld \
./toolchains/univ_tilegx/usr/tilegx-unknown-linux-gnu/sys-root/usr/lib/crt1.o \
./toolchains/univ_tilegx/usr/tilegx-unknown-linux-gnu/sys-root/usr/lib/crti.o \
./toolchains/univ_tilegx/usr/lib/gcc/tilegx-unknown-linux-gnu/4.9.2/crtbeginT.o \
-L./toolchains/univ_tilegx/usr/tilegx-unknown-linux-gnu/lib \
-L./third_party/toolchains/univ_tilegx/usr/lib/gcc/tilegx-unknown-linux-gnu/4.9.2/ \
-L./toolchains/univ_tilegx/usr/tilegx-unknown-linux-gnu/lib \
-L./toolchains/univ_tilegx/usr/lib/gcc/tilegx-unknown-linux-gnu/4.9.2/ \
-L/lib/../lib64 -L/lib -L/usr/lib -plugin ../lib/LLVMgold.so \
CMakeFiles/HelloWorld.dir/HelloWorld.c.o \
--start-group \
-lgcc -lgcc_eh -lc
--end-group \
./toolchains/univ_tilegx/usr/lib/gcc/tilegx-unknown-linux-gnu/4.9.2/crtend.o \
./toolchains/univ_tilegx/usr/tilegx-unknown-linux-gnu/sys-root/usr/lib/crtn.o
./toolchains/univ_tilegx/usr/bin/tilegx-unknown-linux-gnu-ld: cannot find 0�: \
No such file or directory
./toolchains/univ_tilegx/usr/bin/tilegx-unknown-linux-gnu-ld: error:
Failed to delete '0�': 0�: can't get status of file: No such file or directory
clang-3.3: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/HelloWorld.dir/build.make:94: recipe for target 'HelloWorld' failed
make[2]: *** [HelloWorld] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/HelloWorld.dir/all' failed
make[1]: *** [CMakeFiles/HelloWorld.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
起初我认为这是使用LLVMgold.so
基于 Ubuntu 16.04 的可共享对象 () 和基于 14.04 的链接器的问题。链接器将调用可共享对象,然后该对象将回调链接器。但是,现在我有一个基于 16.04 的链接器,我仍然收到错误消息。
自从我构建以来,LLVMgold.so
我放置了一些代码来跟踪链接器调用可共享对象时发生的事情,但那里的一切看起来都很好。我可以看到ld
找不到一个奇怪命名的文件,但我不确定它可能在提供的一组文件中是哪个文件。
我已经尝试了我能想象到的一切,以便我可以-flto
在这个环境中使用。有没有人见过这个?有解决办法吗?还有其他我可以或应该做的事情吗?