Wrong relocation emitted when building shared libraries with Control Flow Integrity

Hello,

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) {
        fp(m);
    }
    return 42;
}

int export() {
    printf("Test: %d\n", getval(free));
    return 0;
}

Hi Artem,

Can you please try LLVM trunk (or the upcoming 4.0 release)? I believe that your bug was fixed by r286611.

Peter

Hi Peter,

Thanks for the help! I can confirm its fixed in the 4.0 release (tested with clang version 4.0.0-svn293947-1~exp1).

Thanks,
Artem