From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1DD223858004; Sat, 3 Apr 2021 13:04:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DD223858004 From: "vries at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug driver/99896] New: g++ drops -lc Date: Sat, 03 Apr 2021 13:04:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: driver X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Apr 2021 13:04:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99896 Bug ID: 99896 Summary: g++ drops -lc Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- [ Spinoff from gdb PR https://sourceware.org/bugzilla/show_bug.cgi?id=3D276= 81 . ] Consider the following test-case, consisting of: ... $ cat main.c=20 #include #include #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include extern void foo (void); int main (void) { regex_t re; int res =3D regcomp (&re, "bla", 0); assert (res =3D=3D 0); int res2 =3D regexec (&re, "bla", 0, NULL, 0); assert (res2 =3D=3D 0); regoff_t res3 =3D re_search (&re, "bla", 3, 0, 3, NULL); assert (res3 =3D=3D 0); foo (); return 0; }=20 ... and: ... $ cat foo.c=20 #include #include #include extern void foo (void); void foo (void) { regex_t re; int res =3D pcre2_regcomp (&re, "bla", 0); assert (res =3D=3D 0); int res2 =3D pcre2_regexec (&re, "bla", 0, NULL, 0); assert (res2 =3D=3D 0); } ... We can compile with gcc and run like this: ... $ gcc main.c -lc foo.c -lpcre2-posix $ ./a.out=20 $ ... likewise, with clang: ... $ clang main.c -lc foo.c -lpcre2-posix $ ./a.out=20 $=20 ... likewise, with clang++: ... $ clang++ -x c++ main.c -lc foo.c -lpcre2-posix $ ./a.out=20 $ ... but with g++: ... $ g++ -x c++ main.c -lc foo.c -lpcre2-posix $ ./a.out=20 Segmentation fault (core dumped) $ ... Using -v, we can see what goes wrong. With gcc, we have: ... collect2 ... main.o -lc foo.o -lpcre2-posix ... ... With g++, we have instead: ... collect2 ... main.o foo.o -lpcre2-posix ... ... Workaround: use -Wl: ... $ g++ -x c++ main.c -Wl,-lc foo.c -lpcre2-posix $ ./a.out=20 $ ...=