feature request: add support for -fpic
with gcc:
$ cat foo.c
#include <stdio.h>
void foo(void)
{
puts("Hello Shared World");
}
$ gcc -fpic -std=c99 -c foo.c
$ gcc -shared -o libfoo.so foo.o
$
with CompCert this seems to work:
$ ccomp -fall -c foo.c
$ ccomp -Wl,-shared -o libfoo.so foo.c
$
But it would be nice to have support for -fpic.
Right, on x86-32 shared libraries can be built from code compiled "normally", without PIC. The downside is more relocation work at dynamic loading time and inability to share the code of the shared library between several processes that use it. On platforms other than x86-32, this may not work at all.
For reference, here is a summary of PIC conventions for x86-32/ELF: http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/ and more info on PIC and its close cousin PIE for OpenBSD: http://www.openbsd.org/papers/nycbsdcon08-pie/mgp00001.html
The most annoying aspect of PIC, from CompCert's back-end viewpoint, is the need to reserve register ebx. Otherwise, there is already a bit of support for not using absolute addressing modes to access global variables (the "Oindirectsymbol" pseudo-instruction), which is already used for MacOS X. This could be reused to provide PIC access to global variables. For function calls, it's a simple matter of calling the "@PLT" stubs.
Just noting that this PR is still highly desirable from my end. Many thanks for any consideration!