Bug 119158 - Using __attribute__((cold)) results in error: Assembler messages: Error: can't resolve .text.unlikely - .L2
Summary: Using __attribute__((cold)) results in error: Assembler messages: Error: can'...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 14.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure
Depends on:
Blocks:
 
Reported: 2025-03-07 14:13 UTC by Ralph Eastwood
Modified: 2025-03-11 20:57 UTC (History)
3 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail: 13.2.0, 14.2.1
Last reconfirmed: 2025-03-07 00:00:00


Attachments
Reduced test case of computed goto and __attribute__((cold)) (125 bytes, text/plain)
2025-03-07 14:13 UTC, Ralph Eastwood
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Eastwood 2025-03-07 14:13:14 UTC
Created attachment 60678 [details]
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
Comment 1 Drea Pinski 2025-03-07 18:27:04 UTC
Confirmed.

The bug is -freorder-blocks-and-partition does not take into account forced labels need to be in the same partition as the main function.