From patchwork Fri Sep 5 17:01:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 250 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091754; bh=wueSKN2OPP0c/uyXOuyMBqyyiwWVU3DA43D79vGNyw8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=mqkYmAo3JrueXRakwFMOQawn3yPmolrbNikzKDvogWaxgeLSHDMDEL7rP31OJjxAv MAJ0ZoDSVxvZLuSGA6amaa8HolulxhvH4qFXpbEYlKOkCzUjfZPCwXwiooJkoYQ7b7 a8CH70La+Wy5re0sqFdfr+42DAhPMQUSlgg76fVJl/ygS62lennmZYCEHFgtJ7qcZh ZSbblDYix1o1Ctfl0v82yytzrizuaMvbt1OBlhZvnvCGcYjKP5PN+PEY629K075Ea0 +9bOswsglfeieqGmy1UyAq4cIiyfxwUd9NSFcpUtJ4NzU81DTAjoq8A6QCHE2cJRZf wcUP0atOsvOow== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EECA4679A8 for ; Fri, 5 Sep 2025 11:02:34 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id PVhvnsWOs8mB for ; Fri, 5 Sep 2025 11:02:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091754; bh=wueSKN2OPP0c/uyXOuyMBqyyiwWVU3DA43D79vGNyw8=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=mqkYmAo3JrueXRakwFMOQawn3yPmolrbNikzKDvogWaxgeLSHDMDEL7rP31OJjxAv MAJ0ZoDSVxvZLuSGA6amaa8HolulxhvH4qFXpbEYlKOkCzUjfZPCwXwiooJkoYQ7b7 a8CH70La+Wy5re0sqFdfr+42DAhPMQUSlgg76fVJl/ygS62lennmZYCEHFgtJ7qcZh ZSbblDYix1o1Ctfl0v82yytzrizuaMvbt1OBlhZvnvCGcYjKP5PN+PEY629K075Ea0 +9bOswsglfeieqGmy1UyAq4cIiyfxwUd9NSFcpUtJ4NzU81DTAjoq8A6QCHE2cJRZf wcUP0atOsvOow== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DEB956799D for ; Fri, 5 Sep 2025 11:02:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091753; bh=ktHPRhoDvo6c42wdaRnIGNKcUUPB2+DplJqCx3SY4/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZHw2sOPRvqomSPTGGdjRMht6z2bXk5hagEzAxPITT42yYIMUrtW9wi3aY3p2oUF6u R6n0FAGJjyttzDr7Pe+J2/RA5Hc7lTG+cj78vFMlUi1uLgvlWY1CMyohZZVFfHPPyW J5s9n77MWNy00OAPhchmHdDPLMmCxbILrf5gPYq13ndARrZD/5/CK5YfnseTe7ZCbo emp7cmYaIz7Pxd+gtgAUgo9IEaEelx2RyFjKNa1t/nF93Ck/BziU7ZyBJ6zI1Lunjm xwmIz176cZUIkRUrgaTttMHk5NXic7VQYWwxSJudwdTtH+OwhKzD1k7hDDt3UK9kXa x88cajfxDrmMQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D1B1E6799D; Fri, 5 Sep 2025 11:02:33 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id Mpk2uoyxqfq2; Fri, 5 Sep 2025 11:02:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757091748; bh=Pp6XC6z6cSfwVPXLUvGGdUPTg2kqppvnPUdp/X225Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a97DkL0tkWrYgYH+/Cqf+zrUl4tzbHi0ZHaxsUkvZg3TfLkZ3c2+/5DKiymvR+Cx2 fLoZhfxv3HvEXzjMALQ5T1UciHnl3qL2WeNegbMKtK51k2Eu7ITqrqyrtUFza9m3hb YMfDpL+KU6J9JHAuW8IHtCZSS0Zjm2Mju1mob+8rbrvXK7a7hl03If59LAOqEBxQPn jWm6q7ZKGVDK2762XmGntEA7S0klD4Q4xQSirDg05xqHLnnSa4kxoQ2wBXyTugSVcz SIgRna0Lkd3BLxzkTBNH1K84ulfMal3TxGy0CrLX3OJpIQbryG0IbgSSmK6QNsiK2f 57Q0ivjTBjEgQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 00257678E6; Fri, 5 Sep 2025 11:02:27 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 5 Sep 2025 11:01:24 -0600 Message-ID: <20250905170132.182249-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250905170132.182249-1-sjg@u-boot.org> References: <20250905170132.182249-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VTUUW7F5NXZFK7QPPHYFOW5GNY3DTZ7S X-Message-ID-Hash: VTUUW7F5NXZFK7QPPHYFOW5GNY3DTZ7S X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/15] ulib: Provide a bit more info in the library-test program List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass When the test is run, indicate which library the test was linked against, static or dynamic. Drop the printf() at the start of main(). Since all printf() calls go to U-Boot, this message is not shown anyway, since the global-data pointer gd is NULL at this point and console_puts() just returns immediately. Signed-off-by: Simon Glass --- test/ulib/ulib_test.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/test/ulib/ulib_test.c b/test/ulib/ulib_test.c index a68290ff484..51b1c62e6b2 100644 --- a/test/ulib/ulib_test.c +++ b/test/ulib/ulib_test.c @@ -2,7 +2,7 @@ /* * Test application for U-Boot shared library * - * This demonstrates linking against libu-boot.so + * This demonstrates linking against libu-boot.so and libu-boot.a * * Copyright 2025 Canonical * Written by Simon Glass @@ -11,17 +11,50 @@ /* Use system headers, not U-Boot headers */ #include #include + +#include #include +/* Runtime detection of link type using /proc/self/maps */ +static const char *detect_link_type(void) +{ + char line[512]; + int fd; + int found_libuboot = 0; + + /* Open /proc/self/maps to check loaded libraries */ + fd = os_open("/proc/self/maps", 0); + if (fd < 0) + return "unable to detect linkage"; + + /* Read line by line to avoid boundary issues */ + while (os_fgets(line, sizeof(line), fd)) { + if (strstr(line, "libu-boot.so")) { + found_libuboot = 1; + break; + } + } + + os_close(fd); + + /* Return appropriate message based on what we found */ + if (found_libuboot) + return "dynamically linked (uses libu-boot.so)"; + else + return "statically linked (uses libu-boot.a)"; +} + int main(int argc, char *argv[]) { int ret; - printf("Calling U-Boot initialization via shared library...\n"); - ret = ulib_init(argv[0]); if (ret) return 1; + printf("Hello, world\n"); + printf("\n- U-Boot\n"); + printf("\nPS: This program is %s\n", detect_link_type()); + return ret; }