[PATCH] ia64: fix dl-sysdep miscompilation on gcc-10
Sergei Trofimovich
slyich@gmail.com
Fri Jun 5 21:31:19 GMT 2020
On Fri, 5 Jun 2020 15:44:24 -0300
Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> On 31/05/2020 18:40, Sergei Trofimovich wrote:
> > On Sun, 31 May 2020 20:34:43 +0100
> > Sergei Trofimovich <slyich@gmail.com> wrote:
> >
> >> On Wed, 20 May 2020 16:45:03 -0300
> >> Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> wrote:
> >>
> >>> On 16/05/2020 10:53, slyich--- via Libc-alpha wrote:
> >>>> From: Sergei Trofimovich <slyfox@gentoo.org>
> >>>>
> >>>> gcc-10 enabled -fno-common by default. This caused glibc link failure:
> >>>>
> >>>> ```
> >>>> $ ia64-unknown-linux-gnu-gcc -pipe -O2 -nostdlib -nostartfiles \
> >>>> -static -o .../elf/sln ...
> >>>> libc.a(dl-support.o): in function `setup_vdso':
> >>>> glibc-2.31/elf/setup-vdso.h:116:(.text+0x1322):
> >>>> relocation truncated to fit: GPREL22 against `.text'
> >>>> collect2: error: ld returned 1 exit status
> >>>> ```
> >>>
> >>> I can't reproduce it with master (b6ad64b907ab00) with GCC 10.1.1 20200520.
> >>> (built using build-many-glibcs.py). I tried to explicit use -fno-common on
> >>> CFLAGS. Are you sing a non default compiler option?
> >>
> >> My apologies. Missed your email.
> >>
> >> The CFLAGS options should be default. Full command is:
> >>
> >> """
> >> ia64-unknown-linux-gnu-gcc -pipe -fdiagnostics-show-option -Wall -Wextra -Wstack-protector -O2 -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu dl-support.c -c -std=gnu11 -fgnu89-inline -pipe -fdiagnostics-show-option -Wall -Wextra -Wstack-protector -O2 -Wall -Wwrite-strings -Wundef -fmerge-all-constants -frounding-math -fno-stack-protector -Wstrict-prototypes -Wold-style-definition -fmath-errno -fpie -ftls-model=initial-exec -U_FORTIFY_SOURCE -I../include -I/tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl/elf -I/tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl -I../sysdeps/unix/sysv/linux/ia64 -I../sysdeps/ia64/nptl -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread -I../sysdeps/gnu -I../sysdeps/unix/inet -I../sysdeps/unix/sysv -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/ia64/fpu -I../sysdeps/ia64 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754 -I../sysdeps/generic -I.. -I../libio -I. -nostdinc -isystem /usr/lib/gcc/ia64-unknown-linux-gnu/10.1.0/include -isystem /usr/lib/gcc/ia64-unknown-linux-gnu/10.1.0/include-fixed -isystem /usr/ia64-unknown-linux-gnu/usr/include -D_LIBC_REENTRANT -include /tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl/libc-modules.h -DMODULE_NAME=libc -include ../include/libc-symbols.h -DPIC -DTOP_NAMESPACE=glibc -o /tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl/elf/dl-support.o -MD -MP -MF /tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl/elf/dl-support.o.dt -MT /tmp/portage/cross-ia64-unknown-linux-gnu/glibc-2.31-r3/work/build-default-ia64-unknown-linux-gnu-nptl/elf/dl-support.o
> >> """
> >>
> >> Might be an effect of default --enable-default-pie --enable-default-ssp.
> >> Or an effect of applied GCC patch: https://gcc.gnu.org/PR84553
> >>
> >> I can try to extract smaller .c example that generates unlinkable
> >> GPREL22 against cross-section symbols if it's useful.
> >>
> >> $ LANG=C ia64-unknown-linux-gnu-gcc -v
> >> # Using built-in specs.
> >> COLLECT_GCC=/usr/bin/ia64-unknown-linux-gnu-gcc
> >> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ia64-unknown-linux-gnu/10.1.0/lto-wrapper
> >> Target: ia64-unknown-linux-gnu
> >> Configured with: /tmp/portage-tmpdir/portage/cross-ia64-unknown-linux-gnu/gcc-10.1.0/work/gcc-10.1.0/configure --host=x86_64-pc-linux-gnu --target=ia64-unknown-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/ia64-unknown-linux-gnu/gcc-bin/10.1.0 --includedir=/usr/lib/gcc/ia64-unknown-linux-gnu/10.1.0/include --datadir=/usr/share/gcc-data/ia64-unknown-linux-gnu/10.1.0 --mandir=/usr/share/gcc-data/ia64-unknown-linux-gnu/10.1.0/man --infodir=/usr/share/gcc-data/ia64-unknown-linux-gnu/10.1.0/info --with-gxx-include-dir=/usr/lib/gcc/ia64-unknown-linux-gnu/10.1.0/include/g++-v10 --with-python-dir=/share/gcc-data/ia64-unknown-linux-gnu/10.1.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 10.1.0 p1' --disable-esp --enable-libstdcxx-time --enable-poison-system-directories --with-sysroot=/usr/ia64-unknown-linux-gnu --disable-bootstrap --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-altivec --disable-fixed-point --enable-libgomp --disable-libmudflap --disable-libssp --disable-libada --disable-systemtap --disable-vtable-verify --disable-libvtv --without-zstd --enable-lto --without-isl --disable-libsanitizer --enable-default-pie --enable-default-ssp
> >> Thread model: posix
> >> Supported LTO compression algorithms: zlib
> >> gcc version 10.1.0 (Gentoo 10.1.0 p1)
> >
> > Tl;DR:
> >
> > I think I managed to write small reproducer, and I think it illustrates
> > that my fix is not effective and still breaks in some setups :(
>
> In fact I think your testcase has a small typo below ;)
Gah, so simple! Thank you!
> >
> > I hope that helps.
> >
> > Detailed example:
> >
> > $ cat a.c
> > // code reference, avoids function descriptor
> > #ifdef USE_TEXT
> > extern int asm_f __attribute__((visibility("hidden"))) __attribute__((section(".text")));
> > #else
> > extern int asm_f __attribute__((visibility("hidden")));
> > #endif
> >
> > long asm_f_ref;
> >
> > asm (
> > ".text\n\t" \
> > ".hidden asm_f\n\t"
> > ".proc asm_f\n\t"
> > "asm_f:\n\t"
> > ".prologue\n\t"
> > ".body\n\t"
> > "br.ret.sptk.many b0;\n\t"
> > ".endp asm_f\n\t"
> > ".previous"
> > );
> >
> > void _start() {
> > asm_f_ref = (unsigned long)&asm_f;
> > }
> >
> > $ cat mk.bash
> > #!/bin/bash
> >
> > local_cc_root=/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > for define in "" "-DUSE_TEST"; do
>
> I think it should be USE_TEXT instead.
>
> > for static in "" "-static"; do
> > for fpie in "" "-fPIE"; do
> > for common in "-fcommon" "-fno-common"; do
> > echo ""
> > for cc in "ia64-unknown-linux-gnu-gcc" "${local_cc_root}/xgcc -B${local_cc_root}"; do
> > echo "define=${define} static=${static} common=${common} fpie=${fpie} cc=${cc}"
> > LANG=C $cc a.c -o a -O2 -nostdlib -nostartfiles ${static} ${define} ${fpie} ${common}
> > done
> > done
> > done
> > done
> > done
> >
> > Running:
> >
> > $ LANG=C ./mk.bash
> >
> > define= static= common=-fcommon fpie= cc=ia64-unknown-linux-gnu-gcc
> > define= static= common=-fcommon fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define= static= common=-fno-common fpie= cc=ia64-unknown-linux-gnu-gcc
> > define= static= common=-fno-common fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/ccBYnt9X.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define= static= common=-fcommon fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define= static= common=-fcommon fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define= static= common=-fno-common fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define= static= common=-fno-common fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/ccH3sdkO.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define= static=-static common=-fcommon fpie= cc=ia64-unknown-linux-gnu-gcc
> > define= static=-static common=-fcommon fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define= static=-static common=-fno-common fpie= cc=ia64-unknown-linux-gnu-gcc
> > /tmp/ccUvQ1vf.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> > define= static=-static common=-fno-common fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/cc9epOsD.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define= static=-static common=-fcommon fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define= static=-static common=-fcommon fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define= static=-static common=-fno-common fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > /tmp/ccPXdLl4.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> > define= static=-static common=-fno-common fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/cca5Gl7p.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define=-DUSE_TEST static= common=-fcommon fpie= cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static= common=-fcommon fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define=-DUSE_TEST static= common=-fno-common fpie= cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static= common=-fno-common fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/ccodz56d.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define=-DUSE_TEST static= common=-fcommon fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static= common=-fcommon fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define=-DUSE_TEST static= common=-fno-common fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static= common=-fno-common fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/cc7dWmZ3.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define=-DUSE_TEST static=-static common=-fcommon fpie= cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static=-static common=-fcommon fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define=-DUSE_TEST static=-static common=-fno-common fpie= cc=ia64-unknown-linux-gnu-gcc
> > /tmp/ccJ2hnsw.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> > define=-DUSE_TEST static=-static common=-fno-common fpie= cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/ccko7sNT.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> >
> > define=-DUSE_TEST static=-static common=-fcommon fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > define=-DUSE_TEST static=-static common=-fcommon fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> >
> > define=-DUSE_TEST static=-static common=-fno-common fpie=-fPIE cc=ia64-unknown-linux-gnu-gcc
> > /tmp/cchRq1Nl.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
> > define=-DUSE_TEST static=-static common=-fno-common fpie=-fPIE cc=/home/slyfox/dev/git/gcc-ia64/gcc/xgcc -B/home/slyfox/dev/git/gcc-ia64/gcc
> > /tmp/ccgQ5Y6G.o: in function `_start':
> > a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> > collect2: error: ld returned 1 exit status
>
> With the above fix I am seeing:
>
> ---
> define= static= common=-fcommon fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define= static= common=-fno-common fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
> /tmp/ccwUMGjK.o: in function `_start':
> a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> collect2: error: ld returned 1 exit status
>
> define= static= common=-fcommon fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define= static= common=-fno-common fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
> /tmp/cc9nPVOO.o: in function `_start':
> a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> collect2: error: ld returned 1 exit status
>
> define= static=-static common=-fcommon fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define= static=-static common=-fno-common fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
> /tmp/ccV4QyrT.o: in function `_start':
> a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> collect2: error: ld returned 1 exit status
>
> define= static=-static common=-fcommon fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define= static=-static common=-fno-common fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
> /tmp/ccSgHDDW.o: in function `_start':
> a.c:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> collect2: error: ld returned 1 exit status
>
> define=-DUSE_TEXT static= common=-fcommon fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static= common=-fno-common fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static= common=-fcommon fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static= common=-fno-common fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static=-static common=-fcommon fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static=-static common=-fno-common fpie= cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static=-static common=-fcommon fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
>
> define=-DUSE_TEXT static=-static common=-fno-common fpie=-fPIE cc=/home/azanella/toolchain/install/compilers/ia64-linux-gnu/bin/ia64-glibc-linux-gnu-gcc
> ---
>
> So it does seem that using the __attribute__((section(".text"))) does help ia64
> in this case. Due the current status I think it should be a better and
> simpler fix.
I agree.
> The alternative would be remove the _dl_sysinfo_break and rewrite the syscall
> mechanism (in both ASM pre-processor and INTERNAL_SYSCALL macros) to check
> if the _dl_sysinfo is set (meaning a vDSO is present) and issuing the syscall
> with brk if not. It will most likely increase the code size and add some
> latency.
I volunteer to convert to asm call when it breaks next time :)
--
Sergei
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 981 bytes
Desc: ЦиÑÑÐ¾Ð²Ð°Ñ Ð¿Ð¾Ð´Ð¿Ð¸ÑÑ OpenPGP
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20200605/ce832cef/attachment.sig>
More information about the Libc-alpha
mailing list