[Bug gprofng/32241] gprofng can't be built with LTO

2024-10-06 Thread lantw44 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=32241

--- Comment #14 from 藍挺瑋  ---
(In reply to H.J. Lu from comment #10)
> Created attachment 15731 [details]
> A patch
> 
> Try this.

Thank you. This patch fixes the build for me.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/32241] New: Binutils can't build itself with -flto=auto -ffat-lto-objects

2024-10-05 Thread lantw44 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=32241

Bug ID: 32241
   Summary: Binutils can't build itself with -flto=auto
-ffat-lto-objects
   Product: binutils
   Version: 2.44 (HEAD)
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: lantw44 at gmail dot com
  Target Milestone: ---

Binutils 2.43, 2.43.1, and the current master branch, can't link gprofng with
CFLAGS='-flto=auto -ffat-lto-objects' CXXFLAGS='-flto=auto -ffat-lto-objects'.
It always fails with an undefined reference to `get_prog_name' error.

To reproduce, build binutils on a system with Binutils 2.43, such as Fedora 41
and Arch Linux, or just build Binutils twice. Run the configure script with
CFLAGS='-flto=auto -ffat-lto-objects' CXXFLAGS='-flto=auto -ffat-lto-objects'
and watch it fail:

/bin/sh ../libtool  --tag=CXX   --mode=link g++ -Wall -pthread -Wno-switch
-flto=auto -ffat-lto-objects   -o gp-archive gp-archive.o ArchiveExp.o
libgprofng.la  -L../../zlib -lz
libtool: link: g++ -Wall -pthread -Wno-switch -flto=auto -ffat-lto-objects -o
gp-archive gp-archive.o ArchiveExp.o  ./.libs/libgprofng.a
-L/path/to/binutils-gdb/zlib -L/path/to/binutils-gdb/libiberty
/path/to/binutils-gdb/opcodes/.libs/libopcodes.a
/path/to/binutils-gdb/bfd/.libs/libbfd.a -lzstd
/path/to/binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread -ldl -lz
-pthread
/path/to/prefix/bin/ld: ./.libs/libgprofng.a(dbe_memmgr.o): in function
`err_out_of_memory':
dbe_memmgr.c:(.text+0x11): undefined reference to `get_prog_name'
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:696: gp-archive] 錯誤 1
make[5]: 離開目錄「/path/to/binutils-gdb/gprofng/src」
make[4]: *** [Makefile:573: all] 錯誤 2

There are several ways known to avoid the problem:

1. Run configure with --enable-shared. This is why Fedora and Arch can
successfully build their packages.
2. Downgrade to Binutils 2.41. I haven't tested 2.42. I just found the same
version could be built on Fedora 40.
3. Don't use -flto=auto -ffat-lto-objects. But these flags are automatically
added when building packages on some distributions.
4. Link gprofng with ld.gold. Copy the link command libtool printed and add
-fuse-ld-gold. It succeeded. This issue seems to be specific to ld.bfd. ld.gold
isn't affected.

I also tried to remove util.o and dbe_memmgr.o from libgprofng.a and manually
them back on the command line. It succeeded. It seems to me that ld.bfd can
handle .o files without problem. It just has problems with .a files.

-- 
You are receiving this mail because:
You are on the CC list for the bug.