freebsd-dev/sys
John Baldwin eb81f38a62 Fix objcopy for little-endian MIPS64 objects.
MIPS64 does not store the 'r_info' field of a relocation table entry as
a 64-bit value consisting of a 32-bit symbol index in the high 32 bits
and a 32-bit type in the low 32 bits as on other architectures.  Instead,
the 64-bit 'r_info' field is really a 32-bit symbol index followed by four
individual byte type fields.  For big-endian MIPS64, treating this as a
64-bit integer happens to be compatible with the layout expected by other
architectures (symbol index in upper 32-bits of resulting "native" 64-bit
integer).  However, for little-endian MIPS64 the parsed 64-bit integer
contains the symbol index in the low 32 bits and the 4 individual byte
type fields in the upper 32-bits (but as if the upper 32-bits were
byte-swapped).

To cope, add two helper routines in gelf_getrel.c to translate between the
correct native 'r_info' value and the value obtained after the normal
byte-swap translation.  Use these routines in gelf_getrel(), gelf_getrela(),
gelf_update_rel(), and gelf_update_rela().  This fixes 'readelf -r' on
little-endian MIPS64 objects which was previously decoding incorrect
relocations as well as 'objcopy: invalid symbox index' warnings from
objcopy when extracting debug symbols from kernel modules.

Even with this fixed, objcopy was still crashing when trying to extract
debug symbols from little-endian MIPS64 modules.  The workaround in
gelf_*rel*() depends on the current ELF object having a valid ELF header
so that the 'e_machine' field can be compared against EM_MIPS.  objcopy
was parsing the relocation entries to possibly rewrite the 'r_info' fields
in the update_relocs() function before writing the initial ELF header to
the destination object file.  Move the initial write of the ELF header
earlier before copy_contents() so that update_relocs() uses the correct
symbol index values.

Note that this change should really go upstream.  The binutils readelf
source has a similar hack for MIPS64EL though I implemented this version
from scratch using the MIPS64 ABI PDF as a reference.

Discussed with:	jkoshy
Reviewed by:	emaste, imp
Approved by:	re (gjb, kib)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D15734
2018-09-05 20:51:53 +00:00
..
amd64 amd64: Properly re-merge r334537 into SMAP-ified copyin(9) and copyout(9). 2018-09-04 19:27:53 +00:00
arm omap4_prcm: Delay the frequencies read check 2018-08-30 14:32:47 +00:00
arm64 Catch exceptions during EFI RT calls on amd64. 2018-09-02 21:37:05 +00:00
bsm
cam Try harder in cfiscsi_offline(). This is believed to be the workaround 2018-09-01 16:16:40 +00:00
cddl Add support for 'C'-compressed ISA extension to DTrace FBT provider. 2018-09-03 14:34:09 +00:00
compat Regen after r338357. 2018-08-28 18:50:34 +00:00
conf Enable 'C'-compressed ISA extension. 2018-09-03 14:43:16 +00:00
contrib Revert drm2 removal. 2018-08-24 00:02:00 +00:00
crypto Don't load ccp automatically with devmatch 2018-08-31 01:01:16 +00:00
ddb add an option for ddb ps command to print process arguments 2018-08-09 11:21:31 +00:00
dev Assign to correct structure members. 2018-09-04 19:28:46 +00:00
dts arm64: Add DTS overlays for A64 2018-08-24 15:00:36 +00:00
fs Remove the Yarrow PRNG algorithm option in accordance with due notice 2018-08-26 12:51:46 +00:00
gdb
geom OpenCrypto: Convert sessions to opaque handles instead of integers 2018-07-18 00:56:25 +00:00
gnu dts: Import DTS for arm64 2018-08-23 13:21:01 +00:00
i386 Remove {max/min}_offset() macros, use vm_map_{max/min}() inlines. 2018-08-29 12:24:19 +00:00
isa Back out r338035 until Warner is finished churning GSoC PNP patches 2018-08-19 00:46:22 +00:00
kern Correct the condition under which we allocate a terminator node. 2018-09-05 19:05:30 +00:00
kgssapi OpenCrypto: Convert sessions to opaque handles instead of integers 2018-07-18 00:56:25 +00:00
libkern Sync strlcpy with userland version, again 2018-06-21 17:35:13 +00:00
mips Remove {max/min}_offset() macros, use vm_map_{max/min}() inlines. 2018-08-29 12:24:19 +00:00
modules Catch exceptions during EFI RT calls on amd64. 2018-09-02 21:37:05 +00:00
net Rather than duplicating the functionality of a macro after r322866 2018-09-03 22:10:49 +00:00
net80211 Fix misspellings of transmitter/transmitted 2018-08-10 20:37:32 +00:00
netgraph Remove the Yarrow PRNG algorithm option in accordance with due notice 2018-08-26 12:51:46 +00:00
netinet Fix style bugs in in_pcblookup_lbgroup(). 2018-09-05 15:04:11 +00:00
netinet6 Replicate r328271 from legacy IP to IPv6 using a single macro 2018-09-03 22:27:27 +00:00
netipsec Use the new VNET_DEFINE_STATIC macro when we are defining static VNET 2018-07-24 16:35:52 +00:00
netpfil Extended pf(4) ioctl interface and pfctl(8) to allow bandwidths of 2018-08-22 19:38:48 +00:00
netsmb Make timespecadd(3) and friends public 2018-07-30 15:46:40 +00:00
nfs Switch RIB and RADIX_NODE_HEAD lock from rwlock(9) to rmlock(9). 2018-06-16 08:26:23 +00:00
nfsclient
nfsserver
nlm
ofed Only NULL check the VNET pointer when VIMAGE is enabled in ibcore. 2018-07-31 11:23:44 +00:00
opencrypto cryptosoft: Reduce generality of supported algorithm composition 2018-08-17 04:40:01 +00:00
powerpc Eliminate the arena parameter to kmem_free(). Implicitly this corrects an 2018-08-25 19:38:08 +00:00
riscv Permit supervisor to access user VA space for certain functions only. 2018-09-05 11:34:58 +00:00
rpc Set SO_SNDTIMEO in the client side krpc when CLSET_TIMEOUT is done. 2018-07-20 12:03:16 +00:00
security The kernel DTrace audit provider (dtaudit) relies on auditd(8) to load 2018-09-03 14:26:43 +00:00
sparc64 Prepare the kernel linker to handle PC-relative ifunc relocations. 2018-08-22 20:44:30 +00:00
sys Fix objcopy for little-endian MIPS64 objects. 2018-09-05 20:51:53 +00:00
teken teken: Fix sequences header which was crossing the 80-col boundary 2018-05-29 08:41:44 +00:00
tests epoch_test: fix compile 2018-07-15 00:31:17 +00:00
tools make_dtb: Always add root directory in the include path 2018-08-23 13:23:21 +00:00
ufs Remove the Yarrow PRNG algorithm option in accordance with due notice 2018-08-26 12:51:46 +00:00
vm Recent changes have created, for the first time, physical memory segments 2018-09-02 18:29:38 +00:00
x86 Fix build of x86 UP kernels after dynamic IRQ changes in r338360. 2018-08-31 18:26:37 +00:00
xdr
xen xen: add missing file from r336474 2018-07-19 10:14:52 +00:00
Makefile