Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp527372rdg; Thu, 12 Oct 2023 12:33:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7ZPQ5tCnsoMhtThkUCHegpsuQ8FifVotydFhijNC/7wJpd6CVBL/nhWCzGBkmKEyE33AP X-Received: by 2002:a17:902:d4ce:b0:1c9:c46c:71fc with SMTP id o14-20020a170902d4ce00b001c9c46c71fcmr8379879plg.59.1697139218078; Thu, 12 Oct 2023 12:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139218; cv=none; d=google.com; s=arc-20160816; b=IDzGfZvLQ7aiHEmxOGniKoj0hY6NFEyeruKTKyBSUb9fIXqYJF9Z9UbsYJaoAkToeZ aXAywIbEWqJMH5QWz5MWy92eT1hW4oiMr0zHUc4SJ95DbTgrWFPFhsc8RceFObX2DkuK 1jf5l852hqZ2JxJGqvt0RcVIc477HsQqdYPCsmFiqa1FBKjM3x6XeQDvnxhGS8rR56Bj 3pWF84BJz275eQAzsFHt5Jhumqj5XpcPUVwX8wo78zjHvfy56L/efLBJXx5RI/XVdrAF aF2QtJy3/ZD9AmZ//tNKY4nmi4i605OFEUbYnLpnmk40Sql9/FUXasPlIwMbRuR5Xv0N jcpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LdKfDPRFjeWUF+1bboAwIUwdKhU6hno0HHoXmTRbv8s=; fh=n5S/AR14tYMsjDdXEOPrR3UbxswSa5eTzDqlfcgbnjE=; b=nANqyg+N54GyVT7B8HrngurNf8ZixFKnFaRte/FLUdPpkJ7mlxdg8XixLqVn8zFhb1 kBoOYBJH1ZEF+/XKysqQYJAWvYAdfaMsRELebBc6vYUkzi1luVuybBVeOL/6PIxrAr+z i1x570AolP/MaU5J+uE53s1OzvGxLOApV/K59zOmw8K2jARcMzW6HoEAB9ek80wweSEH DS/YznW77ZzvMVHNgbPqng1MXzqqtJbCeqaJrICTsowmRjoK6W2FegJdAFztl0b4SC5m HoIdq+EsGSKL8S1TYA8FqgRwNAYM5WK+/46r34xbugkRKEprShrj+/+ZutO2Pm9hmnQe mzfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OI0iPa9X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t14-20020a1709027fce00b001c9af74feaesi2824670plb.215.2023.10.12.12.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OI0iPa9X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E0354828819E; Thu, 12 Oct 2023 12:33:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442533AbjJLTdd (ORCPT + 99 others); Thu, 12 Oct 2023 15:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442351AbjJLTcl (ORCPT ); Thu, 12 Oct 2023 15:32:41 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08073E6 for ; Thu, 12 Oct 2023 12:32:40 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F1F2C433B7; Thu, 12 Oct 2023 19:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697139156; bh=9AFyv1HVznQ9AGg8+z1evlIaZ1Y1s//n3eBUqbBd0OU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OI0iPa9XTvj/R2EO+FAijS+buu0vUftTld0QPQNLukmPbr1X7g1Bug8ZNrXwXrmd7 2iI7bz4ycOXbkK7Ch8gzBAy7fFUHXG4iv7HFWM1fdkonvkdTZLwlZoRZTp8R6Sn1Kn LTlAwVEPqMvjbZqElhLBlMKSEsdrb0vn9f0Ptog3Weh9KHNMXwSaup0HRsdwyA2y+K AJIMTtjcmHtU2dHLco+x3QuRYNYoqsPdKOmT2mnzPu7bA9ggSoVGvH4h02/dfkGs7Q SInBzRTyPIIcH4XgirxvfeeUNLSm0kiiE8d4zVzVymazvs14LnDdajfnlTR1qs34yp ic8flnuhLXNqw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6AFD6CE1059; Thu, 12 Oct 2023 12:32:35 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau Subject: [PATCH nolibc 19/19] selftests/nolibc: add tests for multi-object linkage Date: Thu, 12 Oct 2023 12:32:33 -0700 Message-Id: <20231012193233.207857-19-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:33:37 -0700 (PDT) From: Thomas Weißschuh While uncommon, nolibc executables can be linked together from multiple compilation units. Add some tests to make sure everything works in that case. Signed-off-by: Thomas Weißschuh Link: https://lore.kernel.org/lkml/20231012-nolibc-linkage-test-v1-1-315e682768b4@weissschuh.net/ Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/Makefile | 12 ++++----- .../selftests/nolibc/nolibc-test-linkage.c | 26 +++++++++++++++++++ .../selftests/nolibc/nolibc-test-linkage.h | 9 +++++++ tools/testing/selftests/nolibc/nolibc-test.c | 4 +++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/nolibc/nolibc-test-linkage.c create mode 100644 tools/testing/selftests/nolibc/nolibc-test-linkage.h diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index af60e07d3c12..a0fc07253baf 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -171,17 +171,17 @@ sysroot/$(ARCH)/include: $(Q)mv sysroot/sysroot sysroot/$(ARCH) ifneq ($(NOLIBC_SYSROOT),0) -nolibc-test: nolibc-test.c sysroot/$(ARCH)/include +nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ - -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $< -lgcc + -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c -lgcc else -nolibc-test: nolibc-test.c +nolibc-test: nolibc-test.c nolibc-test-linkage.c $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ - -nostdlib -static -include ../../../include/nolibc/nolibc.h $< -lgcc + -nostdlib -static -include ../../../include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc endif -libc-test: nolibc-test.c - $(QUIET_CC)$(HOSTCC) -o $@ $< +libc-test: nolibc-test.c nolibc-test-linkage.c + $(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c # local libc-test run-libc-test: libc-test diff --git a/tools/testing/selftests/nolibc/nolibc-test-linkage.c b/tools/testing/selftests/nolibc/nolibc-test-linkage.c new file mode 100644 index 000000000000..5ff4c8a1db2a --- /dev/null +++ b/tools/testing/selftests/nolibc/nolibc-test-linkage.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include "nolibc-test-linkage.h" + +#ifndef NOLIBC +#include +#endif + +void *linkage_test_errno_addr(void) +{ + return &errno; +} + +int linkage_test_constructor_test_value; + +__attribute__((constructor)) +static void constructor1(void) +{ + linkage_test_constructor_test_value = 2; +} + +__attribute__((constructor)) +static void constructor2(void) +{ + linkage_test_constructor_test_value *= 3; +} diff --git a/tools/testing/selftests/nolibc/nolibc-test-linkage.h b/tools/testing/selftests/nolibc/nolibc-test-linkage.h new file mode 100644 index 000000000000..c66473070d73 --- /dev/null +++ b/tools/testing/selftests/nolibc/nolibc-test-linkage.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _NOLIBC_TEST_LINKAGE_H +#define _NOLIBC_TEST_LINKAGE_H + +void *linkage_test_errno_addr(void); +extern int linkage_test_constructor_test_value; + +#endif /* _NOLIBC_TEST_LINKAGE_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8da7f15d010e..2f10541e6f38 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -41,6 +41,8 @@ #endif #endif +#include "nolibc-test-linkage.h" + /* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */ #define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2))) #define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1) @@ -647,6 +649,8 @@ int run_startup(int min, int max) CASE_TEST(auxv_addr); EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break; CASE_TEST(auxv_AT_UID); EXPECT_EQ(1, getauxval(AT_UID), getuid()); break; CASE_TEST(constructor); EXPECT_EQ(1, constructor_test_value, 2); break; + CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break; + CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_value, 6); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ -- 2.40.1