https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123552
Bug ID: 123552
Summary: Linker error that gets fixed by adding an optimization
flag
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: luydorarko at vusra dot com
Target Milestone: ---
Created attachment 63322
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63322&action=edit
Preprocessed input file
Output of `gcc -v`:
```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.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,cobol
--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 15.2.1 20251112 (GCC)
```
Command line that causes linking error:
```
$ gcc bradlucier.c
/usr/bin/ld: /tmp/cc1573V1.o: in function `nonsense':
bradlucier.c:(.text+0x3f): undefined reference to `sqrt'
/usr/bin/ld: bradlucier.c:(.text+0x93): undefined reference to `sqrt'
/usr/bin/ld: bradlucier.c:(.text+0xd8): undefined reference to `sqrt'
/usr/bin/ld: bradlucier.c:(.text+0x121): undefined reference to `sqrt'
/usr/bin/ld: bradlucier.c:(.text+0x166): undefined reference to `sqrt'
/usr/bin/ld: /tmp/cc1573V1.o:bradlucier.c:(.text+0x1af): more undefined
references to `sqrt' follow
collect2: error: ld returned 1 exit status
```
Adding a completely unrelated optimization flag fixes the linking error:
```
$ gcc bradlucier.c -O1 # creates a.out successfully
$
```