public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/46563] New: link with -lgcc when creating a shared lib
@ 2010-11-19 16:05 christophe.lyon at st dot com
  2010-11-19 16:09 ` [Bug driver/46563] " christophe.lyon at st dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: christophe.lyon at st dot com @ 2010-11-19 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: link with -lgcc when creating a shared lib
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: christophe.lyon@st.com


Created attachment 22457
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22457
main prog C++ source

As discussed in http://gcc.gnu.org/ml/gcc-help/2010-11/msg00198.html, the G++
driver does not link with -lgcc when creating a shared lib.

This is a problem when the shared lib references some symbols which are only
present in libgcc.a (such as __sync_fetch_and_add and all __sync*). This is the
case for instance on ARM.

I have attached atomic.cxx (shared lib) and atomain.cxx (main prog) to be
compiled with:
$ arm-linux-g++ atomic.cxx -fPIC -shared -o libatomic.so
$ arm-linux-g++ atomain.cxx -o atomain -L. -latomic
.../ld: atomain: hidden symbol `__sync_fetch_and_add_4' in
/.../libgcc.a(linux-atomic.o) is referenced by DSO

As a fix I can suggest to patch gcc.c:init_gcc_specs() and to add static_name
next to shared_name when expanding the specs.
diff -up gcc.c gcc.c.patch
--- gcc.c       2010-02-25 17:20:51.831150000 +0100
+++ gcc.c.patch 2010-11-19 17:02:37.141674000 +0100
@@ -1722,7 +1722,7 @@ init_gcc_specs (struct obstack *obstack,
                static_name, " --as-needed ", shared_name, " --no-as-needed"
                "}"
                "%{shared-libgcc:",
-               shared_name, "%{!shared: ", static_name, "}"
+               shared_name, " ", static_name, "%{!shared: ", static_name, "}"
                "}"
 #else
                "%{!shared:"
@@ -1731,11 +1731,11 @@ init_gcc_specs (struct obstack *obstack,
                "}"
 #ifdef LINK_EH_SPEC
                "%{shared:"
-               "%{shared-libgcc:", shared_name, "}"
+               "%{shared-libgcc:", shared_name, " ", static_name"}"
                "%{!shared-libgcc:", static_name, "}"
                "}"
 #else
-               "%{shared:", shared_name, "}"
+               "%{shared:", shared_name, " ", static_name"}"
 #endif
 #endif
                "}}", NULL);


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

end of thread, other threads:[~2010-11-22 10:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-19 16:05 [Bug driver/46563] New: link with -lgcc when creating a shared lib christophe.lyon at st dot com
2010-11-19 16:09 ` [Bug driver/46563] " christophe.lyon at st dot com
2010-11-19 16:09 ` aph at gcc dot gnu.org
2010-11-19 16:17 ` christophe.lyon at st dot com
2010-11-19 16:49 ` mikpe at it dot uu.se
2010-11-19 17:20 ` christophe.lyon at st dot com
2010-11-19 17:38 ` aph at gcc dot gnu.org
2010-11-19 17:42 ` mikpe at it dot uu.se
2010-11-22  8:47 ` christophe.lyon at st dot com
2010-11-22  9:01 ` christophe.lyon at st dot com
2010-11-22  9:48 ` christophe.lyon at st dot com
2010-11-22 10:02 ` aph at gcc dot gnu.org
2010-11-22 10:12 ` christophe.lyon at st dot com
2010-11-22 10:15 ` aph 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).