public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++
@ 2012-03-29  9:12 christophe.lyon at st dot com
  2012-03-29  9:22 ` [Bug libstdc++/52765] " christophe.lyon at st dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-03-29  9:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

             Bug #: 52765
           Summary: -std=c++0x requires multilib for non-optimized
                    libstdc++
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: christophe.lyon@st.com


Hello,
While experimenting with -std=c++0x and libstdc++ built at -O0 [1], I noticed
that this sample code does not produce the expected result:
==================8<>===============
#include <iostream>
#include <complex>

int main()
{
    const std::complex<float> cf (23., 101.);

    std::cout << cf.real() << '\n';
    std::cout << cf << '\n';

    return 0;
}
==================8<>===============
That is, with -std=c++0x it prints:
23
(0,101)
and without -std=c++0x it prints:
23
(23,101)

This is because the call to cf.real() makes the compiler generate a 'c++0x'
variant of std::complex<float>::real() const, which is also called implicitly
by the library when printing the complex. But the library expects the non
'c++0x' version.

Admittedly, libstdc++ seems to be expected to compiled at -O2 and thus
std::complex<float>::real() is normally inlined, but I am wondering whether
there might be other functions in libstdc++ which would not be inlined at -O2
in the library itself, and thus subject to the same problem.

One way of having compliant libraries for me is to use multilib, but
understanding the root cause of such errors might not be easy for the average
user.

I am not sure this is really a bug (is building libstdc++ at -O0 supported?),
but at least I think it might be worth checking that other functions whose
prototype changes with -std=c++0x are always inlined in the library itself.



[1] I built libstdc++ at -O0 inadvertently, by overriding CFLAGS (not including
-O2) before building GCC.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
@ 2012-03-29  9:22 ` christophe.lyon at st dot com
  2012-03-29 10:10 ` redi at gcc dot gnu.org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-03-29  9:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #1 from christophe.lyon at st dot com 2012-03-29 09:19:30 UTC ---
If you look at libstdc++-v3/include/std/complex:
[...]
#ifdef __GXX_EXPERIMENTAL_CXX0X__
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // DR 387. std::complex over-encapsulated.
      constexpr _Tp
      real() const { return _M_real; }
[...]
#else
[...]
      ///  Return real part of complex number.
      const _Tp&
      real() const { return _M_real; }
[...]
#endif

You can see that depending of __GXX_EXPERIMENTAL_CXX0X__ (automatically defined
with -std=c++0x), the type of the value returned by real() is different.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
  2012-03-29  9:22 ` [Bug libstdc++/52765] " christophe.lyon at st dot com
@ 2012-03-29 10:10 ` redi at gcc dot gnu.org
  2012-03-29 12:20 ` christophe.lyon at st dot com
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-29 10:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-29 10:08:20 UTC ---
(In reply to comment #0)
> I am not sure this is really a bug (is building libstdc++ at -O0 supported?),

Yes, the --enable-libstdcxx-debug configure option builds an alternative
libstdc++.so with -O0 (but I can't reproduce this when using that lib)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
  2012-03-29  9:22 ` [Bug libstdc++/52765] " christophe.lyon at st dot com
  2012-03-29 10:10 ` redi at gcc dot gnu.org
@ 2012-03-29 12:20 ` christophe.lyon at st dot com
  2012-03-29 13:13 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-03-29 12:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #3 from christophe.lyon at st dot com 2012-03-29 12:08:43 UTC ---
Not sure how/if it matters: I am looking at a cross gcc for arm-none-eabi,
built with --disable-shared.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (2 preceding siblings ...)
  2012-03-29 12:20 ` christophe.lyon at st dot com
@ 2012-03-29 13:13 ` paolo.carlini at oracle dot com
  2012-03-29 13:17 ` paolo.carlini at oracle dot com
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 13:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-03-29
     Ever Confirmed|0                           |1

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-29 13:12:40 UTC ---
Something seems fishy on x86_64-linux too, with the library built -O0 and
-std=c++11 I see random segfaults.

But since the problem seems simply that at -O0 we have these *additional*
unwanted exports:

000000000008031e W std::complex<double>::imag() const
0000000000080310 W std::complex<double>::real() const
0000000000080394 W std::complex<long double>::imag() const
0000000000080386 W std::complex<long double>::real() const
00000000000802ac W std::complex<float>::imag() const
000000000008029e W std::complex<float>::real() const
00000000000802e4 W std::complex<double>::complex(double, double)
00000000000802e4 W std::complex<double>::complex(double, double)
0000000000080330 W std::complex<double>::operator=(double)
0000000000080358 W std::complex<long double>::complex(long double, long double)
0000000000080358 W std::complex<long double>::complex(long double, long double)
00000000000803a6 W std::complex<long double>::operator=(long double)
0000000000080276 W std::complex<float>::complex(float, float)
0000000000080276 W std::complex<float>::complex(float, float)
00000000000802be W std::complex<float>::operator=(float)

I suppose the fix should be straightforward: just tighten the linker map and
prevent that from happening.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (3 preceding siblings ...)
  2012-03-29 13:13 ` paolo.carlini at oracle dot com
@ 2012-03-29 13:17 ` paolo.carlini at oracle dot com
  2012-03-29 13:25 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 13:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-29 13:13:19 UTC ---
linker script, I meant


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (4 preceding siblings ...)
  2012-03-29 13:17 ` paolo.carlini at oracle dot com
@ 2012-03-29 13:25 ` paolo.carlini at oracle dot com
  2012-03-29 15:53 ` christophe.lyon at st dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 13:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-29 13:23:17 UTC ---
Created attachment 27033
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27033
Very lightly tested so far

Appears to work as expected. Maybe submitter can test it in his config: just
apply the patchlet and rebuild (library only is fine) as usual.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (5 preceding siblings ...)
  2012-03-29 13:25 ` paolo.carlini at oracle dot com
@ 2012-03-29 15:53 ` christophe.lyon at st dot com
  2012-03-29 15:54 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-03-29 15:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #7 from christophe.lyon at st dot com 2012-03-29 15:45:42 UTC ---
It doesn't work in my context:
- symbol versioning does not apply to static libraries (as already said, I'm
using --disable-shared)
- the problem is not that the library is exporting unwanted symbols, but that
it is referencing symbols which happen to be defined in the user main.o with a
different prototype.

main.o defines and calls real()
libstdc++.a (complex_io.o) calls real(), but expects the version defined in
libstdc++.a which has a different prototype from the one in main.o. However, it
uses the version in main.o by link rules.

Another possible fix could be to add the always_inline attribute in the
library, or make sure to distinguish both prototypes.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (6 preceding siblings ...)
  2012-03-29 15:53 ` christophe.lyon at st dot com
@ 2012-03-29 15:54 ` paolo.carlini at oracle dot com
  2012-03-30  9:05 ` christophe.lyon at st dot com
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 15:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-29 15:52:52 UTC ---
For sure, anyway, at -O0 the library *is* exporting unwanted symbols. I'm not
sure that at this time we can really support what you want.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (7 preceding siblings ...)
  2012-03-29 15:54 ` paolo.carlini at oracle dot com
@ 2012-03-30  9:05 ` christophe.lyon at st dot com
  2012-03-30 10:23 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-03-30  9:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #9 from christophe.lyon at st dot com 2012-03-30 08:39:19 UTC ---
(In reply to comment #2)
> (In reply to comment #0)
> > I am not sure this is really a bug (is building libstdc++ at -O0 supported?),
> 
> Yes, the --enable-libstdcxx-debug configure option builds an alternative
> libstdc++.so with -O0 (but I can't reproduce this when using that lib)

I have experimented with this configure option. I didn't know about it: what is
the intended way of using the debug libraries? I have add -L..../debug to my
link command, and I do reproduce the problem in this context:
- target arm-none-eabi
- --disable-shared

# Using default libs, built at -O2
$ arm-none-eabi-g++ cplx.cxx -o cplx.u -mcpu=cortex-a9 -std=c++0x
$ qemu-system-arm -semihosting -cpu cortex-a9 -nographic -kernel ./cplx.u
23
(23,101)

# Using debug libs, built at -O0
$ arm-none-eabi-g++ cplx.cxx -o cplx.u -mcpu=cortex-a9 -std=c++0x -L
.../lib/debug
$ qemu-system-arm -semihosting -cpu cortex-a9 -nographic -kernel ./cplx.u
23
(0,101)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (8 preceding siblings ...)
  2012-03-30  9:05 ` christophe.lyon at st dot com
@ 2012-03-30 10:23 ` redi at gcc dot gnu.org
  2012-06-25 14:38 ` christophe.lyon at st dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-30 10:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-30 09:59:51 UTC ---
(In reply to comment #9)
> I have experimented with this configure option. I didn't know about it: what is
> the intended way of using the debug libraries?

I use debug/libstdc++.so via LD_LIBRARY_PATH when I want to run in gdb and
step-through code in the library. i.e. I link as normal, but switch to using
the debug lib at run-time. Obviously if using static linking that doesn't work
so you'd have to decide to use that lib at link-time.

I mentioned it here because it's a common (and supported) way to get a
libstdc++ built with -O0 while keeping the primary libs built with the usual
flags (-O2 etc.)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (9 preceding siblings ...)
  2012-03-30 10:23 ` redi at gcc dot gnu.org
@ 2012-06-25 14:38 ` christophe.lyon at st dot com
  2012-06-25 14:45 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: christophe.lyon at st dot com @ 2012-06-25 14:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #11 from christophe.lyon at st dot com 2012-06-25 14:38:00 UTC ---
I have proposed a patch related to this problem some time ago, which received
no feedback:
http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01855.html


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (10 preceding siblings ...)
  2012-06-25 14:38 ` christophe.lyon at st dot com
@ 2012-06-25 14:45 ` redi at gcc dot gnu.org
  2012-06-25 14:50 ` redi at gcc dot gnu.org
  2024-01-17 11:47 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-06-25 14:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-06-25 14:45:18 UTC ---
Patches for libstdc++ should be sent to the libstdc++ list as well as
gcc-patches. That's probably why you didn't get any feedback.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (11 preceding siblings ...)
  2012-06-25 14:45 ` redi at gcc dot gnu.org
@ 2012-06-25 14:50 ` redi at gcc dot gnu.org
  2024-01-17 11:47 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-06-25 14:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-06-25 14:50:10 UTC ---
Oh I see it isn't specific to libstdc++.  You'll just have to push on the
gcc-patches list for review then.  It helps if you describe the problem it
solves in detail, and confirm it was tested successfully, stating on which
platform(s).


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug libstdc++/52765] -std=c++0x requires multilib for non-optimized libstdc++
  2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
                   ` (12 preceding siblings ...)
  2012-06-25 14:50 ` redi at gcc dot gnu.org
@ 2024-01-17 11:47 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-17 11:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52765

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
                 CC|                            |clyon at gcc dot gnu.org
   Target Milestone|---                         |4.8.0

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #14)
> The original problem should be fixed long ago, because those functions use
> the abi_tag now.

I think this was fixed for gcc 4.8.0 by r0-120238-g7a3a9e6821ff5e so I'm going
to close it.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-01-17 11:47 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-29  9:12 [Bug libstdc++/52765] New: -std=c++0x requires multilib for non-optimized libstdc++ christophe.lyon at st dot com
2012-03-29  9:22 ` [Bug libstdc++/52765] " christophe.lyon at st dot com
2012-03-29 10:10 ` redi at gcc dot gnu.org
2012-03-29 12:20 ` christophe.lyon at st dot com
2012-03-29 13:13 ` paolo.carlini at oracle dot com
2012-03-29 13:17 ` paolo.carlini at oracle dot com
2012-03-29 13:25 ` paolo.carlini at oracle dot com
2012-03-29 15:53 ` christophe.lyon at st dot com
2012-03-29 15:54 ` paolo.carlini at oracle dot com
2012-03-30  9:05 ` christophe.lyon at st dot com
2012-03-30 10:23 ` redi at gcc dot gnu.org
2012-06-25 14:38 ` christophe.lyon at st dot com
2012-06-25 14:45 ` redi at gcc dot gnu.org
2012-06-25 14:50 ` redi at gcc dot gnu.org
2024-01-17 11:47 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).