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 via email to