Subject: R_MIPS_64 broken in relocateable links

From: Ralf Baechle <[email-masked]>
Date: Wed, 13 Oct 1999 21:39:26 +0200

The shell archive below is a testcase demonstrating a bug in handling
R_MIPS_64 relocations in 32-bit ELF broken for relocateable links.
The output objectfile will contain bad relocations like:

0000000000000014 l       .text  0000000000000000 xxx

This seems to be caused by BFD temporarily adding 4 to the relocation's
address.  It seem the fix is to undo this when copying R_MIPS_64
relocations to the output file?

  Ralf

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-10-13 12:24 PDT by <ralf@cashcow>.
# Source directory was `/usr/people/ralf'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
# This format requires very little intelligence at unshar time.
# "if test", "echo", "mkdir", and "sed" may be needed.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#     14 -rw-r--r-- nuke-ld-23/s1.s
#     48 -rw-r--r-- nuke-ld-23/s2.s
#    328 -rw-r--r-- nuke-ld-23/Makefile
#
echo=echo
if mkdir _sh92525; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= nuke-ld-23/s1.s ==============
if test ! -d 'nuke-ld-23'; then
  $echo 'x -' 'creating directory' 'nuke-ld-23'
  mkdir 'nuke-ld-23'
fi
if test -f 'nuke-ld-23/s1.s' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'nuke-ld-23/s1.s' '(file already exists)'
else
  $echo 'x -' extracting 'nuke-ld-23/s1.s' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'nuke-ld-23/s1.s' &&
X	.word	0x1234
SHAR_EOF
  : || $echo 'restore of' 'nuke-ld-23/s1.s' 'failed'
fi
# ============= nuke-ld-23/s2.s ==============
if test -f 'nuke-ld-23/s2.s' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'nuke-ld-23/s2.s' '(file already exists)'
else
  $echo 'x -' extracting 'nuke-ld-23/s2.s' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'nuke-ld-23/s2.s' &&
Xxxx:	.dword	something
Xsomething:
X	.dword	0x789a
SHAR_EOF
  : || $echo 'restore of' 'nuke-ld-23/s2.s' 'failed'
fi
# ============= nuke-ld-23/Makefile ==============
if test -f 'nuke-ld-23/Makefile' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'nuke-ld-23/Makefile' '(file already exists)'
else
  $echo 'x -' extracting 'nuke-ld-23/Makefile' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'nuke-ld-23/Makefile' &&
Xtarget=mips-linux-
XAS = $(target)as
XLD = $(target)ld
XOBJDUMP = $(target)objdump
X
Xall: broken.o
X
X.PHONY: broken.o
Xbroken.o:	s1.o s2.o
X	$(LD) -r -o $@ $^
X	$(OBJDUMP) --full-content --section=.text $@
X	$(OBJDUMP) --syms $@ | grep xxx
X	$(OBJDUMP) --reloc $@
X
X.PHONY: clean distclean
Xclean distclean:
X	-rm -f s1.o s2.o broken.o core
SHAR_EOF
  : || $echo 'restore of' 'nuke-ld-23/Makefile' 'failed'
fi
rm -fr _sh92525
exit 0