[llvm-dev] Wrong relocation emitted when building shared libraries with Control Flow Integrity

Artem Dinaburg via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 3 23:02:14 PST 2017


I am encountering a linking failure when using Control Flow Integrity while building a shared library. It looks like the wrong relocation type is being emitted for functions referenced via the PLT. I am using clang 3.9.

The error message I get is:

/usr/bin/ld.gold: error: /tmp/lto-llvm-df723d.o: requires dynamic R_X86_64_PC32 reloc against 'free' which may overflow at runtime; recompile with -fPIC

Recompiling with -fPIC does not actually help. I've managed to create a minimal reproducible testcase. Full command line and code to reproduce are below.

--- hello.c ---
#include <stdio.h>
#include <stdlib.h>

typedef void(*freeptr)(void*);

int getval(freeptr fp) {
    void *m = malloc(sizeof(int));
    if(m) {
    return 42;

int export() {
    printf("Test: %d\n", getval(free));
    return 0;
--- command line ---
clang-3.9 -shared -fuse-ld=gold -flto -fsanitize=cfi-icall -fPIC -o libhello.so hello.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170204/f942d372/attachment.bin>

More information about the llvm-dev mailing list