[PATCH] ia64: fix dl-sysdep miscompilation on gcc-10
Adhemerval Zanella
adhemerval.zanella@linaro.org
Wed May 20 19:45:03 GMT 2020
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?
>
> The difference between gcc-9 and gcc-10 is the way relocation is
> generated for ia64-specific symbol '_dl_sysinfo_break', defined as:
>
> ```c
> 32 #ifndef __ASSEMBLER__
> 33 /* Don't declare this as a function---we want it's entry-point, not
> 34 it's function descriptor... */
> 35 extern int _dl_sysinfo_break attribute_hidden;
> 36 # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
> 37 # define DL_SYSINFO_IMPLEMENTATION \
> 38 asm (".text\n\t" \
> 39 ".hidden _dl_sysinfo_break\n\t" \
> 40 ".proc _dl_sysinfo_break\n\t" \
> ```
>
> Note: it's declared as ".sdata" (defined nearby GOT) but assumed
> to be defined in ".text" as it's really a direct function address.
>
> As a result generated relocation changed from:
>
> from `GPREL64I`:
>
> ```
> 1390: 05 00 84 1e 98 11 [MLX] st8 [r15]=r33
> 1391: GPREL64I .text
> 1396: 00 00 00 00 00 e0 movl r15=0x0;;
> 139c: 01 00 00 60
> 13a0: 0b 78 04 1e 00 20 [MMI] add r15=r1,r15;;
> ```
>
> to `GPREL22`:
>
> ```
> if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)
>
> 1320: 0b 80 00 1c 18 10 [MMI] ld8 r16=[r14];;
> 1322: GPREL22 .text
> 1326: 00 08 3d 30 23 e0 st8 [r15]=r33
> 132c: 01 08 00 90 addl r15=0,r1;;
> ```
>
> This change explicitly declares symbol to be in ".text" section.
> That allows gcc to generate far relocations.
>
> Regression tested on glibc-master and gcc-10.1.0 on rx3600.
The rationale is sound, but the trick to define a function pointer a
data variable on text sections seems hacky and fragile. I still think
it could be a fix, but I think we should refactor and simplify
the over-enginnering of NEED_DL_SYSINFO/USE_DL_SYSINFO.
>
> Bug: https://bugs.gentoo.org/723268
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> ---
> sysdeps/unix/sysv/linux/ia64/dl-sysdep.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
> index 78fa6dd2c9..e526e02ff4 100644
> --- a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
> +++ b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
> @@ -32,7 +32,9 @@
> #ifndef __ASSEMBLER__
> /* Don't declare this as a function---we want it's entry-point, not
> it's function descriptor... */
> -extern int _dl_sysinfo_break attribute_hidden;
> +/* Use section ".text" to force far GPREL64 relocation instead of
> + GPREL22 . */
> +extern int _dl_sysinfo_break attribute_hidden __attribute__((section(".text")));
> # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
> # define DL_SYSINFO_IMPLEMENTATION \
> asm (".text\n\t" \
>
More information about the Libc-alpha
mailing list