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

            Bug ID: 119158
           Summary: Using __attribute__((cold)) results in error:
                    Assembler messages: Error: can't resolve
                    .text.unlikely - .L2
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: caffe at disroot dot org
  Target Milestone: ---

Created attachment 60678
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60678&action=edit
Reduced test case of computed goto and __attribute__((cold))

Attached reduced test case: cold_cgoto_reduce.c

-O2 optimizations triggers the bug.  -fno-reorder-functions works.  Removing
__attribute__((cold)) works.  Affects multiple versions, tested 13.2.0 and
14.2.1.

Output:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20250207 (GCC)

$ gcc -O2 -c cold_cgoto_reduce.c
/tmp/ccNktHIM.s: Assembler messages:
/tmp/ccNktHIM.s:43: Error: can't resolve .text.unlikely - .L2

$ gcc -O2 -fno-reorder-functions -c cold_cgoto_reduce.c && echo ok
ok

Additional information for context:

This was discovered while testing re2c's new code generation which utilizes
computed-gotos with an offset as described in the last part of
https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

Reply via email to