From owner-svn-src-all@FreeBSD.ORG Sat Dec 28 23:01:58 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B51FF797; Sat, 28 Dec 2013 23:01:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A156611F9; Sat, 28 Dec 2013 23:01:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBSN1wMC002328; Sat, 28 Dec 2013 23:01:58 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBSN1wWP002326; Sat, 28 Dec 2013 23:01:58 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201312282301.rBSN1wWP002326@svn.freebsd.org> From: Marcel Moolenaar Date: Sat, 28 Dec 2013 23:01:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260022 - head/lib/libkvm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Dec 2013 23:01:58 -0000 Author: marcel Date: Sat Dec 28 23:01:57 2013 New Revision: 260022 URL: http://svnweb.freebsd.org/changeset/base/260022 Log: 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. Modified: head/lib/libkvm/Makefile head/lib/libkvm/kvm.c Modified: head/lib/libkvm/Makefile ============================================================================== --- head/lib/libkvm/Makefile Sat Dec 28 22:52:46 2013 (r260021) +++ head/lib/libkvm/Makefile Sat Dec 28 23:01:57 2013 (r260022) @@ -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 Modified: head/lib/libkvm/kvm.c ============================================================================== --- head/lib/libkvm/kvm.c Sat Dec 28 22:52:46 2013 (r260021) +++ head/lib/libkvm/kvm.c Sat Dec 28 23:01:57 2013 (r260022) @@ -73,9 +73,44 @@ static char sccsid[] = "@(#)kvm.c 8.2 (B #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 + +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 nli /* 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, * 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);