clang/llvm cmake static build broken on Linux

Hi all,

I just grabbed tot. I’m still able to build dynamic but static linking isn’t working for me anymore.

I’m not sure if I should be directing this to cfe-dev or llvm-dev

[305/306] Linking CXX executable bin/clang-3.6

/usr/bin/ld: dynamic STT_GNU_IFUNC symbol strcmp' with pointer equality in /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/x86_64-linux-gnu/libc.a(strcmp.o)’ can not be used when making an executable; recompile with -fPIE and relink with -pie"

Repro steps:

#!/bin/bash -ex

ROOT_DIR=$HOME/ll/static-fail

mkdir $ROOT_DIR
cd $ROOT_DIR
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd $ROOT_DIR
mkdir build
cd build
cmake -G Ninja …/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_STATIC=True
ninja clang

The first checkin with support for LLVM_BUILD_STATIC has this linking error, so the flag just isn’t intended do what I expected. I am able to build lldb-platform/lldb-gdbserver statically with this flag so it’s working for me.

Vince

This looks like a bug/limitation in bfd ld.

$ gcc test.c -o test -static -Wl,-export-dynamic -fuse-ld=bfd
ld.bfd: dynamic STT_GNU_IFUNC symbol strcmp' with pointer equality in /usr/lib/gcc/x86_64-redhat-linux/4.9.2/…/…/…/…/lib64/libc.a(strcmp.o)’ can not be used when making an executable; recompile with -fPIE and relink with -pie
collect2: error: ld returned 1 exit status
$ gcc test.c -o test -static -Wl,-export-dynamic -fuse-ld=gold

$ cat test.c
#include <string.h>

int main(int argc, char *argv) {
return strcmp(argv[0], argv[1]);
}