I'm trying to adapt an existing scons build system to use clang++ instead of g++. When using -O0 or -O2 -- neither of which output llvm IR -- things work swimmingly, that is to say, the build complete without errors. When using -O4, which compiles to llvm bytecode to allow link-time-optimization, the build fails on the final link.

I've searched various places, but I am unclear on exactly how to fix this, either directly on the command line or, knowing that in my SConstruct file.

Note: Setting env['LINK'] = "/path/to/llvm-link" causes all of my dependency checks to fail.

Note: Adding -Xlinker "-plugin" -Xlinker "/usr/lib/LLVMgold.so" to the command works well. So, the question is how to add this conditioned upon the choice of clang in SConstruct.

$ /usr/sbin/distcc clang++ -o build/release/filex.o -c -std=c++11 -march=core-avx-i -W -Wall -O4 \
    -DHAVE_LLVM=0x0303 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS \
    -D__STDC_LIMIT_MACROS -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_CONFIG_H -D_X11 \
    -DFIFODIR='"/var/run/dir"' -I. -Isrc -I/usr/include -I/usr/include/SDL src/filex.cpp
...
$ ar rc build/release/libfile2.a build/release/filea.o build/release/tools/fileb.o
$ ranlib build/release/libfile2.a
...
$ /usr/sbin/distcc clang++ -o mybinary -pthread build/release/file1.o \
    build/release/libfile2.a ... -L/usr/lib -lLLVMBitWriter -lLLVMX86Disassembler \
    -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser \
    -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMJIT \
    -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts \
    -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC \
    -lLLVMObject -lLLVMCore -lLLVMSupport -lz -lffi -ldl -lm -lboost_iostreams -lSDL \
    -lSDL_net -lpthread -lboost_system -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 \
    -lcairo -lfontconfig -lfreetype -lboost_program_options -lboost_regex -lSDL_ttf \
    -lSDL_mixer -lvorbisfile -lSDL_image -lX11

/usr/sbin/ld.gold: error: build/release/file1.o:1:3: invalid character
/usr/sbin/ld.gold: error: build/release/file1.o:1:3: syntax error, unexpected $end
/usr/sbin/ld.gold: error: build/release/flie1.o: not an object or archive
有帮助吗?

解决方案

The key is to append -Wl,-plugin,/path/to/LLVMgold.so to LINKFLAGS rather than the -Xlinker... syntax.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top