Allow building a cross libkvm by setting TARGET_ARCH. The library so

produced will be called libkvm-${ARCH} instead of libkvm. This allows
installing it alongside the native version.
For symbol lookups, use ps_pglobal_lookup() instead of __fdnlist()
when building a cross libkvm. It is assumed that the cross tool that
uses the cross libkvm also provides an implementation for this
proc_services function.

Note that this commit does not change any of the architecture-specific
code for cross-compilation.
This commit is contained in:
Marcel Moolenaar 2013-12-28 23:01:57 +00:00
parent e153be43ae
commit 3f6558c489
2 changed files with 54 additions and 7 deletions

View File

@ -1,23 +1,35 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
.if defined(TARGET_ARCH)
TARGET_CPUARCH=${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
.else
TARGET_ARCH=${MACHINE_ARCH}
TARGET_CPUARCH=${MACHINE_CPUARCH}
.endif
.if ${TARGET_ARCH} != ${MACHINE_ARCH}
LIB= kvm-${TARGET_ARCH}
CFLAGS+=-DCROSS_LIBKVM
.else
LIB= kvm
.endif
SHLIBDIR?= /lib
SHLIB_MAJOR= 6
CFLAGS+=-DLIBC_SCCS -I${.CURDIR}
.if exists(${.CURDIR}/kvm_${MACHINE_ARCH}.c)
KVM_ARCH=${MACHINE_ARCH}
.if exists(${.CURDIR}/kvm_${TARGET_ARCH}.c)
KVM_ARCH=${TARGET_ARCH}
.else
KVM_ARCH=${MACHINE_CPUARCH}
KVM_ARCH=${TARGET_CPUARCH}
.endif
WARNS?= 3
SRCS= kvm.c kvm_${KVM_ARCH}.c kvm_cptime.c kvm_file.c kvm_getloadavg.c \
kvm_getswapinfo.c kvm_pcpu.c kvm_proc.c kvm_vnet.c
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" || \
${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
.if exists(${.CURDIR}/kvm_minidump_${KVM_ARCH}.c)
SRCS+= kvm_minidump_${KVM_ARCH}.c
.endif
INCS= kvm.h

View File

@ -73,9 +73,44 @@ static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
#include "kvm_private.h"
#ifndef CROSS_LIBKVM
/* from src/lib/libc/gen/nlist.c */
int __fdnlist(int, struct nlist *);
#define kvm_fdnlist __fdnlist
#else
#include <proc_service.h>
static int
kvm_fdnlist(int fd, struct nlist *list)
{
psaddr_t addr;
ps_err_e pserr;
int nfail;
nfail = 0;
while (list->n_name != NULL && list->n_name[0] != '\0') {
list->n_other = 0;
list->n_desc = 0;
pserr = ps_pglobal_lookup(NULL, NULL, list->n_name, &addr);
if (pserr != PS_OK) {
nfail++;
list->n_value = 0;
list->n_type = 0;
} else {
list->n_value = addr;
list->n_type = N_DATA | N_EXT;
}
list++;
}
return (nfail);
}
#endif /* CROSS_LIBKVM */
char *
kvm_geterr(kvm_t *kd)
{
@ -341,7 +376,7 @@ kvm_fdnlist_prefix(kvm_t *kd, struct nlist *nl, int missing, const char *prefix,
/* Do lookup on the reduced list. */
np = n;
unresolved = __fdnlist(kd->nlfd, np);
unresolved = kvm_fdnlist(kd->nlfd, np);
/* Check if we could resolve further symbols and update the list. */
if (unresolved >= 0 && unresolved < missing) {
@ -398,7 +433,7 @@ _kvm_nlist(kvm_t *kd, struct nlist *nl, int initialize)
* slow library call.
*/
if (!ISALIVE(kd)) {
error = __fdnlist(kd->nlfd, nl);
error = kvm_fdnlist(kd->nlfd, nl);
if (error <= 0) /* Hard error or success. */
return (error);