diff mbox series

ia64: fix dl-sysdep miscompilation on gcc-10

Message ID 20200516135332.3969575-1-slyich@gmail.com
State New
Headers show
Series ia64: fix dl-sysdep miscompilation on gcc-10 | expand

Commit Message

Bae, Chang Seok via Libc-alpha May 16, 2020, 1:53 p.m. UTC
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
```

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.

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(-)

Comments

Adhemerval Zanella May 20, 2020, 7:45 p.m. UTC | #1
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"				\
>
Sergei Trofimovich May 31, 2020, 7:34 p.m. UTC | #2
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)


> > 
> > 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"				\
> >
Sergei Trofimovich May 31, 2020, 9:40 p.m. UTC | #3
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 :(

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
 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

Local compiler was build from today's gcc-master as:

#!/bin/bash

../gcc/configure \
    \
    --build=x86_64-pc-linux-gnu \
    --host=x86_64-pc-linux-gnu \
    --target=ia64-unknown-linux-gnu \
    \
    --with-sysroot=/usr/ia64-unknown-linux-gnu \
    --enable-languages=c \
    --disable-bootstrap \
    --prefix="$(pwd)/../gcc-ia64-installed" \
    \
    --enable-languages=c \
    --disable-nls \
    \
    CFLAGS="-O1" CXXFLAGS="-O1" LDFLAGS="-O1" \
    "$@"
Adhemerval Zanella June 5, 2020, 6:44 p.m. UTC | #4
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 ;)

> 
> 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.

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.
Sergei Trofimovich June 5, 2020, 9:31 p.m. UTC | #5
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 :)
diff mbox series

Patch

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"				\