public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified
@ 2013-10-06  3:40 skunk at iskunk dot org
  2013-10-07  6:19 ` [Bug libstdc++/58638] " skunk at iskunk dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: skunk at iskunk dot org @ 2013-10-06  3:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58638
           Summary: libstdc++ builds as non-PIC when --with-pic is
                    specified
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: skunk at iskunk dot org
              Host: x86_64-unknown-linux-gnu
            Target: x86_64-unknown-linux-gnu
             Build: x86_64-unknown-linux-gnu

I built GCC 4.8.1 with "--disable-shared --with-pic" so that I can statically
link libgcc/libstdc++ into executables, including shared-library builds.
However, when I attempted to build a C++ shared object on Linux/amd64 using the
new compiler, I got this:

libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/../lib64/crti.o
/opt/tg-opt/gcc--4.8.1--linux64/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/crtbeginS.o
 .libs/Dqa_wrap.o .libs/dqa_func.o [...]
-L/opt/tg-opt/gcc--4.8.1--linux64/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/opt/tg-opt/gcc--4.8.1--linux64/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../..
/opt/tg/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/libstdc++.a -lm -lc -lgcc
/opt/tg-opt/gcc--4.8.1--linux64/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/crtendS.o
/usr/lib/../lib64/crtn.o -march=opteron -mno-3dnow -O0   -pthread -Wl,-soname
-Wl,libdqa_swig_interface.so -o .libs/libdqa_swig_interface.so
/usr/bin/ld:
/opt/tg/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/libstdc++.a(eh_throw.o):
relocation R_X86_64_32S against `a local symbol' can not be used when making a
shared object; recompile with -fPIC
/opt/tg/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/libstdc++.a: could not read
symbols: Bad value
collect2: error: ld returned 1 exit status
make[6]: *** [libdqa_swig_interface.la] Error 1


This is a regression from 4.7.x, when --with-pic correctly caused all (static)
runtime libraries to be built with PIC code.


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
@ 2013-10-07  6:19 ` skunk at iskunk dot org
  2013-12-04 11:29 ` hjl.tools at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: skunk at iskunk dot org @ 2013-10-07  6:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Daniel Richard G. <skunk at iskunk dot org> ---
A workaround for this issue is to build with CFLAGS="-fPIC" CXXFLAGS="-fPIC"
(presuming that one is building with GCC), in addition to --with-pic. This
results in a compiler build that does not fail as reported above.


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
  2013-10-07  6:19 ` [Bug libstdc++/58638] " skunk at iskunk dot org
@ 2013-12-04 11:29 ` hjl.tools at gmail dot com
  2014-05-21 10:23 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2013-12-04 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cnstar9988 at gmail dot com

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
*** Bug 59380 has been marked as a duplicate of this bug. ***


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
  2013-10-07  6:19 ` [Bug libstdc++/58638] " skunk at iskunk dot org
  2013-12-04 11:29 ` hjl.tools at gmail dot com
@ 2014-05-21 10:23 ` redi at gcc dot gnu.org
  2014-05-21 20:25 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-21 10:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Daniel Richard G. from comment #0)
> I built GCC 4.8.1 with "--disable-shared --with-pic" so that I can
> statically link libgcc/libstdc++ into executables,

Instead of building GCC with --disable-shared, why not just use
-static-libstdc++ when linking?


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (2 preceding siblings ...)
  2014-05-21 10:23 ` redi at gcc dot gnu.org
@ 2014-05-21 20:25 ` redi at gcc dot gnu.org
  2014-05-21 21:09 ` skunk at iskunk dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-21 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think the right fix is

--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -120,6 +120,11 @@ if test "$enable_shared" = yes; then
   glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
   glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED"

+else if test "${with_pic+set}" = set; then
+  glibcxx_lt_pic_flag="-prefer-pic"
+  glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
+  glibcxx_compiler_shared_flag=
+
 else
   glibcxx_lt_pic_flag=
   glibcxx_compiler_pic_flag=


Otherwise we define _GLIBCXX_SHARED for non-shared builds and get unwanted (and
useless) symbols in the static lib.


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (3 preceding siblings ...)
  2014-05-21 20:25 ` redi at gcc dot gnu.org
@ 2014-05-21 21:09 ` skunk at iskunk dot org
  2014-05-23  4:39 ` skunk at iskunk dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: skunk at iskunk dot org @ 2014-05-21 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Daniel Richard G. <skunk at iskunk dot org> ---
(In reply to Jonathan Wakely from comment #4)
> 
> Instead of building GCC with --disable-shared, why not just use
> -static-libstdc++ when linking?

It was a long time ago that I last tried that, so I can't say for sure, but it
was probably that executables were being produced that still had some-or-other
GCC shared-runtime dependency.

(This GCC instance is being used for production builds, so it's
release-engineering considerations uber alles)


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (4 preceding siblings ...)
  2014-05-21 21:09 ` skunk at iskunk dot org
@ 2014-05-23  4:39 ` skunk at iskunk dot org
  2015-01-08 14:25 ` slipcon at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: skunk at iskunk dot org @ 2014-05-23  4:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Daniel Richard G. <skunk at iskunk dot org> ---
(In reply to Jonathan Wakely from comment #7)
> Seems unlikely, but if -static-libgcc -static-libstdc++ gives you a runtime
> dependency on GCC then that should be reported as a bug.

I tried a 4.9.0 build without --disable-shared to jog my memory. The problem
was twofold:

First, GCC can't find its own runtime library when linking programs:

    /usr/bin/ld: cannot find -lgcc_s

I can specify -L$(PREFIX)/lib/gcc/x86_64-unknown-linux-gnu/lib64 manually, and
that allows things to link. But then, unless I futz with
ld.so.conf/LD_LIBRARY_PATH, the resulting executable uses the wrong instance of
libgcc/libstdc++:

    $ ldd swig 
        linux-vdso.so.1 =>  (0x00007fff76839000)
    libdl.so.2 => /lib64/libdl.so.2 (0x000000302ee00000)
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003039a00000)
    libm.so.6 => /lib64/libm.so.6 (0x000000302e600000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003035a00000)
    libc.so.6 => /lib64/libc.so.6 (0x000000302ea00000)
    /lib64/ld-linux-x86-64.so.2 (0x000000302e200000)

(Note: It's probably relevant that I also build GCC with
--enable-version-specific-runtime-libs, to avoid a different way that the
runtimes can get mixed up.)

Not having to specify -static-libblah is a bonus, but these were the real
reasons that I was using --disable-shared. Should I file a new bug for this?


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (5 preceding siblings ...)
  2014-05-23  4:39 ` skunk at iskunk dot org
@ 2015-01-08 14:25 ` slipcon at gmail dot com
  2015-04-14  0:02 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: slipcon at gmail dot com @ 2015-01-08 14:25 UTC (permalink / raw)
  To: gcc-bugs

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

Scott Lipcon <slipcon at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slipcon at gmail dot com

--- Comment #9 from Scott Lipcon <slipcon at gmail dot com> ---
We saw the same issue with gcc 4.9.2 on x86_64 Linux - we build the compiler
with --disable-shared in order to be able to deliver our software on systems
without libstdc++.so.   Without the patches in this issue, we were unable to
link our .sos to libstdc++.a because of the missing -fPIC.   The patch I ended
up using was a bit different than those in the comments below, but seems to be
working for our installation:

--- libstdc++-v3/configure.ac.orig    2015-01-08 08:40:40.480754159 -0500
+++ libstdc++-v3/configure.ac    2015-01-08 08:43:27.633844665 -0500
@@ -120,6 +120,11 @@
   glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
   glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED"

+elif test "${with_pic+set}" = set; then
+  glibcxx_lt_pic_flag="-prefer-pic"
+  glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
+  glibcxx_compiler_shared_flag=
+
 else
   glibcxx_lt_pic_flag=
   glibcxx_compiler_pic_flag=


I hope this gets applied to an official release at some point.


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (6 preceding siblings ...)
  2015-01-08 14:25 ` slipcon at gmail dot com
@ 2015-04-14  0:02 ` redi at gcc dot gnu.org
  2022-08-01 22:27 ` pinskia at gcc dot gnu.org
  2022-08-01 23:07 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2015-04-14  0:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-04-14
     Ever confirmed|0                           |1


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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (7 preceding siblings ...)
  2015-04-14  0:02 ` redi at gcc dot gnu.org
@ 2022-08-01 22:27 ` pinskia at gcc dot gnu.org
  2022-08-01 23:07 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-01 22:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 106501 has been marked as a duplicate of this bug. ***

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

* [Bug libstdc++/58638] libstdc++ builds as non-PIC when --with-pic is specified
  2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
                   ` (8 preceding siblings ...)
  2022-08-01 22:27 ` pinskia at gcc dot gnu.org
@ 2022-08-01 23:07 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-01 23:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Alec Ari from comment #11)
> This fix worked for me:
> 
> --- a/libstdc++-v3/configure.ac
> +++ b/libstdc++-v3/configure.ac
> @@ -121,8 +121,8 @@ if test "$enable_shared" = yes; then
>    glibcxx_compiler_shared_flag="-D_GLIBCXX_SHARED"
>  
>  else
> -  glibcxx_lt_pic_flag=
> -  glibcxx_compiler_pic_flag=
> +  glibcxx_lt_pic_flag="-prefer-pic"
> +  glibcxx_compiler_pic_flag="$lt_prog_compiler_pic_CXX"
>    glibcxx_compiler_shared_flag=
>  fi
> 
> (no elif / no else if)

But this means always PIC, doesn't it? Even if you build with --disable-shared
and --without-pic. Surely that's not right? Why is this better than comment 9?

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

end of thread, other threads:[~2022-08-01 23:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-06  3:40 [Bug libstdc++/58638] New: libstdc++ builds as non-PIC when --with-pic is specified skunk at iskunk dot org
2013-10-07  6:19 ` [Bug libstdc++/58638] " skunk at iskunk dot org
2013-12-04 11:29 ` hjl.tools at gmail dot com
2014-05-21 10:23 ` redi at gcc dot gnu.org
2014-05-21 20:25 ` redi at gcc dot gnu.org
2014-05-21 21:09 ` skunk at iskunk dot org
2014-05-23  4:39 ` skunk at iskunk dot org
2015-01-08 14:25 ` slipcon at gmail dot com
2015-04-14  0:02 ` redi at gcc dot gnu.org
2022-08-01 22:27 ` pinskia at gcc dot gnu.org
2022-08-01 23:07 ` 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).