Fix kldxref on PowerPC64

When using kldxref on kernel modules built with clang8 + lld8,
kldxref would be unable to find the modules metadata information,
because PowerPC64 was using the ef_nop.c implementation of
ef_reloc().

When GNU LD was used, it was also relocating the metadata section of
the .ko file. LLD does not do this, but only generate dynamic
relocations for it. With minor changes, ef_powerpc.c can now work
for PowerPC64 too.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D19370
This commit is contained in:
Leandro Lupori 2019-02-27 13:24:42 +00:00
parent c7851c5b7c
commit 7e4520854c
2 changed files with 10 additions and 3 deletions

View File

@ -6,7 +6,7 @@ SRCS= kldxref.c ef.c ef_obj.c
WARNS?= 2
.if exists(ef_${MACHINE_CPUARCH}.c) && ${MACHINE_ARCH} != "powerpc64"
.if exists(ef_${MACHINE_CPUARCH}.c)
SRCS+= ef_${MACHINE_CPUARCH}.c
.else
SRCS+= ef_nop.c

View File

@ -34,10 +34,17 @@
#include <err.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include "ef.h"
#ifdef __powerpc64__
#define PRI_ELF_SIZE PRIu64
#else
#define PRI_ELF_SIZE PRIu32
#endif
/*
* Apply relocations to the values obtained from the file. `relbase' is the
* target relocation address of the section, and `dataoff/len' is the region
@ -63,11 +70,11 @@ ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
return (0);
switch (rtype) {
case R_PPC_RELATIVE: /* word32 B + A */
case R_PPC_RELATIVE: /* word32|doubleword64 B + A */
*where = relbase + addend;
break;
default:
warnx("unhandled relocation type %u", rtype);
warnx("unhandled relocation type %" PRI_ELF_SIZE, rtype);
}
return (0);
}