diff mbox series

build failure on ia64 (+ patch), "relocation truncated to fit: GPREL22 against `.text'"

Message ID 4817905.GXAFRqVoOG@pinacolada
State New
Headers show
Series build failure on ia64 (+ patch), "relocation truncated to fit: GPREL22 against `.text'" | expand

Commit Message

Andreas K. Huettel July 29, 2023, 6:34 p.m. UTC
When testing a manual build on ia64 we ran (on two different Gentoo machines) into
https://bugs.gentoo.org/723268
https://sourceware.org/pipermail/libc-alpha/2020-May/114028.html

gcc -o /home/dilfridge/glibc_build/support/test-run-command -nostdlib -nostartfiles -static      /home/dilfridge/glibc_build/csu/crt1.o /home/dilfridge/glibc_build/csu/crti.o `gcc  --print-file-name=crtbegin.o` /home/dilfridge/glibc_build/support/test-run-command.o /home/dilfridge/glibc_build/elf/static-stubs.o /home/dilfridge/glibc_build/support/libsupport_nonshared.a  -Wl,--start-group /home/dilfridge/glibc_build/libc.a -lgcc  -Wl,--end-group `gcc  --print-file-name=crtend.o` /home/dilfridge/glibc_build/csu/crtn.o
/usr/lib/gcc/ia64-unknown-linux-gnu/13/../../../../ia64-unknown-linux-gnu/bin/ld: warning: -z relro ignored
/home/dilfridge/glibc_build/libc.a(dl-support.o): in function `_dl_aux_init':
/home/dilfridge/glibc/elf/dl-support.c:239:(.text+0x51): relocation truncated to fit: GPREL22 against `.text'
/home/dilfridge/glibc_build/libc.a(dl-support.o): in function `setup_vdso':
/home/dilfridge/glibc/elf/setup-vdso.h:108:(.text+0xea2): relocation truncated to fit: GPREL22 against `.text'
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:290: /home/dilfridge/glibc_build/support/test-run-command] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/home/dilfridge/glibc/support'
make[1]: *** [Makefile:484: support/others] Error 2
make[1]: Leaving directory '/home/dilfridge/glibc'
make: *** [Makefile:9: all] Error 2

Turns out we have a fix for this in our Gentoo patchset since glibc-2.31, pasted below.

Since this fixes a clear build failure, is localized to sysdeps/unix/sysv/linux/ia64,
and there are no positive test results without it anywhere, I'd like to pull it in for 2.38.

Any objections?

From ed428afb4c6353692fba6cedaa2f9db7bc9fb551 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyfox@gentoo.org>
Date: Sat, 11 Jul 2020 20:06:51 +0300
Subject: [PATCH 4/9] Fix miscompilation on ia64's gcc-10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Bug: https://bugs.gentoo.org/723268
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
---
 sysdeps/unix/sysv/linux/ia64/dl-sysdep.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Adhemerval Zanella Netto July 30, 2023, 12:08 a.m. UTC | #1
On 29/07/23 15:34, Andreas K. Huettel via Libc-alpha wrote:
> When testing a manual build on ia64 we ran (on two different Gentoo machines) into
> https://bugs.gentoo.org/723268
> https://sourceware.org/pipermail/libc-alpha/2020-May/114028.html
> 
> gcc -o /home/dilfridge/glibc_build/support/test-run-command -nostdlib -nostartfiles -static      /home/dilfridge/glibc_build/csu/crt1.o /home/dilfridge/glibc_build/csu/crti.o `gcc  --print-file-name=crtbegin.o` /home/dilfridge/glibc_build/support/test-run-command.o /home/dilfridge/glibc_build/elf/static-stubs.o /home/dilfridge/glibc_build/support/libsupport_nonshared.a  -Wl,--start-group /home/dilfridge/glibc_build/libc.a -lgcc  -Wl,--end-group `gcc  --print-file-name=crtend.o` /home/dilfridge/glibc_build/csu/crtn.o
> /usr/lib/gcc/ia64-unknown-linux-gnu/13/../../../../ia64-unknown-linux-gnu/bin/ld: warning: -z relro ignored
> /home/dilfridge/glibc_build/libc.a(dl-support.o): in function `_dl_aux_init':
> /home/dilfridge/glibc/elf/dl-support.c:239:(.text+0x51): relocation truncated to fit: GPREL22 against `.text'
> /home/dilfridge/glibc_build/libc.a(dl-support.o): in function `setup_vdso':
> /home/dilfridge/glibc/elf/setup-vdso.h:108:(.text+0xea2): relocation truncated to fit: GPREL22 against `.text'
> collect2: error: ld returned 1 exit status
> make[2]: *** [../Rules:290: /home/dilfridge/glibc_build/support/test-run-command] Error 1
> make[2]: *** Waiting for unfinished jobs....
> make[2]: Leaving directory '/home/dilfridge/glibc/support'
> make[1]: *** [Makefile:484: support/others] Error 2
> make[1]: Leaving directory '/home/dilfridge/glibc'
> make: *** [Makefile:9: all] Error 2
> 
> Turns out we have a fix for this in our Gentoo patchset since glibc-2.31, pasted below.
> 
> Since this fixes a clear build failure, is localized to sysdeps/unix/sysv/linux/ia64,
> and there are no positive test results without it anywhere, I'd like to pull it in for 2.38.
> 
> Any objections?
> 
> From ed428afb4c6353692fba6cedaa2f9db7bc9fb551 Mon Sep 17 00:00:00 2001
> From: Sergei Trofimovich <slyfox@gentoo.org>
> Date: Sat, 11 Jul 2020 20:06:51 +0300
> Subject: [PATCH 4/9] Fix miscompilation on ia64's gcc-10
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> Bug: https://bugs.gentoo.org/723268
> Signed-off-by: Andreas K. Hüttel <dilfridge@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 3e4d5da820..eb7681b704 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"				\


It has been proposed before [1] and it seems that it is not really the right
fix. I can't not reproduce it with the gcc built with build-many-glibc.py,
but I don't really expect it to that different from Gentoo.

I think it might be possible to code this in C and obtain its entry-point
directly instead of the ODP for the syscall redirection (I recall I did
something similar for ppc64).

[1] https://sourceware.org/pipermail/libc-alpha/2020-May/114493.html
Andreas K. Huettel July 30, 2023, 12:15 a.m. UTC | #2
> > When testing a manual build on ia64 we ran (on two different Gentoo machines) into
> > https://bugs.gentoo.org/723268
> > https://sourceware.org/pipermail/libc-alpha/2020-May/114028.html
> > 

> It has been proposed before [1] and it seems that it is not really the right
> fix. I can't not reproduce it with the gcc built with build-many-glibc.py,
> but I don't really expect it to that different from Gentoo.

Hmm, interesting. I don't know, but can test.

The build failure popped up immediately when I tried to make a build outside
our build system. Of course this was still using Gentoo's binutils etc.

The patch has been in Gentoo's glibc since July 2020, and I'm not aware of
any problems. Then again, the number of active ia64 users is probably small.

> I think it might be possible to code this in C and obtain its entry-point
> directly instead of the ODP for the syscall redirection (I recall I did
> something similar for ppc64).
> 
> [1] https://sourceware.org/pipermail/libc-alpha/2020-May/114493.html
Florian Weimer July 30, 2023, 8:10 a.m. UTC | #3
* Andreas K. Huettel via Libc-alpha:

> diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
> index 3e4d5da820..eb7681b704 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")));

More context:

| /* 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;
| # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
| # define DL_SYSINFO_IMPLEMENTATION              \
|   asm (".text\n\t"                              \
|        ".hidden _dl_sysinfo_break\n\t"          \
|        ".proc _dl_sysinfo_break\n\t"            \
|        "_dl_sysinfo_break:\n\t"                 \
|        ".prologue\n\t"                          \
|        ".altrp b6\n\t"                          \
|        ".body\n\t"                              \
|        "break 0x100000;\n\t"                    \
|        "br.ret.sptk.many b6;\n\t"               \
|        ".endp _dl_sysinfo_break\n\t"            \
|        ".previous");
| #endif

So this seems actually correct because the symbol is defined in .text.
(I was wondered why this would make .text writable.)
Adhemerval Zanella Netto July 30, 2023, 1:14 p.m. UTC | #4
On 30/07/23 05:10, Florian Weimer wrote:
> * Andreas K. Huettel via Libc-alpha:
> 
>> diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
>> index 3e4d5da820..eb7681b704 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")));
> 
> More context:
> 
> | /* 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;
> | # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
> | # define DL_SYSINFO_IMPLEMENTATION              \
> |   asm (".text\n\t"                              \
> |        ".hidden _dl_sysinfo_break\n\t"          \
> |        ".proc _dl_sysinfo_break\n\t"            \
> |        "_dl_sysinfo_break:\n\t"                 \
> |        ".prologue\n\t"                          \
> |        ".altrp b6\n\t"                          \
> |        ".body\n\t"                              \
> |        "break 0x100000;\n\t"                    \
> |        "br.ret.sptk.many b6;\n\t"               \
> |        ".endp _dl_sysinfo_break\n\t"            \
> |        ".previous");
> | #endif
> 
> So this seems actually correct because the symbol is defined in .text.
> (I was wondered why this would make .text writable.)

That was my understanding back then as well, and I tested myself the testcase
Sergei has created [1] and at least with gcc from 6 to 13 built with 
build-many-glibcs.py I don't see any relocation failure.  But at same time
I don't see any relocation failure with current code either, so I am not
sure why this is happening with Gentoo toolchain (maybe a incomplete backport?).

---
$ cat mk.bash
#!/usr/bin/bash

if [ $# -eq 0 ]; then
  echo "usage: mk.bash compiler"
  exit 0;
fi

CC=$1

cat > conftest.c << EOF
#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"
);
EOF

for define in "" "-DUSE_TEST"; do
 for static in "" "-static"; do
  for fpie in "" "-fPIE"; do
   for common in "-fcommon" "-fno-common"; do
    echo -n "define=${define} static=${static} common=${common} fpie=${fpie}: "
    $CC conftest.c -o a -O2 -nostdlib -nostartfiles -e asm_f_ref \
            ${static} ${define} ${fpie} ${common} 2>&1 >/dev/null
    if [ $? -eq 0 ]; then
      echo "OK"
    else
      echo "FAIL"
    fi
   done
  done
 done
done

rm conftest.c
---


[1] https://sourceware.org/pipermail/libc-alpha/2020-May/114493.html
Sam James July 30, 2023, 1:27 p.m. UTC | #5
Adhemerval Zanella Netto via Libc-alpha <libc-alpha@sourceware.org> writes:

> On 30/07/23 05:10, Florian Weimer wrote:
>> * Andreas K. Huettel via Libc-alpha:
>> 
>>> diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
>>> index 3e4d5da820..eb7681b704 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")));
>> 
>> More context:
>> 
>> | /* 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;
>> | # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
>> | # define DL_SYSINFO_IMPLEMENTATION              \
>> |   asm (".text\n\t"                              \
>> |        ".hidden _dl_sysinfo_break\n\t"          \
>> |        ".proc _dl_sysinfo_break\n\t"            \
>> |        "_dl_sysinfo_break:\n\t"                 \
>> |        ".prologue\n\t"                          \
>> |        ".altrp b6\n\t"                          \
>> |        ".body\n\t"                              \
>> |        "break 0x100000;\n\t"                    \
>> |        "br.ret.sptk.many b6;\n\t"               \
>> |        ".endp _dl_sysinfo_break\n\t"            \
>> |        ".previous");
>> | #endif
>> 
>> So this seems actually correct because the symbol is defined in .text.
>> (I was wondered why this would make .text writable.)
>
> That was my understanding back then as well, and I tested myself the testcase
> Sergei has created [1] and at least with gcc from 6 to 13 built with 
> build-many-glibcs.py I don't see any relocation failure.  But at same time
> I don't see any relocation failure with current code either, so I am not
> sure why this is happening with Gentoo toolchain (maybe a incomplete backport?).

I don't think we do much interesting there though. We had a user report
this again a few days ago with 13.

Our patchset at the moment is
https://gitweb.gentoo.org/proj/gcc-patches.git/tree/13.2.0/gentoo.

with
```
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/ia64-unknown-linux-gnu/13/lto-wrapper
Target: ia64-unknown-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-13.2.0/work/gcc-13.2.0/configure --host=ia64-unknown-linux-gnu --build=ia64-unknown-linux-gnu --prefix=/usr --bindir=/usr/ia64-unknown-linux-gnu/gcc-bin/13 --includedir=/usr/lib/gcc/ia64-unknown-linux-gnu/13/include --datadir=/usr/share/gcc-data/ia64-unknown-linux-gnu/13 --mandir=/usr/share/gcc-data/ia64-unknown-linux-gnu/13/man --infodir=/usr/share/gcc-data/ia64-unknown-linux-gnu/13/info --with-gxx-include-dir=/usr/lib/gcc/ia64-unknown-linux-gnu/13/include/g++-v13 --with-python-dir=/share/gcc-data/ia64-unknown-linux-gnu/13/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 13.2.0 p3' --with-gcc-major-version-only --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-fixed-point --enable-libgomp --disable-libssp --disable-libada --disable-cet --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --without-zstd --without-isl --disable-libsanitizer --enable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (Gentoo 13.2.0 p3)
```

>
> ---
> $ cat mk.bash
> #!/usr/bin/bash
>
> if [ $# -eq 0 ]; then
>   echo "usage: mk.bash compiler"
>   exit 0;
> fi
>
> CC=$1
>
> cat > conftest.c << EOF
> #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"
> );
> EOF
>
> for define in "" "-DUSE_TEST"; do
>  for static in "" "-static"; do
>   for fpie in "" "-fPIE"; do
>    for common in "-fcommon" "-fno-common"; do
>     echo -n "define=${define} static=${static} common=${common} fpie=${fpie}: "
>     $CC conftest.c -o a -O2 -nostdlib -nostartfiles -e asm_f_ref \
>             ${static} ${define} ${fpie} ${common} 2>&1 >/dev/null
>     if [ $? -eq 0 ]; then
>       echo "OK"
>     else
>       echo "FAIL"
>     fi
>    done
>   done
>  done
> done
>
> rm conftest.c
> ---
>
>
> [1] https://sourceware.org/pipermail/libc-alpha/2020-May/114493.html
Richard Henderson July 30, 2023, 2:03 p.m. UTC | #6
On 7/30/23 06:14, Adhemerval Zanella Netto via Libc-alpha wrote:
> 
> 
> On 30/07/23 05:10, Florian Weimer wrote:
>> * Andreas K. Huettel via Libc-alpha:
>>
>>> diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
>>> index 3e4d5da820..eb7681b704 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")));
>>
>> More context:
>>
>> | /* 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;
>> | # define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
>> | # define DL_SYSINFO_IMPLEMENTATION              \
>> |   asm (".text\n\t"                              \
>> |        ".hidden _dl_sysinfo_break\n\t"          \
>> |        ".proc _dl_sysinfo_break\n\t"            \
>> |        "_dl_sysinfo_break:\n\t"                 \
>> |        ".prologue\n\t"                          \
>> |        ".altrp b6\n\t"                          \
>> |        ".body\n\t"                              \
>> |        "break 0x100000;\n\t"                    \
>> |        "br.ret.sptk.many b6;\n\t"               \
>> |        ".endp _dl_sysinfo_break\n\t"            \
>> |        ".previous");
>> | #endif
>>
>> So this seems actually correct because the symbol is defined in .text.
>> (I was wondered why this would make .text writable.)
> 
> That was my understanding back then as well, and I tested myself the testcase
> Sergei has created [1] and at least with gcc from 6 to 13 built with
> build-many-glibcs.py I don't see any relocation failure.  But at same time
> I don't see any relocation failure with current code either, so I am not
> sure why this is happening with Gentoo toolchain (maybe a incomplete backport?).
> 
> ---
> $ cat mk.bash
> #!/usr/bin/bash
> 
> if [ $# -eq 0 ]; then
>    echo "usage: mk.bash compiler"
>    exit 0;
> fi
> 
> CC=$1
> 
> cat > conftest.c << EOF
> #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"
> );
> EOF

Certainly this won't fail, because it doesn't have the actual use.
You needed

int main() { asm_f_ref = (long)asm_f; return 0; }

to complete the test.

Even then I might expect that the test is too small, and a 22-bit gprel relocation may 
well succeed here.  Perhaps '.space 1 << 22' after '.endp asm_f'


r~

> 
> for define in "" "-DUSE_TEST"; do
>   for static in "" "-static"; do
>    for fpie in "" "-fPIE"; do
>     for common in "-fcommon" "-fno-common"; do
>      echo -n "define=${define} static=${static} common=${common} fpie=${fpie}: "
>      $CC conftest.c -o a -O2 -nostdlib -nostartfiles -e asm_f_ref \
>              ${static} ${define} ${fpie} ${common} 2>&1 >/dev/null
>      if [ $? -eq 0 ]; then
>        echo "OK"
>      else
>        echo "FAIL"
>      fi
>     done
>    done
>   done
> done
> 
> rm conftest.c
> ---
> 
> 
> [1] https://sourceware.org/pipermail/libc-alpha/2020-May/114493.html
Alexander Monakov July 30, 2023, 4:41 p.m. UTC | #7
On Sun, 30 Jul 2023, Richard Henderson via Libc-alpha wrote:

> Certainly this won't fail, because it doesn't have the actual use.
> You needed
> 
> int main() { asm_f_ref = (long)asm_f; return 0; }
> 
> to complete the test.
> 
> Even then I might expect that the test is too small, and a 22-bit gprel
> relocation may well succeed here.  Perhaps '.space 1 << 22' after '.endp
> asm_f'

Note that Gentoo builds with --enable-default-pie, which may be important
here (the testing script quoted below forgot to pass -pie alongside -fpie).

Alexander

> > for define in "" "-DUSE_TEST"; do
> >   for static in "" "-static"; do
> >    for fpie in "" "-fPIE"; do
> >     for common in "-fcommon" "-fno-common"; do
> >      echo -n "define=${define} static=${static} common=${common}
> >      fpie=${fpie}: "
> >      $CC conftest.c -o a -O2 -nostdlib -nostartfiles -e asm_f_ref \
> >              ${static} ${define} ${fpie} ${common} 2>&1 >/dev/null
> >      if [ $? -eq 0 ]; then
> >        echo "OK"
> >      else
> >        echo "FAIL"
> >     fi
> >    done
> >   done
> >   done
> > done
Adhemerval Zanella Netto July 30, 2023, 7:06 p.m. UTC | #8
On 30/07/23 13:41, Alexander Monakov wrote:
> 
> On Sun, 30 Jul 2023, Richard Henderson via Libc-alpha wrote:
> 
>> Certainly this won't fail, because it doesn't have the actual use.
>> You needed
>>
>> int main() { asm_f_ref = (long)asm_f; return 0; }
>>
>> to complete the test.
>>
>> Even then I might expect that the test is too small, and a 22-bit gprel
>> relocation may well succeed here.  Perhaps '.space 1 << 22' after '.endp
>> asm_f'
> 
> Note that Gentoo builds with --enable-default-pie, which may be important
> here (the testing script quoted below forgot to pass -pie alongside -fpie).

With Richard suggestion to actually reference the symbol the issues seems to
be the -fno-common (which GCC 10 defaults to all architecture and glibc 
enforces since 7c241325d67af9e24ff03d4c6f6280c17ea181f8). Even with the
text segment hack it fails with relocation overflow.
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 3e4d5da820..eb7681b704 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"				\