Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking any program with mold-1.10.1 on ppc64 BE fails with: cannot find a symbol in .opd for R_PPC64_REL24 at offset 0x0 #987

Open
ernsteiswuerfel opened this issue Feb 11, 2023 · 8 comments

Comments

@ernsteiswuerfel
Copy link

Building mold-1.10.1 works fine on Gentoo ppc64 Big Endian but using it as system-wide-linker via LDFLAGS="-fuse-ld=mold -Wl,-O1 -Wl,--as-needed" won't work.

E.g. emerge less fails at config stage:

>>> Emerging (1 of 1) sys-apps/less-608-r1::gentoo
 * less-608.tar.gz BLAKE2B SHA512 size ;-) ...                                                          [ ok ]
>>> Unpacking source...
>>> Unpacking less-608.tar.gz to /var/tmp/portage/sys-apps/less-608-r1/work
>>> Source unpacked in /var/tmp/portage/sys-apps/less-608-r1/work
>>> Preparing source in /var/tmp/portage/sys-apps/less-608-r1/work/less-608 ...
 * Applying less-608-procfs.patch ...                                                                   [ ok ]
 * Running eautoreconf in '/var/tmp/portage/sys-apps/less-608-r1/work/less-608' ...
 * Running 'aclocal --system-acdir=/var/tmp/portage/sys-apps/less-608-r1/temp/aclocal' ...              [ ok ]
 * Running 'autoconf --force' ...                                                                       [ ok ]
 * Running 'autoheader' ...                                                                             [ ok ]
 * Running elibtoolize in: less-608/
>>> Source prepared.
>>> Configuring source in /var/tmp/portage/sys-apps/less-608-r1/work/less-608 ...
 * econf: updating less-608/config.guess with /usr/share/gnuconfig/config.guess
 * econf: updating less-608/config.sub with /usr/share/gnuconfig/config.sub
./configure --prefix=/usr --build=powerpc64-unknown-linux-gnu --host=powerpc64-unknown-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --docdir=/usr/share/doc/less-608-r1 --htmldir=/usr/share/doc/less-608-r1/html --libdir=/usr/lib64 --with-regex=pcre2 --with-editor=/usr/libexec/editor
checking for powerpc64-unknown-linux-gnu-gcc... powerpc64-unknown-linux-gnu-gcc
checking whether the C compiler works... no
configure: error: in `/var/tmp/portage/sys-apps/less-608-r1/work/less-608':
configure: error: C compiler cannot create executables
See `config.log' for more details

!!! Please attach the following file when seeking support:
!!! /var/tmp/portage/sys-apps/less-608-r1/work/less-608/config.log
 * ERROR: sys-apps/less-608-r1::gentoo failed (configure phase):

config errors out with mold: fatal: /usr/lib/gcc/powerpc64-unknown-linux-gnu/12/crtbeginS.o:(.text): cannot find a symbol in .opd for R_PPC64_REL24 at offset 0x0.
config.log

@rui314
Copy link
Owner

rui314 commented Feb 11, 2023

Can you upload /usr/lib/gcc/powerpc64-unknown-linux-gnu/12/crtbeginS.o so that I can peek inside of that file?

@ernsteiswuerfel
Copy link
Author

Sure!
crtbeginS.o.gz

@rui314
Copy link
Owner

rui314 commented Feb 12, 2023

Your crtbeginS.o looks weird as most symbols have been stripped. Compare the following two crt files. The first one is mine and the second is yours. As you can see, your crt file's text segment doesn't have symbols. You may want to rebuild your crt file.

/usr/lib/gcc-cross/powerpc64-linux-gnu/10/crtbeginS.o:     file format elf64-powerpc


Disassembly of section .text:

0000000000000000 <.deregister_tm_clones>:
   0:   3c 62 00 00     addis   r3,r2,0
   4:   3d 22 00 00     addis   r9,r2,0
   8:   38 63 00 00     addi    r3,r3,0
   c:   39 29 00 00     addi    r9,r9,0
  10:   7c 29 18 00     cmpd    r9,r3
  14:   4d 82 00 20     beqlr
  18:   3d 22 00 00     addis   r9,r2,0
  1c:   e9 29 00 00     ld      r9,0(r9)
  20:   2c 29 00 00     cmpdi   r9,0
  24:   4d 82 00 20     beqlr
  28:   7c 08 02 a6     mflr    r0
  2c:   f8 01 00 10     std     r0,16(r1)
  30:   f8 21 ff 91     stdu    r1,-112(r1)
  34:   f8 41 00 28     std     r2,40(r1)
  38:   e9 49 00 00     ld      r10,0(r9)
  3c:   e9 69 00 10     ld      r11,16(r9)
  40:   7d 49 03 a6     mtctr   r10
  44:   e8 49 00 08     ld      r2,8(r9)
  48:   4e 80 04 21     bctrl
  4c:   e8 41 00 28     ld      r2,40(r1)
  50:   38 21 00 70     addi    r1,r1,112
  54:   e8 01 00 10     ld      r0,16(r1)
  58:   7c 08 03 a6     mtlr    r0
  5c:   4e 80 00 20     blr

0000000000000060 <.register_tm_clones>:
  60:   3c 62 00 00     addis   r3,r2,0
  64:   3c 82 00 00     addis   r4,r2,0
  68:   38 63 00 00     addi    r3,r3,0
  6c:   38 84 00 00     addi    r4,r4,0
  70:   7c 83 20 50     subf    r4,r3,r4
  74:   7c 84 1e 74     sradi   r4,r4,3
  78:   7c 84 0e 74     sradi   r4,r4,1
  7c:   7c 84 01 95     addze.  r4,r4
  80:   4d 82 00 20     beqlr
  84:   3d 22 00 00     addis   r9,r2,0
  88:   e9 29 00 00     ld      r9,0(r9)
  8c:   2c 29 00 00     cmpdi   r9,0
  90:   4d 82 00 20     beqlr
  94:   7c 08 02 a6     mflr    r0
  98:   f8 01 00 10     std     r0,16(r1)
  9c:   f8 21 ff 91     stdu    r1,-112(r1)
  a0:   f8 41 00 28     std     r2,40(r1)
  a4:   e9 49 00 00     ld      r10,0(r9)
  a8:   e9 69 00 10     ld      r11,16(r9)
  ac:   7d 49 03 a6     mtctr   r10
  b0:   e8 49 00 08     ld      r2,8(r9)
  b4:   4e 80 04 21     bctrl
  b8:   e8 41 00 28     ld      r2,40(r1)
  bc:   38 21 00 70     addi    r1,r1,112
  c0:   e8 01 00 10     ld      r0,16(r1)
  c4:   7c 08 03 a6     mtlr    r0
  c8:   4e 80 00 20     blr
  cc:   60 42 00 00     ori     r2,r2,0

00000000000000d0 <.__do_global_dtors_aux>:
  d0:   3d 22 00 00     addis   r9,r2,0
  d4:   89 29 00 00     lbz     r9,0(r9)
  d8:   2c 09 00 00     cmpwi   r9,0
  dc:   4c 82 00 20     bnelr
  e0:   7c 08 02 a6     mflr    r0
  e4:   fb a1 ff e8     std     r29,-24(r1)
  e8:   fb c1 ff f0     std     r30,-16(r1)
  ec:   f8 01 00 10     std     r0,16(r1)
  f0:   f8 21 ff 71     stdu    r1,-144(r1)
  f4:   3d 22 00 00     addis   r9,r2,0
  f8:   f8 41 00 28     std     r2,40(r1)
  fc:   e9 29 00 00     ld      r9,0(r9)
 100:   2c 29 00 00     cmpdi   r9,0
 104:   41 82 00 14     beq     118 <.__do_global_dtors_aux+0x48>
 108:   3d 22 00 00     addis   r9,r2,0
 10c:   e8 69 00 00     ld      r3,0(r9)
 110:   48 00 00 01     bl      110 <.__do_global_dtors_aux+0x40>
 114:   60 00 00 00     nop
 118:   3d 42 00 00     addis   r10,r2,0
 11c:   3f c2 00 00     addis   r30,r2,0
 120:   39 4a 00 00     addi    r10,r10,0
 124:   3b de 00 00     addi    r30,r30,0
 128:   3d 22 00 00     addis   r9,r2,0
 12c:   7f de 50 50     subf    r30,r30,r10
 130:   e9 29 00 00     ld      r9,0(r9)
 134:   7f de 1e 74     sradi   r30,r30,3
 138:   3f a2 00 00     addis   r29,r2,0
 13c:   3b de ff ff     addi    r30,r30,-1
 140:   3b bd 00 00     addi    r29,r29,0
 144:   7c 29 f0 40     cmpld   r9,r30
 148:   40 80 00 50     bge     198 <.__do_global_dtors_aux+0xc8>
 14c:   fb e1 00 88     std     r31,136(r1)
 150:   3f e2 00 00     addis   r31,r2,0
 154:   3b ff 00 00     addi    r31,r31,0
 158:   60 00 00 00     nop
 15c:   60 42 00 00     ori     r2,r2,0
 160:   39 29 00 01     addi    r9,r9,1
 164:   f9 3f 00 00     std     r9,0(r31)
 168:   79 29 1f 24     rldicr  r9,r9,3,60
 16c:   7d 3d 48 2a     ldx     r9,r29,r9
 170:   e9 49 00 00     ld      r10,0(r9)
 174:   e9 69 00 10     ld      r11,16(r9)
 178:   7d 49 03 a6     mtctr   r10
 17c:   e8 49 00 08     ld      r2,8(r9)
 180:   4e 80 04 21     bctrl
 184:   e8 41 00 28     ld      r2,40(r1)
 188:   e9 3f 00 00     ld      r9,0(r31)
 18c:   7c 29 f0 40     cmpld   r9,r30
 190:   41 80 ff d0     blt     160 <.__do_global_dtors_aux+0x90>
 194:   eb e1 00 88     ld      r31,136(r1)
 198:   48 00 00 01     bl      198 <.__do_global_dtors_aux+0xc8>
 19c:   38 21 00 90     addi    r1,r1,144
 1a0:   39 20 00 01     li      r9,1
 1a4:   e8 01 00 10     ld      r0,16(r1)
 1a8:   eb a1 ff e8     ld      r29,-24(r1)
 1ac:   3d 42 00 00     addis   r10,r2,0
 1b0:   eb c1 ff f0     ld      r30,-16(r1)
 1b4:   99 2a 00 00     stb     r9,0(r10)
 1b8:   7c 08 03 a6     mtlr    r0
 1bc:   4e 80 00 20     blr

00000000000001c0 <.frame_dummy>:
 1c0:   48 00 00 00     b       1c0 <.frame_dummy>

Disassembly of section .fini:

0000000000000000 <.fini>:
   0:   48 00 00 01     bl      0 <.fini>
   4:   60 00 00 00     nop

Disassembly of section .init:

0000000000000000 <.init>:
   0:   48 00 00 01     bl      0 <.init>
   4:   60 00 00 00     nop
crtbeginS.o:     file format elf64-powerpc


Disassembly of section .text:

0000000000000000 <.text>:
   0:   3c 62 00 00     addis   r3,r2,0
   4:   3d 22 00 00     addis   r9,r2,0
   8:   38 63 00 00     addi    r3,r3,0
   c:   39 29 00 00     addi    r9,r9,0
  10:   7c 29 18 00     cmpd    r9,r3
  14:   4d 82 00 20     beqlr
  18:   3d 22 00 00     addis   r9,r2,0
  1c:   e9 29 00 00     ld      r9,0(r9)
  20:   2c 29 00 00     cmpdi   r9,0
  24:   4d 82 00 20     beqlr
  28:   7c 08 02 a6     mflr    r0
  2c:   f8 01 00 10     std     r0,16(r1)
  30:   f8 21 ff 91     stdu    r1,-112(r1)
  34:   f8 41 00 28     std     r2,40(r1)
  38:   e9 49 00 00     ld      r10,0(r9)
  3c:   e9 69 00 10     ld      r11,16(r9)
  40:   7d 49 03 a6     mtctr   r10
  44:   e8 49 00 08     ld      r2,8(r9)
  48:   4e 80 04 21     bctrl
  4c:   e8 41 00 28     ld      r2,40(r1)
  50:   38 21 00 70     addi    r1,r1,112
  54:   e8 01 00 10     ld      r0,16(r1)
  58:   7c 08 03 a6     mtlr    r0
  5c:   4e 80 00 20     blr
  60:   3c 62 00 00     addis   r3,r2,0
  64:   3c 82 00 00     addis   r4,r2,0
  68:   38 63 00 00     addi    r3,r3,0
  6c:   38 84 00 00     addi    r4,r4,0
  70:   7c 83 20 50     subf    r4,r3,r4
  74:   7c 84 1e 74     sradi   r4,r4,3
  78:   7c 84 0e 74     sradi   r4,r4,1
  7c:   7c 84 01 95     addze.  r4,r4
  80:   4d 82 00 20     beqlr
  84:   3d 22 00 00     addis   r9,r2,0
  88:   e9 29 00 00     ld      r9,0(r9)
  8c:   2c 29 00 00     cmpdi   r9,0
  90:   4d 82 00 20     beqlr
  94:   7c 08 02 a6     mflr    r0
  98:   f8 01 00 10     std     r0,16(r1)
  9c:   f8 21 ff 91     stdu    r1,-112(r1)
  a0:   f8 41 00 28     std     r2,40(r1)
  a4:   e9 49 00 00     ld      r10,0(r9)
  a8:   e9 69 00 10     ld      r11,16(r9)
  ac:   7d 49 03 a6     mtctr   r10
  b0:   e8 49 00 08     ld      r2,8(r9)
  b4:   4e 80 04 21     bctrl
  b8:   e8 41 00 28     ld      r2,40(r1)
  bc:   38 21 00 70     addi    r1,r1,112
  c0:   e8 01 00 10     ld      r0,16(r1)
  c4:   7c 08 03 a6     mtlr    r0
  c8:   4e 80 00 20     blr
  cc:   60 00 00 00     nop
  d0:   3d 22 00 00     addis   r9,r2,0
  d4:   89 29 00 00     lbz     r9,0(r9)
  d8:   2c 09 00 00     cmpwi   r9,0
  dc:   4c 82 00 20     bnelr
  e0:   3d 22 00 00     addis   r9,r2,0
  e4:   7c 08 02 a6     mflr    r0
  e8:   e9 29 00 00     ld      r9,0(r9)
  ec:   2c 29 00 00     cmpdi   r9,0
  f0:   f8 01 00 10     std     r0,16(r1)
  f4:   f8 21 ff 91     stdu    r1,-112(r1)
  f8:   41 82 00 14     beq     10c <.text+0x10c>
  fc:   3d 22 00 00     addis   r9,r2,0
 100:   e8 69 00 00     ld      r3,0(r9)
 104:   48 00 00 01     bl      104 <.text+0x104>
 108:   60 00 00 00     nop
 10c:   48 00 00 01     bl      10c <.text+0x10c>
 110:   38 21 00 70     addi    r1,r1,112
 114:   39 20 00 01     li      r9,1
 118:   3d 42 00 00     addis   r10,r2,0
 11c:   e8 01 00 10     ld      r0,16(r1)
 120:   99 2a 00 00     stb     r9,0(r10)
 124:   7c 08 03 a6     mtlr    r0
 128:   4e 80 00 20     blr
 12c:   60 00 00 00     nop
 130:   48 00 00 00     b       130 <.text+0x130>

@Arfrever
Copy link

Portage (default package manager in Gentoo) strips files by default.
For relocatables (including *.o files), it uses strip --strip-unneeded -N __gentoo_check_ldflags__.
For libraries and executables, it uses strip --strip-unneeded -N __gentoo_check_ldflags__ -R .comment -R .GCC.command.line -R .note.gnu.gold-version.
However it is not a problem for other linkers...

@ernsteiswuerfel
Copy link
Author

After a hint from Arfrever on IRC (#gentoo-powerpc) I rebuilt gcc-12 with FEATURES="nostrip" and the resulting crtbeginS.o indeed got more info. At emerge -1 less configuration continues but errors out some time later with

[...]
configure:3125: powerpc64-unknown-linux-gnu-gcc -o conftest -Os -mcpu=power9 -mtune=power9 -pipe  -fuse-ld=mold -Wl,-O1 -Wl,--as-needed conftest.c  >&5
configure:3129: $? = 0
configure:3152: result: 
configure:3174: checking whether we are cross compiling
configure:3182: powerpc64-unknown-linux-gnu-gcc -o conftest -Os -mcpu=power9 -mtune=power9 -pipe  -fuse-ld=mold -Wl,-O1 -Wl,--as-needed conftest.c  >&5
mold: error: undefined symbol: _restgpr0_31
>>> referenced by conftest.c
>>>               /var/tmp/portage/sys-apps/less-608-r1/temp/ccUDhJlC.o
collect2: error: ld returned 1 exit status
configure:3186: $? = 1
configure:3193: ./conftest
./configure: 1: eval: ./conftest: not found
configure:3197: $? = 127
configure:3204: error: in `/var/tmp/portage/sys-apps/less-608-r1/work/less-608':
configure:3206: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

crtbeginS.o.gz
config.log

@rui314
Copy link
Owner

rui314 commented Feb 12, 2023

As to stripping the object files, your object files' .opd sections (the Official Procedure Description sections) don't contain symbols. That's very odd and arguably a violation of the PPC64 psABI even if other linkers don't care about it. At least it's unnecessary churn.

Let me take a look at the _restgpr0_31 issue.

@Arfrever
Copy link

crtbeginS.o.gz

It seems that relevant part of behavior of llvm-strip is the same as GNU strip.

strip --strip-unneeded crtbeginS.o -o crtbeginS_stripped_gnu.o
llvm-strip --strip-unneeded crtbeginS.o -o crtbeginS_stripped_llvm.o

(And then you can compare crtbeginS.o, crtbeginS_stripped_gnu.o, crtbeginS_stripped_llvm.o...)

@rui314
Copy link
Owner

rui314 commented Feb 13, 2023

Stripping final executable files is fine, but stripping intermediate object files doesn't make much sense. If a compiler emits a symbol, it's there for a reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants