larmel / lacc

A simple, self-hosting C compiler
MIT License
915 stars 66 forks source link

-shared/-static and -pie/-nopie linker recognition on OpenBSD. #18

Closed ibara closed 2 years ago

ibara commented 5 years ago

This PR organizes linker flags correctly for all permutations of -static/-shared, -pie/-nopie on OpenBSD. I didn't touch the Linux side of things because I don't know what should be correct there, but Linux will need some changes to cope.

At least on OpenBSD, you can't send -static and -shared directly to the linker; it expects -Bdynamic and -Bstatic (at least, I followed what clang does in this regard). I avoided sending -pie and -nopie directly as well in the (admittedly strange) edge case where someone tries to use -pie and -nopie in the same invocation.

larmel commented 5 years ago

I don't think -Bdynamic is the way to create shared libraries. My /usr/bin/ld resolves to LLD 7.7.1, and supports -shared, like GNU linker. Are you sure it doesn't work; which linker is installed on your system?

I tried to clean up this somewhat, and ended up with only a change for static. Having logic around valid uses of -pie/-nopie etc is not necessary IMO. With this, 'make test-linker' works on both my Linux and OpenBSD install. It has a test for -shared, but not -static (yet).

Let me know if there is some scenario that still does not work for you.