[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

H.J. Lu  changed:

   What|Removed |Added

 Resolution|--- |FIXED
   Target Milestone|--- |2.42
 Status|NEW |RESOLVED

--- Comment #7 from H.J. Lu  ---
Fixed for 2.42.

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

--- Comment #6 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by H.J. Lu :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bac5753ca24bbbd601b6be93faa40e9458d8baa5

commit bac5753ca24bbbd601b6be93faa40e9458d8baa5
Author: H.J. Lu 
Date:   Wed Aug 30 08:49:15 2023 -0700

elf: Check DT_SYMTAB only on non-IR object

Check DT_SYMTAB only on non-IR object of archive member to avoid crash
on LLVM IR object with NULL elf_tdata.

PR ld/30811
* elflink.c (elf_link_is_defined_archive_symbol): Check
DT_SYMTAB only on non-IR object.

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

H.J. Lu  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 CC||hjl.tools at gmail dot com
   Last reconfirmed||2023-08-30
 Ever confirmed|0   |1

--- Comment #5 from H.J. Lu  ---
A patch is posted at

https://sourceware.org/pipermail/binutils/2023-August/129300.html

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread du.paul136 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

--- Comment #4 from Paul Du  ---
Oops, I forgot to add that the problem disappears if I do:
- Remove -flto=thin from the compiler & linker flags

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread du.paul136 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

--- Comment #3 from Paul Du  ---
To test the example, you can either:
- Run manual_build.sh
- Use the CMakeLists.txt like that: mkdir build && cd build &&
CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -DCMAKE_BUILD_TYPE=Release -GNinja
.. && ninja -v

When I try to build this on ArchLinux or Ubuntu 23.10 (both on new installs
with a docker image), I get a segmentation fault.

The result of ./manual_build.sh is:

clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation:
/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/13.2.1
Found candidate GCC installation:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/ld" -pie --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -o out/main
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib64/Scrt1.o
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib64/crti.o
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/crtbeginS.o
-L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1
-L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib -L/lib -L/usr/lib -plugin
/usr/bin/../lib/LLVMgold.so -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto
out/exec.o out/libutils.a -lstdc++ -lm -lomp -rpath /usr/lib -L/usr/lib -lgcc_s
-lgcc -lpthread -lc -lgcc_s -lgcc
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/crtendS.o
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib64/crtn.o
clang-16: error: unable to execute command: Segmentation fault (core dumped)
clang-16: error: linker command failed due to signal (use -v to see invocation)

coredumpctl debug gave me something like this:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x7f6cb8650e6f in elf_link_is_defined_archive_symbol
(symdef=0x559325125800, abfd=0x559325118be0) at
/usr/src/debug/binutils/binutils-gdb/bfd/elflink.c:3574
3574  if (elf_use_dt_symtab_p (abfd))   
(gdb) bt
#0  0x7f6cb8650e6f in elf_link_is_defined_archive_symbol
(symdef=0x559325125800, abfd=0x559325118be0) at
/usr/src/debug/binutils/binutils-gdb/bfd/elflink.c:3574
#1  elf_link_add_archive_symbols (abfd=0x559325118940, info=0x5593246c0c40
) at /usr/src/debug/binutils/binutils-gdb/bfd/elflink.c:6078
#2  0x5593245dbf8f in load_symbols (entry=entry@entry=0x559325014030,
place=place@entry=0x7ffcdbec9b80) at
/usr/src/debug/binutils/binutils-gdb/ld/ldlang.c:3098
#3  0x5593245dbcdd in open_input_bfds (s=0x559325014030,
mode=OPEN_BFD_RESCAN) at /usr/src/debug/binutils/binutils-gdb/ld/ldlang.c:3587
#4  0x5593245b8478 in lang_process () at
/usr/src/debug/binutils/binutils-gdb/ld/ldlang.c:8196
#5  0x5593245e2c21 in main (argc=41, argv=) at
/usr/src/debug/binutils/binutils-gdb/ld/ldmain.c:501


The problem disappears if I do one of the following:
- Change the compiler to GCC
- Remove #pragma omp critical from utils.cpp
- Add -fuse-ld=gold to LDFLAGS
- Don't create a static library but link with out/utils.o instead
- Run it on Ubuntu 22.04 or 23.04 (binutils < 2.41)

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread du.paul136 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

Paul Du  changed:

   What|Removed |Added

  Attachment #15095|0   |1
is obsolete||

--- Comment #2 from Paul Du  ---
Created attachment 15096
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15096=edit
Minimal reproducible example

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


[Bug ld/30811] bfd segfault with clang LTO and OpenMP

2023-08-30 Thread du.paul136 at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30811

--- Comment #1 from Paul Du  ---
Created attachment 15095
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15095=edit
main file

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