Segmentation fault in /usr/bin/arm-linux-gnueabi-ld.bfd when cross-compiling with clang-10 using LTO
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
binutils (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Hello,
For a project I'm working on, I have prepared an Ubuntu 20.04 chroot environment using debootstrap:
# lsb_release -a
LSB Version: core-11.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
In this environment I have installed various compilers and cross-compilers, in order to build a couple of open-source software packages for x86, amd64, arm and aarch64. When cross-compiling coreutils-3.82 for arm using clang-10 and -flto -fsanitize=cfi, I get the following crash (instructions on how to reproduce are given later on):
# gdb /software/
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
...
(gdb) set follow-fork-mode child
(gdb) run -target armv7-linux-gnueabi -I /usr/arm-
Starting program: /software/
...
Thread 2.1 "ld" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7c90100 (LWP 1132)]
elf32_arm_
root_
17986 ../../bfd/
(gdb) bt
#0 elf32_arm_
root_
#1 0x00007ffff7f1ebf6 in elf32_arm_
func=<optimized out>) at ../../bfd/
#2 0x00007ffff7f57c7e in bfd_elf_final_link (abfd=abfd@
at ../../bfd/
#3 0x00007ffff7f28b1b in elf32_arm_
#4 0x000055555557850f in ldwrite () at ../../ld/
#5 0x0000555555560469 in main (argc=<optimized out>, argv=<optimized out>) at ../../ld/
(gdb) x/10i $pc
=> 0x7ffff7f1e520 <elf32_
0x7ffff7f1e524 <elf32_
0x7ffff7f1e52a <elf32_
0x7ffff7f1e52c <elf32_
0x7ffff7f1e52e <elf32_
0x7ffff7f1e530 <elf32_
0x7ffff7f1e532 <elf32_
0x7ffff7f1e533 <elf32_
0x7ffff7f1e536 <elf32_
0x7ffff7f1e537 <elf32_
(gdb) i r rdx
rdx 0x2e3174706f746567 3328569625858565479
(gdb) x/16bx $rdx
0x2e3174706f746567: Cannot access memory at address 0x2e3174706f746567
Notice how $rdx has been overwritten with the value "getopt1." :-)
To reproduce, download coreutils-3.82 and extract it, say, under /tmp.
Next, create the following symbolic links (I do this because afaik it's an alternative to specifying -triplet in CFLAGS, CXXFLAGS and LDFLAGS):
# ls -la /software/
lrwxrwxrwx 1 root root 19 May 30 17:07 /software/
lrwxrwxrwx 1 root root 17 May 30 17:07 /software/
lrwxrwxrwx 1 root root 21 May 30 17:07 /software/
Then, from within /tmp/coreutils-
# mkdir build
# cd build
# ../configure --host=
CC=
CFLAGS="-I /usr/arm-
CXX=
CXXFLAGS="-I /usr/arm-
CPP=
CPPFLAGS="-I /usr/arm-
LDFLAGS="-L /usr/arm-
RANLIB=
AR="llvm-ar-10"
# make
A couple of minutes later the build process will fail with a segmentation fault. To see the faulting command:
# make V=1
...
/software/
clang: error: unable to execute command: Segmentation fault (core dumped)
After installing binutils-
# apt-cache policy binutils-
binutils-
Installed: 2.34-6ubuntu1.1
Candidate: 2.34-6ubuntu1.1
Version table:
*** 2.34-6ubuntu1.1 500
500 http://
500 http://
100 /var/lib/
2.34-6ubuntu1 500
500 http://