From nobody Thu Jan 18 22:25:53 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TGHQ971Cxz578Sx; Thu, 18 Jan 2024 22:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TGHQ95b3Vz40xx; Thu, 18 Jan 2024 22:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705616753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nFgUIgaUsWYKea3bsL6oWdvOhO+CEzJ3CAFIwuDN8kU=; b=tRRDKkRQKAZ9EgXfg2cXZV7bX4WDyJBw1P05l24m2aqekt3GkTdTqqVc7ETxnFvglCXGYo NHRbITfS40u4Nge1sG0AQeSmAlQ7qDXEgH/YX7zO0VvcD71WUR+MuuB1+cJfmMwkVXErQj lFaQmH0RkV0IA0U7vCtTVcP4p7p1H65/P1e8O4lfvyD1+XotWfIABPg6DlS9BOKagTEqCM IMEcGRL70c2cAeCL2fUBY2mR87TTu3QYMZk6aVMX+mMCap1S3pPn0Jp7B9UDTTZX14cVcv 3yJg2KytJSmoRmz7mcvWjo/ht3YtuVUxQejr18+gy+QgI2Q3od5UWCsVwTL61A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705616753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nFgUIgaUsWYKea3bsL6oWdvOhO+CEzJ3CAFIwuDN8kU=; b=hMjDUq/C8t7LhD9BayuDN+W0no0hm/ZLmLHkvA76Z0wiht5QoglPEe4DjAOWDrwjPtG6hf jwa3XA+nNRR4VHfZsINoQc10pvt/lMgyYtvCidoAyx34+OqZ0tSQhPrq/f73xms8+9zpiG Z8mhiBBgD1VxSsoEt9bIrdq1cs2xzCa82zceFxr+s2H5uAAnMyWAmZ6WW55oB0f471njjO HzuRGVwYZ3YIqk08I0kcGZTBjnJ8Wgvm5f08loCfjtsiUVXkLv19dx5ZRvPEuQhxMBkA/i 4sGHtSeOV7WXALauckAexCxVHHQbqgt51vieMX6ErGUJyUsDhXWhUcxDtXnDrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705616753; a=rsa-sha256; cv=none; b=uYtOX8PGnvh/3ffrRsJLYuTZL9hrotgbbIr9DKibdP3mYfOrF8dIEJYfC3v4u8jycmyJFE uFmy21zVAMwjxcjRHSHvyWejeh+qnVraL3QtfSt7jKJWdKB/hutAqwmVSHViVKP95T5YgQ e33n+HL1GZdt2aBugb+WpkOsF72wpqSLbh1VlsHaU/n6IyfSKhYNSGeq7+tDO8DdeqshEV ix8nT/dLtz0yzjVB1Jnmgf2hPQ8uam+1FJ7pD6LMCcb0YkT9K4tRW2oCFGPTU3jgvzEStD TPwMqKL2a/2A1dPFSpKIwtZUxh/+QBvn6mjwSNWJidPEB5E/Qpm3zD7UkdUQ9A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TGHQ94hlvzQ4V; Thu, 18 Jan 2024 22:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40IMPrrZ089199; Thu, 18 Jan 2024 22:25:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40IMProo089196; Thu, 18 Jan 2024 22:25:53 GMT (envelope-from git) Date: Thu, 18 Jan 2024 22:25:53 GMT Message-Id: <202401182225.40IMProo089196@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 84410c7bb737 - stable/14 - kldxref: Add arm support List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 84410c7bb737d2d4b1ff22605f7bd24841f3b3f6 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=84410c7bb737d2d4b1ff22605f7bd24841f3b3f6 commit 84410c7bb737d2d4b1ff22605f7bd24841f3b3f6 Author: Jessica Clarke AuthorDate: 2023-12-14 18:27:09 +0000 Commit: John Baldwin CommitDate: 2024-01-18 21:30:29 +0000 kldxref: Add arm support (cherry picked from commit c88f7d8fb54051366d91acfc6c80aca6154da3b4) --- usr.sbin/kldxref/Makefile | 1 + usr.sbin/kldxref/ef_arm.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/usr.sbin/kldxref/Makefile b/usr.sbin/kldxref/Makefile index 07451ba8f42b..7b392e020939 100644 --- a/usr.sbin/kldxref/Makefile +++ b/usr.sbin/kldxref/Makefile @@ -4,6 +4,7 @@ PROG= kldxref MAN= kldxref.8 SRCS= kldxref.c ef.c ef_obj.c elf.c SRCS+= ef_aarch64.c \ + ef_arm.c \ ef_amd64.c \ ef_i386.c \ ef_mips.c \ diff --git a/usr.sbin/kldxref/ef_arm.c b/usr.sbin/kldxref/ef_arm.c new file mode 100644 index 000000000000..4b926839ee5d --- /dev/null +++ b/usr.sbin/kldxref/ef_arm.c @@ -0,0 +1,94 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2003 Jake Burkholder. + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * Copyright (c) 2023 Jessica Clarke + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include + +#include "ef.h" + +/* + * Apply relocations to the values we got from the file. `relbase' is the + * target relocation address of the section, and `dataoff' is the target + * relocation address of the data in `dest'. + */ +static int +ef_arm_reloc(struct elf_file *ef, const void *reldata, Elf_Type reltype, + GElf_Addr relbase, GElf_Addr dataoff, size_t len, void *dest) +{ + char *where; + GElf_Addr addr, addend; + GElf_Size rtype, symidx; + const GElf_Rel *rel; + const GElf_Rela *rela; + + switch (reltype) { + case ELF_T_REL: + rel = (const GElf_Rel *)reldata; + where = (char *)dest + relbase + rel->r_offset - dataoff; + addend = 0; + rtype = GELF_R_TYPE(rel->r_info); + symidx = GELF_R_SYM(rel->r_info); + break; + case ELF_T_RELA: + rela = (const GElf_Rela *)reldata; + where = (char *)dest + relbase + rela->r_offset - dataoff; + addend = rela->r_addend; + rtype = GELF_R_TYPE(rela->r_info); + symidx = GELF_R_SYM(rela->r_info); + break; + default: + return (EINVAL); + } + + if (where < (char *)dest || where >= (char *)dest + len) + return (0); + + if (reltype == ELF_T_REL) + addend = le32dec(where); + + switch (rtype) { + case R_ARM_ABS32: /* S + A */ + addr = EF_SYMADDR(ef, symidx) + addend; + le32enc(where, addr); + break; + case R_ARM_RELATIVE: /* B + A */ + addr = addend + relbase; + le32enc(where, addr); + break; + default: + warnx("unhandled relocation type %d", (int)rtype); + } + return (0); +} + +ELF_RELOC(ELFCLASS32, ELFDATA2LSB, EM_ARM, ef_arm_reloc);