public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mathieu.malaterre at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-104248-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            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=-latomic ...

some other time this more complex as in this above case where a static library
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 updated
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-276587351

             reply	other threads:[~2022-01-26 16:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 16:43 mathieu.malaterre at gmail dot com [this message]
2022-01-26 16:48 ` [Bug c/104248] " mathieu.malaterre at gmail dot com
2022-01-26 17:02 ` [Bug driver/104248] " schwab@linux-m68k.org
2022-01-26 17:21 ` mathieu.malaterre at gmail dot com
2022-01-26 17:28 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104248-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).