From nobody Fri Oct 18 20:21:40 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 4XVbhN6sSSz5Yv4y; Fri, 18 Oct 2024 20:21:40 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XVbhN5jZgz4GRB; Fri, 18 Oct 2024 20:21:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729282900; 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=pGMjfmPwSGAkIrxyO9rMeBjG3vc0oweTSx20RkgQMyA=; b=EVHCzXdsKDG2+5fm9XS+a3fhEefJJVDxzv55BGBT8rmWSnRF01da+w+Z3by04gAWo50WNM lrrT2+RP1l1Yx4ryGSUZXL712iolyWcBg8ZLt/15WUqLYpZYNlNzF6QJsoPYRE3RUuZFIq cNpf9M2iwH7X1579T8atmmm9IO1TLnbqsu0TamwQjEQ2WxjOxBNLvjg6ZRvZ0TsncvFJbN 5PX9dcE3DW0hWo2Bi/s6Ue3gYCN9dsSb5+Nr8dFQOy9tAdTYH4Io+BF/KIAKN3tkrSWcER q/d54KLXNCzsBAXC1ETGs2YiGteqV7w3Ge1eAMeB6cqSvJ5ippzWSzjp/Tjl7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729282900; 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=pGMjfmPwSGAkIrxyO9rMeBjG3vc0oweTSx20RkgQMyA=; b=l0DG/g8Y2+pYMkQtMxeGq7BGt38tQn2sXFjEzzR4XsmUGFb4aFt0ZjvYscMkyLfuENh0/3 eXcLq7qBhazaOWbluTc6hTSf/bUPfuTABgGm4FLgPciN77byYEnzgmcjjfOKEkBU0v6oNY WTrkS7ImxJg1SLhyhc5y77PvwVIsDkoF4GljfMVT31WhHqDOzOcLqLIbo30+L01BmugPy0 wiwOfZouPczrndq0Gcp1mfL+rmqhI1zHkW5hfQKgY4C5IW7yMPwsS+s2qt2wkaj7ZR6y2a /b4K3Y6t+yj35pIVO0K2MpQrPczBBPif7BoQFNhCXQbGe+L8BTv8h6xyLeiNnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729282900; a=rsa-sha256; cv=none; b=T0vo2ZcXMgVdgIW0rnuBiZDqut7mnbPE/bS48uiG0sCUmaBAAK4TawtgyfLz0UywHIbGKF fDVsUdtO3xmKgtRAudlnEtVM4FVm7xmkEovC1hJtWjnCGqq5Zx3wBKfiF7lybhlvDNIfct J8TmiBX6wLlBBQD3M3xBjlJT4Yr+1XFJzlkNYQUDv00TQHItVBtXpe/T9tM5+FtHv1CvkO AesU75WiUPonJNI3uc0xXGK10TaUBV1HEgDDCgF6L3/9fm8idSeo0muGOJcHZ8VxNHV3MG L3XlW7qWRaGYV+BUkPa5ETeHAQn0jXbsDjVB6jWz7zeqQTqKpAQnumEdvhTJ3w== 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 4XVbhN5K90zndW; Fri, 18 Oct 2024 20:21:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49IKLeo3074897; Fri, 18 Oct 2024 20:21:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49IKLe0C074894; Fri, 18 Oct 2024 20:21:40 GMT (envelope-from git) Date: Fri, 18 Oct 2024 20:21:40 GMT Message-Id: <202410182021.49IKLe0C074894@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ka Ho Ng Subject: git: 43628a31e3a2 - main - libkldelf: add elf_lookup_symbol function 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 43628a31e3a22e1ea9e2936bdcb07ecbd72aaa5f Auto-Submitted: auto-generated The branch main has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=43628a31e3a22e1ea9e2936bdcb07ecbd72aaa5f commit 43628a31e3a22e1ea9e2936bdcb07ecbd72aaa5f Author: Ka Ho Ng AuthorDate: 2024-10-08 04:24:37 +0000 Commit: Ka Ho Ng CommitDate: 2024-10-18 20:21:44 +0000 libkldelf: add elf_lookup_symbol function The elf_lookup_symbol function looks up the symbol with a given symbol name. A pointer to the GElf_Sym of the symbol is returned if the symbol exists in the opened ELF file. Sponsored by: Juniper Networks, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D46764 --- lib/libkldelf/ef.c | 1 + lib/libkldelf/ef_obj.c | 1 + lib/libkldelf/elf.c | 6 ++++++ lib/libkldelf/kldelf.h | 13 +++++++++++++ 4 files changed, 21 insertions(+) diff --git a/lib/libkldelf/ef.c b/lib/libkldelf/ef.c index 052798ee31e4..dcd87fe2bf83 100644 --- a/lib/libkldelf/ef.c +++ b/lib/libkldelf/ef.c @@ -89,6 +89,7 @@ static struct elf_file_ops ef_file_ops = { .seg_read_string = ef_seg_read_string, .symaddr = ef_symaddr, .lookup_set = ef_lookup_set, + .lookup_symbol = ef_lookup_symbol, }; static void diff --git a/lib/libkldelf/ef_obj.c b/lib/libkldelf/ef_obj.c index e09bd036b71e..32a7c17127ed 100644 --- a/lib/libkldelf/ef_obj.c +++ b/lib/libkldelf/ef_obj.c @@ -109,6 +109,7 @@ static struct elf_file_ops ef_obj_file_ops = { .seg_read_string = ef_obj_seg_read_string, .symaddr = ef_obj_symaddr, .lookup_set = ef_obj_lookup_set, + .lookup_symbol = ef_obj_lookup_symbol, }; static GElf_Off diff --git a/lib/libkldelf/elf.c b/lib/libkldelf/elf.c index da319ffc6c98..8af02622de13 100644 --- a/lib/libkldelf/elf.c +++ b/lib/libkldelf/elf.c @@ -686,3 +686,9 @@ elf_reloc(struct elf_file *efile, const void *reldata, Elf_Type reltype, return (efile->ef_reloc(efile, reldata, reltype, relbase, dataoff, len, dest)); } + +int +elf_lookup_symbol(struct elf_file *efile, const char *name, GElf_Sym **sym) +{ + return (EF_LOOKUP_SYMBOL(efile, name, sym)); +} diff --git a/lib/libkldelf/kldelf.h b/lib/libkldelf/kldelf.h index e0a8cc627ff2..71de31a94291 100644 --- a/lib/libkldelf/kldelf.h +++ b/lib/libkldelf/kldelf.h @@ -48,6 +48,8 @@ (ef)->ef_ops->symaddr((ef)->ef_ef, symidx) #define EF_LOOKUP_SET(ef, name, startp, stopp, countp) \ (ef)->ef_ops->lookup_set((ef)->ef_ef, name, startp, stopp, countp) +#define EF_LOOKUP_SYMBOL(ef, name, sym) \ + (ef)->ef_ops->lookup_symbol((ef)->ef_ef, name, sym) /* XXX, should have a different name. */ typedef struct ef_file *elf_file_t; @@ -67,6 +69,7 @@ struct elf_file_ops { GElf_Addr (*symaddr)(elf_file_t ef, GElf_Size symidx); int (*lookup_set)(elf_file_t ef, const char *name, GElf_Addr *startp, GElf_Addr *stopp, long *countp); + int (*lookup_symbol)(elf_file_t ef, const char *name, GElf_Sym **sym); }; typedef int (elf_reloc_t)(struct elf_file *ef, const void *reldata, @@ -310,6 +313,16 @@ int elf_read_mod_pnp_match_info(struct elf_file *efile, GElf_Addr addr, int elf_reloc(struct elf_file *ef, const void *reldata, Elf_Type reltype, GElf_Addr relbase, GElf_Addr dataoff, size_t len, void *dest); +/* + * Find the symbol with the specified symbol name 'name' within the given + * 'efile'. 0 is returned when such a symbol is found, otherwise ENOENT is + * returned. + * + * XXX: This only return the first symbol being found when traversing symtab. + */ +int elf_lookup_symbol(struct elf_file *efile, const char *name, + GElf_Sym **sym); + __END_DECLS #endif /* _KLDELF_H_*/