Bug 28894 - segfault when building openjdk13 on x86 32bit (binutils 2.38 regression)
Summary: segfault when building openjdk13 on x86 32bit (binutils 2.38 regression)
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.39
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-15 10:51 UTC by Jan Palus
Modified: 2022-02-16 13:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-02-15 00:00:00


Attachments
the version script (22.24 KB, text/plain)
2022-02-15 18:33 UTC, Pierre Labastie
Details
the object file where the failure occurs (115.57 KB, application/x-object)
2022-02-15 19:03 UTC, Pierre Labastie
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Palus 2022-02-15 10:51:07 UTC
After switching to binutils 2.38 openjdk13 build failed on i686 with error:

/usr/bin/ld: /tmp/B.zx6ygnoi/BUILD/jdk13u-jdk-13.0.10-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/acce
ss.o: warning: relocation in read-only section `.text._ZN14AccessInternal15RuntimeDispatchILy16464EP7oopDescLNS_11BarrierTypeE1
1EE11equals_initES2_S2_[_ZN14AccessInternal15RuntimeDispatchILy16464EP7oopDescLNS_11BarrierTypeE11EE11equals_initES2_S2_]'
/usr/bin/ld: BFD (GNU Binutils) 2.38 assertion fail elfxx-x86.c:529
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.

Just before upgrading binutils another build was successful with binutils 2.37. Note that x86_64 build succeeded with binutils 2.38.

gcc 11.2.0 (with most of patches from gcc-11 patch)
glibc 2.35
Comment 1 H.J. Lu 2022-02-15 16:22:09 UTC
Please provide ALL linker inputs so that I can reproduce it on
totally different machines.
Comment 2 Pierre Labastie 2022-02-15 18:33:06 UTC
Created attachment 13980 [details]
the version script
Comment 3 Pierre Labastie 2022-02-15 18:40:49 UTC
I have a similar issue with openjdk-17.0.2 (in a 32 bit VM):
/usr/bin/ld: /sources/openjdk/jdk17u-jdk-17.0.2-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/adaptiveSizePolicy.o: warning: relocation in read-only section `.text'
/usr/bin/ld: BFD (GNU Binutils) 2.38 assertion fail ../../bfd/elfxx-x86.c:529
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.

The command line leading to that is:
/usr/bin/g++ -Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-O1 -Wl,--hash-style=gnu -march=i586 -m32 -shared -m32 -Wl,-version-script=/sources/openjdk/jdk17u-jdk-17.0.2-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/mapfile -Wl,-soname=libjvm.so -o /sources/openjdk/jdk17u-jdk-17.0.2-ga/build/linux-x86-server-release/support/modules_libs/java.base/server/libjvm.so @/sources/openjdk/jdk17u-jdk-17.0.2-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/_BUILD_LIBJVM_objectfilenames.txt -lm -ldl -lpthread -lrt

I have attached the "version-script". The compressed directory objs (that contains all the object files unless I've missed something) will be attached next
Comment 4 Pierre Labastie 2022-02-15 18:57:28 UTC
Problem is the compressed objs directory is ~240MB
I cannot attach it. Don't know I can reduce it, sorry.
Comment 5 Pierre Labastie 2022-02-15 19:03:35 UTC
Created attachment 13983 [details]
the object file where the failure occurs
Comment 6 Jan Palus 2022-02-15 19:12:42 UTC
Confirmed that issue also occurs on glibc 2.34.

In my case command line is:

/usr/bin/i686-pld-linux-g++ -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,relro -Wl,-z,noexecstack -Wl,-O1 -march=i586 -m32 -Wl,--as-needed -Wl,--no-copy-dt-needed-entries -Wl,-z,relro -Wl,-z,combreloc -static-libstdc++ -static-libgcc -shared -m32 -Wl,--as-needed -Wl,--no-copy-dt-needed-entries -Wl,-z,relro -Wl,-z,combreloc -Wl,-version-script=/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/mapfile -Wl,-soname=libjvm.so -o /home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/linux-x86-server-release/support/modules_libs/java.base/server/libjvm.so @/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/_BUILD_LIBJVM_objectfilenames.txt -lm -ldl -lpthread

version script: http://jpalus.fastmail.com/version-script
all object files: http://jpalus.fastmail.com/objs.tar.xz
Comment 7 H.J. Lu 2022-02-15 19:43:35 UTC
(In reply to Jan Palus from comment #6)
> Confirmed that issue also occurs on glibc 2.34.
> 
> In my case command line is:
> 
> /usr/bin/i686-pld-linux-g++ -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,relro
> -Wl,-z,noexecstack -Wl,-O1 -march=i586 -m32 -Wl,--as-needed
> -Wl,--no-copy-dt-needed-entries -Wl,-z,relro -Wl,-z,combreloc
> -static-libstdc++ -static-libgcc -shared -m32 -Wl,--as-needed
> -Wl,--no-copy-dt-needed-entries -Wl,-z,relro -Wl,-z,combreloc
> -Wl,-version-script=/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-
> jdk-13.0.10-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/
> mapfile -Wl,-soname=libjvm.so -o
> /home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/
> linux-x86-server-release/support/modules_libs/java.base/server/libjvm.so
> @/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/
> linux-x86-server-release/hotspot/variant-server/libjvm/objs/
> _BUILD_LIBJVM_objectfilenames.txt -lm -ldl -lpthread
> 
> version script: http://jpalus.fastmail.com/version-script
> all object files: http://jpalus.fastmail.com/objs.tar.xz

Please provide @/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/_BUILD_LIBJVM_objectfilenames.txt
Comment 8 H.J. Lu 2022-02-15 19:47:12 UTC
(In reply to H.J. Lu from comment #7)
> 
> Please provide
> @/home/users/atler/rpm/packages/BUILD.i686-linux/jdk13u-jdk-13.0.10-ga/build/
> linux-x86-server-release/hotspot/variant-server/libjvm/objs/
> _BUILD_LIBJVM_objectfilenames.txt

No need for it.
Comment 9 Pierre Labastie 2022-02-15 20:17:46 UTC
To be complete, my toolchain is:
gcc-11.2.0, glibc-2.35, bintuils-2.38

I've installed binutils-2.37 and run the exact same command (that is, not recompiling the object files). Still, I see the warning:
/usr/bin/ld: /sources/openjdk/jdk17u-jdk-17.0.2-ga/build/linux-x86-server-release/hotspot/variant-server/libjvm/objs/adaptiveSizePolicy.o: warning: relocation in read-only section `.text'

But then I see:
/usr/bin/ld: warning: creating DT_TEXTREL in a shared object

and the link succeeds. Trying to bisect from 2.37 to 2.38
Comment 10 H.J. Lu 2022-02-15 22:15:01 UTC
It is caused by

3747999c6bd40a7ac905ef306a82214b336067b6 is the first bad commit
commit 3747999c6bd40a7ac905ef306a82214b336067b6
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Dec 27 10:13:06 2021 -0800

    ld: Extract _bfd_elf_link_iterate_on_relocs
Comment 11 H.J. Lu 2022-02-15 22:30:35 UTC
[hjl@gnu-tgl-3 pr28894]$ cat x.s
	.text
	addl	foo@INDNTPOFF, %eax
	.section .tbss,"awT",@nobits
	.globl	foo
	.hidden foo
foo:
	.byte 0
[hjl@gnu-tgl-3 pr28894]$ gcc -c -m32 x.s
[hjl@gnu-tgl-3 pr28894]$ ld -shared  -m elf_i386  x.o
ld: BFD (Linux/GNU Binutils) 2.38.50.0.1.20220212 assertion fail /export/linux/src/binutils/binutils/bfd/elfxx-x86.c:547
Segmentation fault (core dumped)
[hjl@gnu-tgl-3 pr28894]$
Comment 12 Sourceware Commits 2022-02-15 23:11:44 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit 3319ba7a8d6a42ba071d691789bc184632399331
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 15 15:03:02 2022 -0800

    i386: Update I386_NEED_DYNAMIC_RELOC_TYPE_P for DT_TEXTREL
    
    Update I386_NEED_DYNAMIC_RELOC_TYPE_P to allow R_386_TLS_IE for relocation
    in read-only section.
    
    bfd/
    
            PR ld/28894
            * elfxx-x86.h (I386_NEED_DYNAMIC_RELOC_TYPE_P): Allow
            R_386_TLS_IE.
    
    ld/
            PR ld/28894
            * testsuite/ld-i386/i386.exp: Run pr28894.
            * testsuite/ld-i386/pr28894.d: New file.
            * testsuite/ld-i386/pr28894.s: Likewise.
Comment 13 Sourceware Commits 2022-02-15 23:16:23 UTC
The binutils-2_38-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit ae1cab7d3f39686d9c7ddadbac297e9ae76ffccf
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 15 15:03:02 2022 -0800

    i386: Update I386_NEED_DYNAMIC_RELOC_TYPE_P for DT_TEXTREL
    
    Update I386_NEED_DYNAMIC_RELOC_TYPE_P to allow R_386_TLS_IE for relocation
    in read-only section.
    
    bfd/
    
            PR ld/28894
            * elfxx-x86.h (I386_NEED_DYNAMIC_RELOC_TYPE_P): Allow
            R_386_TLS_IE.
    
    ld/
            PR ld/28894
            * testsuite/ld-i386/i386.exp: Run pr28894.
            * testsuite/ld-i386/pr28894.d: New file.
            * testsuite/ld-i386/pr28894.s: Likewise.
    
    (cherry picked from commit 3319ba7a8d6a42ba071d691789bc184632399331)
Comment 14 H.J. Lu 2022-02-15 23:17:02 UTC
Fixed for 2.39 and on 2.38 branch.
Comment 15 Jan Palus 2022-02-15 23:52:11 UTC
Confirmed openjdk builds fine with above fix. Thanks!
Comment 16 Pierre Labastie 2022-02-16 13:05:48 UTC
A little late to the party, openjdk-17 builds again too. Thanks for the quick fix.