From nobody Fri Dec 15 18:57:34 2023 X-Original-To: dev-commits-src-branches@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 4SsJPW1s9hz53wqS; Fri, 15 Dec 2023 18:57:35 +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 4SsJPW0sDnz3MJl; Fri, 15 Dec 2023 18:57:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702666655; 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=GGi/F2vbxbX3+dEmCs99RvGQTMNWgk4ffT2HgWBdeWw=; b=TjMNPmO81zGZr+UJt5zi/1xhsYWClnJ2CB1clLe2tenCQY/mi5+M8oHDgisPbYE0elPTLj zY80Db122XhyrB+HDRAUKyb2Dz0ZodKHJGyeZ3M9gGzij0RNnrmNxCGrv1vXQvgZZHrLoz x8iWOnhuTff5lJftNnOCg6X22yqR78CTv/XtEj3rjmaYjXm8hk8VICHSodPwkTGc122UJb u/sXhh7IqSnk5v7CBCfmjo0Le5wjV6Z+/w2vNkoP5D63jI59nNyMCOPNHiCvgcYNx7ySui b+5BUiKUfRCgBX4qb/9vQF9l0g++l/FQ68xNLu1eiF/CZz8+8fUrUGPWhriQJg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702666655; a=rsa-sha256; cv=none; b=u/Vr3Zj1RsUsa00Iu9dB7a5n6nLsQm17e9QNKfMPMgs7Bwy98dyDrhTRxE/nLW4MV2NEFu CKJOl4tErrDlk2GCaSTokVfzrkViyzlA3e0NYE5z8Sdp28U996nec5exbCDRtEl5DQDSFU A+4fSe1UsrCSLuTqf6jypEoqoDWFp7t+vi02ZoWgb7HK/FKhC3jKbq0SOez2Tq7W5rSu0C nFvHE81Sa0YsaSXqg+9tAV4zUBfw83EYON3xpwPExkuM3bmpU9uPu6Tn28DZRYQhyHM3q4 hl49y5b/aZzqreWRA9UAi/VupyZJK2o93ANrReuZiNeWsvthWIM0ugLc8VeyMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702666655; 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=GGi/F2vbxbX3+dEmCs99RvGQTMNWgk4ffT2HgWBdeWw=; b=rHn9o1s8MNTLi3XAabuXUM/5r3hgzVpmjvDDCGHXxxisFfKzLYHAYpqEWK6GDPn8HyZjc+ MXIFI+Jkz04M00QMJcizAuJ5hIuUIjCkl1f257APMhp6xLXPrO6oN5l9yEMBMPYYK3e8Lo pnv3nVEyM8IN6lw/XqVd7U9Emb808IaM1StsqO9VI/eh1SLctJB0iSVyuKca/PIO2Z2GnO s7yuH79CrdxwaA/SSOSxHG5lKosF/nhOETaeYRj4JHsRlCFx++DvNykDH3oXGMGc4eLBkt oyEjT5vPYR6S15dNJDHMMSHLd251n2w3RpqVdeH1H2swI6qkrbCkcjezelwebA== 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 4SsJPV74Gnz7cn; Fri, 15 Dec 2023 18:57:34 +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 3BFIvYOF018494; Fri, 15 Dec 2023 18:57:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BFIvYIM018491; Fri, 15 Dec 2023 18:57:34 GMT (envelope-from git) Date: Fri, 15 Dec 2023 18:57:34 GMT Message-Id: <202312151857.3BFIvYIM018491@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 9986fd59d855 - stable/13 - rtld: add a test for RTLD_DEEPBIND List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9986fd59d855234cbb999b2a4099ad3cd094aa49 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=9986fd59d855234cbb999b2a4099ad3cd094aa49 commit 9986fd59d855234cbb999b2a4099ad3cd094aa49 Author: Kyle Evans AuthorDate: 2023-12-01 01:26:09 +0000 Commit: Kyle Evans CommitDate: 2023-12-15 16:56:59 +0000 rtld: add a test for RTLD_DEEPBIND This tests that with RTLD_DEEPBIND, symbols are looked up in all of the object's needed objects before the global object. ATF_REQUIRE_INTEQ was added after stable/13 branched, so we shim it out here. PR: 275393 Reviewed by: kib Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. (cherry picked from commit d9c543b6b0cabea6e6679d70b4e701018e7eab80) --- etc/mtree/BSD.tests.dist | 2 + libexec/rtld-elf/tests/Makefile | 5 +- libexec/rtld-elf/tests/Makefile.inc | 3 + libexec/rtld-elf/tests/libdeep/Makefile | 15 +++++ libexec/rtld-elf/tests/libdeep/libdeep.c | 28 +++++++++ libexec/rtld-elf/tests/libval/Makefile | 10 +++ libexec/rtld-elf/tests/libval/libval.c | 26 ++++++++ libexec/rtld-elf/tests/libval2/Makefile | 8 +++ libexec/rtld-elf/tests/rtld_deepbind/Makefile | 10 +++ .../rtld-elf/tests/rtld_deepbind/rtld_deepbind.c | 72 ++++++++++++++++++++++ libexec/rtld-elf/tests/target/Makefile | 2 +- 11 files changed, 179 insertions(+), 2 deletions(-) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index f9a551bbc39b..5714d873cb3b 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -432,6 +432,8 @@ rc .. rtld-elf + rtld_deepbind + .. .. tftpd .. diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile index 7eacfb899699..06e143a441a1 100644 --- a/libexec/rtld-elf/tests/Makefile +++ b/libexec/rtld-elf/tests/Makefile @@ -1,6 +1,9 @@ -SUBDIR+= libpythagoras target +SUBDIR+= libpythagoras libdeep libval libval2 target +TESTS_SUBDIRS+= rtld_deepbind +SUBDIR_DEPEND_libdeep= libval2 +SUBDIR_DEPEND_rtld_deepbind= libval SUBDIR_DEPEND_target= libpythagoras ATF_TESTS_C= ld_library_pathfds diff --git a/libexec/rtld-elf/tests/Makefile.inc b/libexec/rtld-elf/tests/Makefile.inc new file mode 100644 index 000000000000..dfba72a51ce7 --- /dev/null +++ b/libexec/rtld-elf/tests/Makefile.inc @@ -0,0 +1,3 @@ + +PACKAGE?= tests +TESTSDIR?= ${TESTSBASE}/libexec/rtld-elf diff --git a/libexec/rtld-elf/tests/libdeep/Makefile b/libexec/rtld-elf/tests/libdeep/Makefile new file mode 100644 index 000000000000..9324b6f25efe --- /dev/null +++ b/libexec/rtld-elf/tests/libdeep/Makefile @@ -0,0 +1,15 @@ + +SHLIB?= deep +SHLIB_MAJOR= 0 + +LIBDIR= ${TESTSBASE}/libexec/rtld-elf/rtld_deepbind +SHLIBDIR= ${TESTSBASE}/libexec/rtld-elf/rtld_deepbind + +SRCS= libdeep.c + +LIBVAL2= ${.OBJDIR}/../libval2 +LDFLAGS+= -L${LIBVAL2} -Wl,-rpath,'$$ORIGIN' +DPADD+= -lval2 +LDADD+= -lval2 + +.include diff --git a/libexec/rtld-elf/tests/libdeep/libdeep.c b/libexec/rtld-elf/tests/libdeep/libdeep.c new file mode 100644 index 000000000000..e570769300cf --- /dev/null +++ b/libexec/rtld-elf/tests/libdeep/libdeep.c @@ -0,0 +1,28 @@ +/*- + * + * Copyright (C) 2023 NetApp, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + * + */ + +#include + +int get_value(void); +int proxy_get_value(void); +void set_value(int); +void proxy_set_value(int); + +int +proxy_get_value(void) +{ + + return (get_value()); +} + +void +proxy_set_value(int val) +{ + + return (set_value(val)); +} diff --git a/libexec/rtld-elf/tests/libval/Makefile b/libexec/rtld-elf/tests/libval/Makefile new file mode 100644 index 000000000000..66728c01dc9b --- /dev/null +++ b/libexec/rtld-elf/tests/libval/Makefile @@ -0,0 +1,10 @@ + +SHLIB?= val +SHLIB_MAJOR= 0 + +LIBDIR= ${TESTSBASE}/libexec/rtld-elf/rtld_deepbind +SHLIBDIR= ${TESTSBASE}/libexec/rtld-elf/rtld_deepbind + +SRCS= libval.c + +.include diff --git a/libexec/rtld-elf/tests/libval/libval.c b/libexec/rtld-elf/tests/libval/libval.c new file mode 100644 index 000000000000..97c97a0310a7 --- /dev/null +++ b/libexec/rtld-elf/tests/libval/libval.c @@ -0,0 +1,26 @@ +/*- + * + * Copyright (C) 2023 NetApp, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + * + */ + +static int val; + +int get_value(void); +void set_value(int); + +int +get_value(void) +{ + + return (val); +} + +void +set_value(int nval) +{ + + val = nval; +} diff --git a/libexec/rtld-elf/tests/libval2/Makefile b/libexec/rtld-elf/tests/libval2/Makefile new file mode 100644 index 000000000000..2b5cf5342092 --- /dev/null +++ b/libexec/rtld-elf/tests/libval2/Makefile @@ -0,0 +1,8 @@ + +LIBVAL= ${.CURDIR}/../libval + +# Just rebuild libval +.PATH: ${LIBVAL:tA} +SHLIB?= val2 + +.include "${LIBVAL}/Makefile" diff --git a/libexec/rtld-elf/tests/rtld_deepbind/Makefile b/libexec/rtld-elf/tests/rtld_deepbind/Makefile new file mode 100644 index 000000000000..bcc55d945c7e --- /dev/null +++ b/libexec/rtld-elf/tests/rtld_deepbind/Makefile @@ -0,0 +1,10 @@ + +TESTSDIR?= ${TESTSBASE}/libexec/rtld-elf/rtld_deepbind +ATF_TESTS_C= rtld_deepbind + +LIBVAL= ${.OBJDIR}/../libval +LDFLAGS.rtld_deepbind+= -L${LIBVAL} -Wl,-rpath,'$$ORIGIN' +DPADD+= -lval +LDADD+= -lval + +.include diff --git a/libexec/rtld-elf/tests/rtld_deepbind/rtld_deepbind.c b/libexec/rtld-elf/tests/rtld_deepbind/rtld_deepbind.c new file mode 100644 index 000000000000..30f71331bc62 --- /dev/null +++ b/libexec/rtld-elf/tests/rtld_deepbind/rtld_deepbind.c @@ -0,0 +1,72 @@ +/*- + * + * Copyright (C) 2023 NetApp, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + * + */ + +#include + +#include + +int get_value(void); +void set_value(int); + +#define APP_VALUE 5 +#define LIB_VALUE 20 + +#ifndef ATF_REQUIRE_INTEQ +/* atf-c/macros.h */ +#define ATF_REQUIRE_INTEQ(expected, actual) \ + ATF_REQUIRE_MSG((expected) == (actual), "%s != %s (%jd != %jd)", #expected, \ + #actual, (intmax_t)(expected), (intmax_t)(actual)) +#endif + +ATF_TC_WITHOUT_HEAD(deepbind_simple); +ATF_TC_BODY(deepbind_simple, tc) +{ + void *hdl; + void (*proxy_set_value)(int); + int (*proxy_get_value)(void); + int app_value, lib_value; + + set_value(APP_VALUE); + + /* + * libdeep has a dependency on libval2.so, which is a rebuild of + * libval.so that provides get_value() and set_value() for both us and + * the lib. The lib's get_value() and set_value() should bind to the + * versions in libval2 instead of libval with RTLD_DEEPBIND. + */ + hdl = dlopen("$ORIGIN/libdeep.so", RTLD_LAZY | RTLD_DEEPBIND); + ATF_REQUIRE(hdl != NULL); + + proxy_set_value = dlsym(hdl, "proxy_set_value"); + ATF_REQUIRE(proxy_set_value != NULL); + + proxy_get_value = dlsym(hdl, "proxy_get_value"); + ATF_REQUIRE(proxy_get_value != NULL); + + (*proxy_set_value)(LIB_VALUE); + + lib_value = (*proxy_get_value)(); + app_value = get_value(); + + /* + * In the initial implementation or if libdeep.so is *not* linked + * against its own libval2, then these both return the later set + * LIB_VALUE (20) as they bind to the symbol provided by libval and + * use its .bss val. + */ + ATF_REQUIRE_INTEQ(lib_value, LIB_VALUE); + ATF_REQUIRE_INTEQ(app_value, APP_VALUE); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, deepbind_simple); + + return atf_no_error(); +} diff --git a/libexec/rtld-elf/tests/target/Makefile b/libexec/rtld-elf/tests/target/Makefile index f63d8072ae3c..aa4875b6748d 100644 --- a/libexec/rtld-elf/tests/target/Makefile +++ b/libexec/rtld-elf/tests/target/Makefile @@ -2,7 +2,7 @@ .include PROG= target -BINDIR= ${TESTSBASE}/libexec/rtld-elf +BINDIR= ${TESTSDIR} WARNS?= 3 CFLAGS+= -I${.CURDIR}/../libpythagoras