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

            Bug ID: 123932
           Summary: g++ moves -lc out of link group passed to the linker
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aoliva at gcc dot gnu.org
  Target Milestone: ---

Board support libraries (libgloss, libbsp) may offer bits that libc depends on,
but sometimes also depend on other libc bits.

In the former case, -lc will appear before -lgloss, and that should be enough.

In the latter case, we may need a link group, such as -Wl,--start-group -lc
-lbsp -Wl,--end-group.

I've just found out the painful way that these don't work with g++, because
g++spec.cc:lang_specific_driver has, since the beginning of time (1996 if not
earlier), *moved* -lc and -lm to the end of the linker command, just after
-lstdc++.

Making it -wl,--start-group,-lc instead hides -lc from g++ and works around the
problem, but...  this behavior is not exactly helpful IMHO, and it's not like
it would hurt to have -lc and -lm *added* after -lstdc++, instead of moving
them, is it?  Sure, it would slow linking down a bit, but that's better than
breaking a carefully crafted link group or something.

OTOH, I realize that such explicit groups are somewhat fragile to begin with,
so messing with them may be undesirable, and maybe whoever sets out to use them
can be counted on to figure out why it doesn't work the same with g++.

Reply via email to