public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108734] New: powerpc: False Detection of __atomic_*_8  Builtins
@ 2023-02-09  3:53 rmclure at linux dot ibm.com
  2023-02-09  3:56 ` [Bug c/108734] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rmclure at linux dot ibm.com @ 2023-02-09  3:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108734
           Summary: powerpc: False Detection of __atomic_*_8  Builtins
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rmclure at linux dot ibm.com
                CC: bergner at gcc dot gnu.org
  Target Milestone: ---

Created attachment 54440
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54440&action=edit
False positive with __has_builtin

Using built-in specs.
COLLECT_GCC=powerpc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/powerpc-linux-gnu/12/lto-wrapper
Target: powerpc-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 12.2.0-3ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12 --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm
--disable-libquadmath --disable-libquadmath-support --enable-plugin
--with-system-zlib --enable-libphobos-checking=release
--without-target-system-zlib --with-libphobos-druntime-only=yes
--enable-secureplt --disable-softfloat --with-cpu=default32 --disable-softfloat
--enable-targets=powerpc-linux,powerpc64-linux --enable-multiarch
--disable-werror --with-long-double-128 --enable-multilib
--enable-checking=release --build=powerpc64le-linux-gnu
--host=powerpc64le-linux-gnu --target=powerpc-linux-gnu
--program-prefix=powerpc-linux-gnu- --includedir=/usr/powerpc-linux-gnu/include
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Ubuntu 12.2.0-3ubuntu1)


The attached program should compile on 32-bit systems, built with
`powerpc-linux-gnu-gcc fail.c -o fail`.

Instead, __has_builtin(__atomic_store_8) evaluates to true, and we get a linker
error.

```
/usr/lib/gcc-cross/powerpc-linux-gnu/11/../../../../powerpc-linux-gnu/bin/ld:
/tmp/ccJ9g2pV.o: in function `main':
fail.c:(.text+0x24): undefined reference to `__atomic_store_8'
collect2: error: ld returned 1 exit status
```

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
@ 2023-02-09  3:56 ` pinskia at gcc dot gnu.org
  2023-02-09  3:59 ` rmclure at linux dot ibm.com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-09  3:56 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Link against libatomic.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
  2023-02-09  3:56 ` [Bug c/108734] " pinskia at gcc dot gnu.org
@ 2023-02-09  3:59 ` rmclure at linux dot ibm.com
  2023-02-09  7:56 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rmclure at linux dot ibm.com @ 2023-02-09  3:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Rohan McLure <rmclure at linux dot ibm.com> ---
The issue here is less that I don't have access to the symbol __atomic_store_8,
it's that the preprocessor directive __has_builtin appears to false positive.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
  2023-02-09  3:56 ` [Bug c/108734] " pinskia at gcc dot gnu.org
  2023-02-09  3:59 ` rmclure at linux dot ibm.com
@ 2023-02-09  7:56 ` pinskia at gcc dot gnu.org
  2023-02-09  8:19 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-09  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=81358

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
These builtins are always available (via libatomic if neded) so testing
__has_builtin does not make sense.

If you are asking why libatomic is not automatically linked then this is a dup
of bug 81358.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
                   ` (2 preceding siblings ...)
  2023-02-09  7:56 ` pinskia at gcc dot gnu.org
@ 2023-02-09  8:19 ` redi at gcc dot gnu.org
  2023-02-09 17:56 ` dje at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-09  8:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
What are you actually trying to do here?

If you're trying to provide your own definitions for the atomic built-ins then
obviously you need to know platform-specific details, including whether that
operation is already expanded without emitting a library call.

If you're trying to do something else, maybe testing the macro
__GCC_ATOMIC_LLONG_LOCK_FREE==2 can help.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
                   ` (3 preceding siblings ...)
  2023-02-09  8:19 ` redi at gcc dot gnu.org
@ 2023-02-09 17:56 ` dje at gcc dot gnu.org
  2023-02-09 23:40 ` rmclure at linux dot ibm.com
  2023-02-10  9:33 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: dje at gcc dot gnu.org @ 2023-02-09 17:56 UTC (permalink / raw)
  To: gcc-bugs

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

David Edelsohn <dje at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dje at gcc dot gnu.org

--- Comment #5 from David Edelsohn <dje at gcc dot gnu.org> ---
Rohan,

I'm sorry that this is confusing, but the issue is cockpit error.

__has_builtin() does not mean that the builtin is inlined.  It only means that
GCC recognizes the builtin.  That is how __has_builtin() is documented.  In 32
bit mode, GCC emits an external reference for the builtin: 8 byte atomic
requires libatomic library, which is not linked by default (and shouldn't be).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
                   ` (4 preceding siblings ...)
  2023-02-09 17:56 ` dje at gcc dot gnu.org
@ 2023-02-09 23:40 ` rmclure at linux dot ibm.com
  2023-02-10  9:33 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rmclure at linux dot ibm.com @ 2023-02-09 23:40 UTC (permalink / raw)
  To: gcc-bugs

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

Rohan McLure <rmclure at linux dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Rohan McLure <rmclure at linux dot ibm.com> ---
David is right, I was assuming '__has_builtin' implied that the function would
be inlined in without needing to be obtained from libatomic. The translation
unit attached should then at least compile with no linker flags required, as if
the check fails it should define a stub implementation of __atomic_store_8
(pardon the obvious syntax error in that stub).

Sorry, my mistake. Yes that makes more sense.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/108734] powerpc: False Detection of __atomic_*_8  Builtins
  2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
                   ` (5 preceding siblings ...)
  2023-02-09 23:40 ` rmclure at linux dot ibm.com
@ 2023-02-10  9:33 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-10  9:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #5)
> __has_builtin() does not mean that the builtin is inlined.  It only means
> that GCC recognizes the builtin.  That is how __has_builtin() is documented.
> In 32 bit mode, GCC emits an external reference for the builtin: 8 byte
> atomic requires libatomic library, which is not linked by default (and
> shouldn't be).

And this is consistent with e.g. __has_builtin(__builtin_strlen). The fact that
GCC recognizes the token "__builtin_strlen" doesn't mean that you don't need an
extern definition of strlen for cases where the built-in isn't inlined. It's
just that for the atomic built-ins the name of the built-in is the same as the
name of the extern function that might be used.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-02-10  9:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09  3:53 [Bug c/108734] New: powerpc: False Detection of __atomic_*_8 Builtins rmclure at linux dot ibm.com
2023-02-09  3:56 ` [Bug c/108734] " pinskia at gcc dot gnu.org
2023-02-09  3:59 ` rmclure at linux dot ibm.com
2023-02-09  7:56 ` pinskia at gcc dot gnu.org
2023-02-09  8:19 ` redi at gcc dot gnu.org
2023-02-09 17:56 ` dje at gcc dot gnu.org
2023-02-09 23:40 ` rmclure at linux dot ibm.com
2023-02-10  9:33 ` redi at gcc dot gnu.org

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).