Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: add support for -fpic #7

Open
didickman opened this issue Dec 28, 2014 · 2 comments
Open

feature request: add support for -fpic #7

didickman opened this issue Dec 28, 2014 · 2 comments

Comments

@didickman
Copy link
Contributor

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.

@xavierleroy
Copy link
Contributor

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.

@didickman
Copy link
Contributor Author

Just noting that this PR is still highly desirable from my end. Many thanks for any consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants