public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108076] New: GCC with -O3 produces code which fails to link
@ 2022-12-12 14:53 martid0311 at gmail dot com
  2022-12-12 14:54 ` [Bug c/108076] " martid0311 at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: martid0311 at gmail dot com @ 2022-12-12 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108076
           Summary: GCC with -O3 produces code which fails to link
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martid0311 at gmail dot com
  Target Milestone: ---

Created attachment 54074
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54074&action=edit
The source code which fails to compile

The attached source file ("compiler-output.c") fails to link with GCC with -O3
(compiling for x86_64). I've tested it using "gcc (Ubuntu
11.3.0-1ubuntu1~22.04) 11.3.0", but someone on IRC has confirmed that it's also
an issue on "gcc (Debian 12.2.0-9.1) 12.2.0".

Running `gcc -O3 compiler-output.c` fails with this set of errors:
/usr/bin/ld: /tmp/ccgWgyyV.o: warning: relocation against `.L8' in read-only
section `.text.startup'
/usr/bin/ld: /tmp/ccgWgyyV.o: in function `main':
gnuc-compiler-output.c:(.text.startup+0x2f): undefined reference to `.L7'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x36): undefined reference
to `.L15'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x48): undefined reference
to `.L5'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x5a): undefined reference
to `.L6'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x6a): undefined reference
to `.L8'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x76): undefined reference
to `.L9'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x90): undefined reference
to `.L10'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0x9b): undefined reference
to `.L11'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0xa9): undefined reference
to `.L12'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0xb5): undefined reference
to `.L13'
/usr/bin/ld: gnuc-compiler-output.c:(.text.startup+0xcf): undefined reference
to `.L14'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

I've looked at the generated assembly code (using `gcc -S`), and sure enough,
the main function contains code like "leaq    .L15(%rip), %rdx" and "leaq   
.L5(%rip), %rax" even though there's no label called .L15 or .L5.

The source code contains a label jump table which gets initialized like this:
static void *jmp_targets[62];
int main() {
    jmp_targets[0] = &&instr_0;
    jmp_targets[1] = &&instr_1;
    jmp_targets[2] = &&instr_2;
    jmp_targets[7] = &&instr_7;
    ...

If we change the code to use an initializer list it works:
int main() {
    void *jmp_targets[] = {
        [0] = &&instr_0,
        [1] = &&instr_1,
        [2] = &&instr_2,
        [7] = &&instr_7,
        ...

Interestingly, it also works if we compile with `-O3 -flto`.

Note: the code will segfault unless you provide it command line arguments. If
you want to try to run it, run something like `./a.out 5 10`. It will print the
sum of the two numbers.

Output of `gcc -v`:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)

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

* [Bug c/108076] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
@ 2022-12-12 14:54 ` martid0311 at gmail dot com
  2022-12-12 15:15 ` [Bug tree-optimization/108076] [10/11/12/13 Regression] " amonakov at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: martid0311 at gmail dot com @ 2022-12-12 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Martin Dørum <martid0311 at gmail dot com> ---
Created attachment 54075
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54075&action=edit
Preprocessed source code from gcc --save-temps

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

* [Bug tree-optimization/108076] [10/11/12/13 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
  2022-12-12 14:54 ` [Bug c/108076] " martid0311 at gmail dot com
@ 2022-12-12 15:15 ` amonakov at gcc dot gnu.org
  2022-12-12 16:19 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-12-12 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org
            Summary|GCC with -O3 produces code  |[10/11/12/13 Regression]
                   |which fails to link         |GCC with -O3 produces code
                   |                            |which fails to link
      Known to work|                            |8.5.0
          Component|c                           |tree-optimization
           Keywords|                            |link-failure

--- Comment #2 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
GIMPLE if-conversion seems to delete BBs with address-taken labels; works with
-fno-tree-loop-if-convert

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

* [Bug tree-optimization/108076] [10/11/12/13 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
  2022-12-12 14:54 ` [Bug c/108076] " martid0311 at gmail dot com
  2022-12-12 15:15 ` [Bug tree-optimization/108076] [10/11/12/13 Regression] " amonakov at gcc dot gnu.org
@ 2022-12-12 16:19 ` pinskia at gcc dot gnu.org
  2022-12-12 16:30 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-12 16:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-12-12
      Known to work|                            |9.1.0, 9.2.0, 9.4.0, 9.5.0
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |10.5
     Ever confirmed|0                           |1
      Known to fail|                            |10.1.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/108076] [10/11/12/13 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-12-12 16:19 ` pinskia at gcc dot gnu.org
@ 2022-12-12 16:30 ` jakub at gcc dot gnu.org
  2022-12-12 16:38 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-12 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Reduced testcase:
static void *j;
int v;
__attribute__((__leaf__)) int atoi (const char *);

int
main ()
{
  j = &&lab1;
  &&lab2;
  atoi ("42");
lab1:
lab2:
  if (v)
    goto *j;
}
which fails to link with -O2 starting with
r12-4240-g2b8453c401b699ed93c085d0413ab4b5030bcdb8
and with -O2 -ftree-vectorize starting with
r10-7522-g75efe9cb1f8938a713ce540dc3b27bc2afcd3fae

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

* [Bug tree-optimization/108076] [10/11/12/13 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-12-12 16:30 ` jakub at gcc dot gnu.org
@ 2022-12-12 16:38 ` rguenth at gcc dot gnu.org
  2022-12-13 10:41 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-12 16:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.

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

* [Bug tree-optimization/108076] [10/11/12/13 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (4 preceding siblings ...)
  2022-12-12 16:38 ` rguenth at gcc dot gnu.org
@ 2022-12-13 10:41 ` cvs-commit at gcc dot gnu.org
  2022-12-13 10:56 ` [Bug tree-optimization/108076] [10/11/12 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-13 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:b4fddbe9592e9feb37ce567d90af822b75995531

commit r13-4630-gb4fddbe9592e9feb37ce567d90af822b75995531
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 12 17:52:46 2022 +0100

    tree-optimization/108076 - if-conversion and forced labels

    When doing if-conversion we simply throw away labels without checking
    whether they are possibly targets of non-local gotos or have their
    address taken.  The following rectifies this and refuses to if-convert
    such loops.

            PR tree-optimization/108076
            * tree-if-conv.cc (if_convertible_loop_p_1): Reject blocks
            with non-local or forced labels that we later remove
            labels from.

            * gcc.dg/torture/pr108076.c: New testcase.

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

* [Bug tree-optimization/108076] [10/11/12 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (5 preceding siblings ...)
  2022-12-13 10:41 ` cvs-commit at gcc dot gnu.org
@ 2022-12-13 10:56 ` rguenth at gcc dot gnu.org
  2023-01-24 14:27 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-13 10:56 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|                            |13.0
            Summary|[10/11/12/13 Regression]    |[10/11/12 Regression] GCC
                   |GCC with -O3 produces code  |with -O3 produces code
                   |which fails to link         |which fails to link

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar.

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

* [Bug tree-optimization/108076] [10/11/12 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (6 preceding siblings ...)
  2022-12-13 10:56 ` [Bug tree-optimization/108076] [10/11/12 " rguenth at gcc dot gnu.org
@ 2023-01-24 14:27 ` cvs-commit at gcc dot gnu.org
  2023-05-02 12:03 ` [Bug tree-optimization/108076] [10/11 " cvs-commit at gcc dot gnu.org
  2023-07-07 10:06 ` [Bug tree-optimization/108076] [10 " rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-24 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:a3dfcaac560f5589028fdd967bfaa60d84c265ac

commit r12-9064-ga3dfcaac560f5589028fdd967bfaa60d84c265ac
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 12 17:52:46 2022 +0100

    tree-optimization/108076 - if-conversion and forced labels

    When doing if-conversion we simply throw away labels without checking
    whether they are possibly targets of non-local gotos or have their
    address taken.  The following rectifies this and refuses to if-convert
    such loops.

            PR tree-optimization/108076
            * tree-if-conv.cc (if_convertible_loop_p_1): Reject blocks
            with non-local or forced labels that we later remove
            labels from.

            * gcc.dg/torture/pr108076.c: New testcase.

    (cherry picked from commit b4fddbe9592e9feb37ce567d90af822b75995531)

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

* [Bug tree-optimization/108076] [10/11 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-01-24 14:27 ` cvs-commit at gcc dot gnu.org
@ 2023-05-02 12:03 ` cvs-commit at gcc dot gnu.org
  2023-07-07 10:06 ` [Bug tree-optimization/108076] [10 " rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-02 12:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:893b9d8d7df3f6134aa4dd5f501db652448df41f

commit r11-10674-g893b9d8d7df3f6134aa4dd5f501db652448df41f
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 12 17:52:46 2022 +0100

    tree-optimization/108076 - if-conversion and forced labels

    When doing if-conversion we simply throw away labels without checking
    whether they are possibly targets of non-local gotos or have their
    address taken.  The following rectifies this and refuses to if-convert
    such loops.

            PR tree-optimization/108076
            * tree-if-conv.c (if_convertible_loop_p_1): Reject blocks
            with non-local or forced labels that we later remove
            labels from.

            * gcc.dg/torture/pr108076.c: New testcase.

    (cherry picked from commit b4fddbe9592e9feb37ce567d90af822b75995531)

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

* [Bug tree-optimization/108076] [10 Regression] GCC with -O3 produces code which fails to link
  2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-05-02 12:03 ` [Bug tree-optimization/108076] [10/11 " cvs-commit at gcc dot gnu.org
@ 2023-07-07 10:06 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to fail|                            |10.5.0
         Resolution|---                         |FIXED
   Target Milestone|10.5                        |11.4

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-07-07 10:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 14:53 [Bug c/108076] New: GCC with -O3 produces code which fails to link martid0311 at gmail dot com
2022-12-12 14:54 ` [Bug c/108076] " martid0311 at gmail dot com
2022-12-12 15:15 ` [Bug tree-optimization/108076] [10/11/12/13 Regression] " amonakov at gcc dot gnu.org
2022-12-12 16:19 ` pinskia at gcc dot gnu.org
2022-12-12 16:30 ` jakub at gcc dot gnu.org
2022-12-12 16:38 ` rguenth at gcc dot gnu.org
2022-12-13 10:41 ` cvs-commit at gcc dot gnu.org
2022-12-13 10:56 ` [Bug tree-optimization/108076] [10/11/12 " rguenth at gcc dot gnu.org
2023-01-24 14:27 ` cvs-commit at gcc dot gnu.org
2023-05-02 12:03 ` [Bug tree-optimization/108076] [10/11 " cvs-commit at gcc dot gnu.org
2023-07-07 10:06 ` [Bug tree-optimization/108076] [10 " rguenth 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).