将自动工具项目编译为LLVM位代码时出现链接器错误

问题描述 投票:3回答:1

我按照http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html#compiling-llvm-from-source-with-gold-plugin上的说明尝试将包括coreutils在内的各种项目编译为LLVM IR。

我尝试使用Clang 3.4和一个简单的测试文件在Ubuntu 14.04上测试我的安装,>

clang -flto -fuse-ld=gold -Wl,-plugin-opt=also-emit-llvm test.o

如上所述,但失败了>>

test.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)

但是,在添加参数-B/usr/lib/gold-ld之后,我可以编译测试文件。

仍然,编译coreutils失败,并出现以下错误:

/usr/lib/gold-ld/ld: error: src/libver.a: no archive symbol table (run ranlib)
/usr/lib/gold-ld/ld: error: lib/libcoreutils.a: no archive symbol table (run ranlib)
/usr/lib/gold-ld/ld: error: lib/libcoreutils.a: no archive symbol table (run ranlib)
/tmp/lto-llvm-dc31af.o:ld-temp.o:function usage: error: undefined reference to 'program_name'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function usage: error: undefined reference to 'quote'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function usage: error: undefined reference to 'program_name'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'set_program_name'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'exit_failure'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'close_stdout'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'parse_user_spec'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'xgetgroups'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'quote'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'parse_user_spec'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'xgetgroups'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'quote'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'Version'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'version_etc'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function main: error: undefined reference to 'quote'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function parse_additional_groups: error: undefined reference to 'xstrdup'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function parse_additional_groups: error: undefined reference to 'xstrtoul'
/tmp/lto-llvm-dc31af.o:ld-temp.o:function parse_additional_groups: error: undefined reference to 'x2nrealloc'

最后执行的命令是:

clang -flto -B/usr/lib/gold-ld  -Wl,--as-needed -flto  -B/usr/lib/gold-ld -fuse-ld=gold -Wl,-plugin-opt=also-emit-llvm  -o src/chroot src/chroot.o src/libver.a lib/libcoreutils.a  lib/libcoreutils.a 

在libver.a和libcoreutils.a上手动执行llvm-ranlib不会更改结果。执行llvm-nm -s src/libver.a将打印以下内容:

 D Version

但是,对于普通的构建,输出如下:

Archive map
Version in version.o

version.o:
00000000 D Version

llvm-ranlib是否有问题?您对如何解决链接器错误有任何建议?

我按照http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html#compiling-llvm-from-source-with-gold-plugin上的说明进行操作尝试编译各种项目...

makefile linker llvm gnu-coreutils gold-linker
1个回答
0
投票

您尝试过onlu ranlib吗?您需要llvm-ar(设置(CMAKE_AR llvm-ar)),可能还需要llvm-nm。llvm -ar代替ar对我来说效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.