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

Richard Henderson richard.henderson@linaro.org
Sun Jul 30 14:03:42 GMT 2023


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



More information about the Libc-alpha mailing list