From nobody Thu Jan 18 22:26:24 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 4TGHQn1XLlz578b1; Thu, 18 Jan 2024 22:26:25 +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 4TGHQm6cRTz421m; Thu, 18 Jan 2024 22:26:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705616784; 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=99rvO/j/oz0O16xCo7TSgHBxKfmJjwV2Go+5vOVAXuA=; b=IOOGnjViclWglguHMGFX0GOcXQ7D2GZvdR6FZMzBhdtF5dP7RVjD3TyQwUX6DHMcu/i1Y8 gec525twKYTwYSn35RjLAIjtUoLfwBMcDdMkri4m26HD+cWnqHvDk3k9HvJu2KxS9/4Hgc gSjZaDZog5tu0eLqw1+g02zGwtjLhkrul7VHw3rBfnohgRw/ZhCblhFg80PT3nMVXLuDnU gtF16ZMalSWl/SnEM2ReBdA0B3B8RHaHI4cTUOpM+tPXWcmVC/d0A/kEqxbGyThjypiQiN eS21Zx6G7BCtYgn7miqgnfEUfC9WLkxanZe3MOPwTvopJbbwom1rY0hMogGzJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705616784; 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=99rvO/j/oz0O16xCo7TSgHBxKfmJjwV2Go+5vOVAXuA=; b=W+Aivtrd24AR1rHxa3xVS7QwP6UErJpbtQFv7TR4lN9+7sEDtqsrEmxWOlxdhkdrsienx1 uZSUvQ+/sJtmkvuL6qeOLfe2wXZMpexHTaSUEjffmDsOyXOiBXCaqq5Wp7Yrfc68Om7ABS uctlYNzXL1hRGxtiUG3JOOXuJavRUGzOlmvHgQKsP+1XaeOK7WyJvNaH47CcemOsUFRSj7 ukUXKsQZ5dmYoZnYEDJcQXq3H/QOf2DauVafnR+KEr/iDjQR8AiIM1GIIQweOzxQ1jfB/9 v6DHlZFY3bSB1Tvj91dulgC2yoDP94v789wgw2wt3LjSooirnCtq2VXzt7GrMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705616784; a=rsa-sha256; cv=none; b=TMaQFVSYGnqNrRDZxXfypDPGFotTpzjfNpjO8NsZhH020TLrITA0rAhEgW216AVIwNyhBW iNTYy0TGuugfaWjwwsl/ck+/kZx1XAzvU27Kgb291GPPQI3GHkDRxP33zEdffDxLFv4wLn cyWXgcWYQwB7O7aVGN1Ham+tVq8zCU851KWSSI4l8HF/zNLnWutkcbtIKYkqNpFaQYLONe dSnwG1CxtMnqjY+itANeN0NkNJ/8Tx8oMb3//GwXAvplNEVdfVQ2rK0+i3IbDzrUphlmMu GNaf5sxzaVAelhzMI4pLkz4mbjI/GyHEQO+seNiavP7Kks54yFlyUbp3yLMRUQ== 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 4TGHQm5kCtzQKx; Thu, 18 Jan 2024 22:26:24 +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 40IMQOjG090332; Thu, 18 Jan 2024 22:26:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40IMQOMg090328; Thu, 18 Jan 2024 22:26:24 GMT (envelope-from git) Date: Thu, 18 Jan 2024 22:26:24 GMT Message-Id: <202401182226.40IMQOMg090328@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: 3ab67201a2f4 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 3ab67201a2f4c48cfba864f087bce2c0b85c0249 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3ab67201a2f4c48cfba864f087bce2c0b85c0249 commit 3ab67201a2f4c48cfba864f087bce2c0b85c0249 Author: Jessica Clarke AuthorDate: 2023-12-14 18:27:09 +0000 Commit: John Baldwin CommitDate: 2024-01-18 21:30:32 +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);