On Tue, Mar 26, 2013 at 09:15:38PM +0100, Pascal Stumpf wrote:
> 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.

Yes, I know that. As the email subject says. My debug libraries are also
compiled with profiling info.

> > 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.

Well, then perhaps just ignore the option when passed without nopie?

> 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).

Interesting, I will, thanks!

> 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.

Yes I did. I've been building this way for three years now.

I would just set something like this, and it would work like a charm:

        set (CMAKE_CXX_FLAGS_DEBUG              "-O0 -g -pg")
        set (CMAKE_CXX_FLAGS_MINSIZEREL         "-Os -DNDEBUG")
        set (CMAKE_CXX_FLAGS_RELEASE            "-O2 -DNDEBUG")
        set (CMAKE_CXX_FLAGS_RELWITHDEBINFO     "-O2 -DNDEBUG -g")

But now, when I tried to build inside a clean object directory I ran
into this issue.

> > 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.

Okay.

> > Thus I propose the following diff that removes the nopie bits.
> 
> No, this would break linking profiled executables.

I don't understand how, can you go into more details please?

Anyway, can we then just ignore the -pg option if it doesn't work for
shared instead of breaking the link? Or do you have a better solution?

Thanks,
Paul Irofti

Reply via email to