From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1829A3850426; Wed, 26 Jan 2022 16:43:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1829A3850426 From: "mathieu.malaterre at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/104248] New: armel: C11 atomics requires to be linked with libatomic.a explicitly Date: Wed, 26 Jan 2022 16:43:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mathieu.malaterre at gmail dot com 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: Wed, 26 Jan 2022 16:43:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104248 Bug ID: 104248 Summary: armel: C11 atomics requires to be linked with libatomic.a explicitly Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mathieu.malaterre at gmail dot com Target Milestone: --- Consider the following c11 code (lib + executable): ``` :::::::::::::: foo.c :::::::::::::: _Atomic(long long) ll; int foo(void) { ++ll; return 42; } :::::::::::::: prog.c :::::::::::::: int foo(void); int main(int argc, char* argv[]) { return foo(); } ``` On Debian armel arch, most built system will fail to compile the above. The error reported is: ``` /usr/bin/ld: libfoo.a(foo.c.o): in function `foo': foo.c:(.text+0x40): undefined reference to `__atomic_fetch_add_8' ``` One need to carefully pass `atomic` library on the compilation line. So if = you are lucky this is just: LDFLAGS=3D-latomic ... some other time this more complex as in this above case where a static libr= ary is build, thus one needs to: ``` cc -rdynamic prog.o -o prog libfoo.a -Wl,-Bstatic -latomic -Wl,-Bdynamic ``` --- I see that on some other arch (riscv), the spec file for gcc has been updat= ed to pass automatically (?) the proper flag: `--as-needed -latomic` [1] Could someone from gcc/arm team please describe what is the reason for not doing something equivalent for the spec file in armel case ? Thanks for your time. [1] https://github.com/riscv-collab/riscv-gcc/issues/12#issuecomment-276587= 351=