On Tue, 26 Mar 2013 21:48:42 +0200, Paul Irofti wrote: > Good evening everyone, > > I discovered about one or two weeks ago that I can't link any debug > libraries on OpenBSD. At first I thought it was a cmake update[1] but > then I started digging further and it turns out its our gcc.
This is not about debug, but profiling libraries. > What threw me off is that gcc-4.7 from ports behaves the same way, but > I later discovered it's the same issue. > > Anyway, the problem pops up when doing something like this: > > ----------------------------------------------------------------------- > $ cc -shared -fpic -o libtest.so.0.0 `lorder test.so test1.so|tsort -q` > $ > ----------------------------------------------------------------------- > > versus something like this: > > ----------------------------------------------------------------------- > $ cc -shared -fpic -pg -o libtest.so.0.0 `lorder test.so test1.so|tsort -q` > /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to > 0000000000400260 > $ > ----------------------------------------------------------------------- > > This used to work in the past and no longer does on -current. It used to work in the sense that it produced a shared library with profiling and debug information. But this information is useless on OpenBSD. Profiling only works with static executables/libraries. Adding support for shared libraries would be non-trivial, and probably need support in ld.so. Look at sprof on Linux (even there, gprof doesn't support shared libraries). The correct approach here is probably to error out when -pg is given in combination with -shared on OpenBSD. Have you seen this command line in a real-world build system? In that case, just disable -pg. > I tested on a 5.1 system and the last command links libtest properly > without an error. > > I tracked it down to the commit that enabled PIE support on OpenBSD. > > I looked at the specs from other operating systems and Linux > distributions and I haven't found any -nopie references not only in the > libs section, but throughout the entire spec. That's because nobody else has the -nopie option in ld. > Thus I propose the following diff that removes the nopie bits. No, this would break linking profiled executables. > An identical diff is needed for the ports tree and I will take care of > it if this is accepted. So comments, okays? > > Cheers, > Paul Irofti > > > [1] -- http://marc.info/?l=openbsd-ports&m=136371733926696&w=2 > > Index: gcc/gcc.c > =================================================================== > RCS file: /cvs/src/gnu/gcc/gcc/gcc.c,v > retrieving revision 1.2 > diff -u -p -r1.2 gcc.c > --- gcc/gcc.c 28 Aug 2012 18:59:28 -0000 1.2 > +++ gcc/gcc.c 26 Mar 2013 19:33:05 -0000 > @@ -684,7 +684,7 @@ proper position among the other output f > > #ifndef LINK_PIE_SPEC > #ifdef HAVE_LD_PIE > -#define LINK_PIE_SPEC "%{pie:-pie} %{p|pg|nopie:-nopie} " > +#define LINK_PIE_SPEC "%{pie:-pie} " > #else > #define LINK_PIE_SPEC "%{pie:} " > #endif > >