tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: unresolvable R_X86_64_NONE relocation against symbol `__sF'



On Thu, 18 May 2023, Edgar Fuß wrote:

attached (gzip-ed and .work.log renamed).


There are multiple invalid relocations types in those object files. For
instance:

```
$ readelf -r common.o.bad | head

Relocation section '.rela.text' at offset 0x3c20 contains 261 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
00000000001e  002f00000000 R_X86_64_NONE     0000000000000000 fetchLastErrCode - 4
00000000002b  000a00000002 R_X86_64_PC32     0000000000000000 .LC0 - 4
000000000037  003000000000 R_X86_64_NONE     0000000000000000 fetchLastErrString - 4
000000000047  003300000004 R_X86_64_PLT32    0000000000000000 __errno - 4
000000000059  000600000002 R_X86_64_PC32     0000000000000000 .rodata - 4
000000000069  002f00000000 R_X86_64_NONE     0000000000000000 fetchLastErrCode - 4
000000000074  003300000004 R_X86_64_PLT32    0000000000000000 __errno - 4
$
```

compared to one produced using gcc-10.4.0 + binutils-2.26.1 (in the /tmp/B/bin
dir.  which I got from here:
http://archive.netbsd.org/pub/pkgsrc-archive/packages/NetBSD/amd64/8.0_2019Q3/All):

```
$ PATH=/tmp/B/bin:$PATH gcc -fcommon -Wl,-zrelro -O2 -fPIC -std=gnu99 \
  -fstack-protector -Wall -DDEF_UMASK=0022 -D_LARGEFILE_SOURCE -D_LARGE_FILES \
  -D_FILE_OFFSET_BITS=64 -DINET6 -DWITH_SSL -DFTP_COMBINE_CWDS -DNETBSD \
  -c /usr/src/external/bsd/fetch/dist/libfetch/common.c -o common.o.good
$ readelf -r common.o.good | head

Relocation section '.rela.text' at offset 0x3600 contains 258 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000017  002b0000002a R_X86_64_REX_GOTP 0000000000000000 fetchLastErrCode - 4
000000000024  000f00000002 R_X86_64_PC32     0000000000000000 .LC0 - 4
000000000030  002c0000002a R_X86_64_REX_GOTP 0000000000000000 fetchLastErrString - 4
000000000040  002f00000004 R_X86_64_PLT32    0000000000000000 __errno - 4
00000000004e  000600000002 R_X86_64_PC32     0000000000000000 .rodata - 4
00000000005e  002b0000002a R_X86_64_REX_GOTP 0000000000000000 fetchLastErrCode - 4
000000000069  002f00000004 R_X86_64_PLT32    0000000000000000 __errno - 4
$
```

`R_X86_64_REX_GOTP' is the correct relocation type for `-fPIC' as can be seen
from the assembly:

```
$ PATH=/tmp/B/bin:$PATH gcc -fcommon -Wl,-zrelro -O2 -fPIC -std=gnu99 \
  -fstack-protector -Wall -DDEF_UMASK=0022 -D_LARGEFILE_SOURCE -D_LARGE_FILES \
  -D_FILE_OFFSET_BITS=64 -DINET6 -DWITH_SSL -DFTP_COMBINE_CWDS -DNETBSD \
  -S /usr/src/external/bsd/fetch/dist/libfetch/common.c -o common.S
$ sed -n '21,31p' common.S .L3:
        movl    4(%rdi), %edx
        movq    fetchLastErrCode@GOTPCREL(%rip), %rax
        movl    %edx, (%rax)
        movq    8(%rdi), %rcx
        leaq    .LC0(%rip), %rdx
        movl    $256, %esi
        movq    fetchLastErrString@GOTPCREL(%rip), %rdi
        xorl    %eax, %eax
        jmp     snprintf@PLT
        .cfi_endproc
$
```

The assembler will turn GOTPCREL output by the compiler into R_X86_64_REX_GOTP
(both for `-fPIC').

Can you post the assembly and object file produced by whatever compiler
this points to:

/var/work/pkgsrc/pkgtools/pkg_install/work/.gcc/bin/gcc

You can use the command-lines I've given above to produce them. They should
be functionally the same as the ones in your log file.

-RVP


Home | Main Index | Thread Index | Old Index