CompCert icon indicating copy to clipboard operation
CompCert copied to clipboard

LLVM linker, dynamic relocation against local symbol in readonly segment

Open monniaux opened this issue 3 years ago • 1 comments

static int toto;
int *const p = &toto;

int main() { return 0; }

fails to link under OpenBSD x86_64 with LLVM 13.0.0 (but I suspect this may apply to any system using the LLVM linker? perhaps even MacOS X?) with the following message:

ld: error: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

The static and const bits are necessary.

This can be fixed by using in compcert.ini:

prepro=clang
linker=clang
asm=clang
linker_options=-m64 -Wl,-z,notext

I'm unsure if something has to be done inside CompCert proper, or if one should just write that somewhere in documentation.

monniaux avatar Sep 07 '22 09:09 monniaux

This is the problem that #385 addressed a while ago, but only for macOS so far. The fix needs to be propagated to other configurations.

xavierleroy avatar Sep 08 '22 14:09 xavierleroy