3

I followed the instructions on http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html#compiling-llvm-from-source-with-gold-plugin to try to compile various projects including the coreutils to LLVM IR.

I tried to test my installation on Ubuntu 14.04 with Clang 3.4 and a simple test file with

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

as described but it failed with

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

However, after adding the parameter -B/usr/lib/gold-ld I could compile the test file.

Still, compiling the coreutils fails with the following error:

/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'

The last command executed is:

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 

Manually executing llvm-ranlib on libver.a and libcoreutils.a does not change the outcome. Executing llvm-nm -s src/libver.a prints the following:

 D Version

However, with a normal build the output is the following:

Archive map
Version in version.o

version.o:
00000000 D Version

Is there a problem with llvm-ranlib? Do you have any suggestions on how to fix the linker error?

box
  • 3,156
  • 3
  • 26
  • 36

1 Answers1

0

You have tried onlu ranlib? You need llvm-ar (set (CMAKE_AR llvm-ar)) and possibly llvm-nm. llvm-ar instead of ar worked well fo me.

Olga Krishtal
  • 177
  • 1
  • 4