Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp598331lqp; Sun, 9 Jun 2024 10:09:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZOx64thhnGwbToXrG8BQmRlc2NqDzRSKD0jjwnYARxC6p424cb+3Pb+9YR5GM6iMswWuXdXMZlxrBzKFGCRPuq7lDgeoetNema2Ii4Q== X-Google-Smtp-Source: AGHT+IG8xbdP93oIhJ4ohMlm43N9ZVqA5BH6GYKvooWykniWLf3+zwfpdEZoBvaGnSxofcBn2P9O X-Received: by 2002:a05:620a:4491:b0:795:47c5:59b1 with SMTP id af79cd13be357-79547c55fa3mr832409085a.7.1717952990389; Sun, 09 Jun 2024 10:09:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717952990; cv=pass; d=google.com; s=arc-20160816; b=UGNSTsJgQLgZfG7UVswT7kq10XIXt2ekBpHwSj6W5IhedBM8Zeej+Y02UI3/YewxEg L25cVQ2z6i+jwjxgw7LThuc6HmR7rC0GaVwRgdDCF9hZRouHSx0d1LPLdih5XVPbP1T+ QfXRKsbjoDuSJa6Acq3KCXmDRY+ERCvpQQw9lEyE9LvjWewxdZwN6UbRyFbZ0el+TSMO FSDWDv2HBxVOZffDmB3+f1ASEcB/4i+hepSMkmsWjj+lvtsajttIYDy8Yin0BaJdgV9C 5VSsKevqPJ6JsIIxi99TsJxjbKrkPos+bsysaRNKTvTk505IUrlKetj+EEQX/p6qZmDn 2YLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tGqewXax5PYlT0n8lB+3ZuUvxYAHssvnsMqQ7iVc/Yk=; fh=7HnC7Uex5fEz2up45K14lx49glCQ0NA+JK3+QaU5qMY=; b=sf5DHHz5qKkLdY0gDdsnjq7R6lvmjmA5EknwEBe0sSTKdrkL4E4JG2DLOU7XSQlZkz sWVKd7KWgRftWLKs9eQ4hTmzOGL8/e8gXEakJi9YG5yWnot0fufDsqMRN2hgWlJ6h+aI xcA5qSXiizBTZOf4VSYnF54EFH6LEwU8Fd5f7FxfaMAHbAtISPhkiamOHUhQtiV5Tb1P 5Pkwas2cYe1Z7V7ZUd59qCKtFgosZvCFjwob25V1D3OOgLl/zOtWYQ0SOnCwYzErXyaq 04/hay4A2tufQzp4bgzgCHqR5WyhBC/Yl3kvoHMLWJ28AC3avNgU6Wz+NQesWEOOLzRm Tn9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q0ZmNO2J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-207438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-795f2fd686esi78067485a.123.2024.06.09.10.09.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 10:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q0ZmNO2J; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-207438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1DF581C20927 for ; Sun, 9 Jun 2024 17:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EB7D4D8AF; Sun, 9 Jun 2024 17:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q0ZmNO2J" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB4914CE05; Sun, 9 Jun 2024 17:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717952962; cv=none; b=t4anoQ+NS7jF/IjXEf015ZQsRYf5DFf4334acngiYELxwlD2JzHy9sAdqM5qx7rX1VQkF4d8nZAtYUbULB0L6gfHSI8JvNy6+zMoRIBR7dGrmwOSoFE3ZVQw3h07ywYXrQUuiOsKFENVpsSvtYgyy5vOcA1pi+1d05a4Fl3sG+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717952962; c=relaxed/simple; bh=CN5mfKSIOsNFwgS0HImQpDJa66QgoGbxMOB/gULNMSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvb9ezu4mYCp+vf4Tezw2sNtOEGvgM7oZKqpTv0SRYniBBDb9zOtH39ZH+UWna86D9ux+/fksADpJv9sqJGZFvEmr5VgTVr9+JB07/wXblZJONjdiDp0HwnayGpn3G3QFM3V6yF1pEQUSP6K/EQj2yFzmNB/iTZGtKeY8+e9R6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q0ZmNO2J; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 699B8C4AF1D; Sun, 9 Jun 2024 17:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717952962; bh=CN5mfKSIOsNFwgS0HImQpDJa66QgoGbxMOB/gULNMSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0ZmNO2Jo4JMy8hSeh2U5e5bXJqUYqCe8o+iKDCBJI7oO14oGW/EFjaQ6VOgDjP2K TBAp+URnKfDoyKHwCAtpQObX5u+r/dxFfbmw/crekq+UpzL0Zg7lU7/awHSRij/MGw wNBdjQhP4yI0WO35WxQrzA5SgIKKSzSgr+2X30rRP3GM4Vofs4fVEGPiDgwG2ERC/Z HSlqUQXuWE2HyirgbvlvibVD0dSEM3lqrzpiktHizfF6MheC+fviKvqw6Kpqm7MAyr 4VszE8xYUo8YtxuOI4PPBI6CTl9hyOAC0XrrRDMfjx5E9MRf3DfGhq+vsksgsLr1Nt BJCSU3v9VCYFw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Ard Biesheuvel , Arnd Bergmann , Nathan Chancellor , Nicolas Schier , linux-arch@vger.kernel.org Subject: [PATCH v2 2/3] kbuild: remove PROVIDE() for kallsyms symbols Date: Mon, 10 Jun 2024 02:04:19 +0900 Message-ID: <20240609170855.1708665-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240609170855.1708665-1-masahiroy@kernel.org> References: <20240609170855.1708665-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This reimplements commit 951bcae6c5a0 ("kallsyms: Avoid weak references for kallsyms symbols"). I am not a big fan of PROVIDE(). As an alternative solution, this commit prepends one more kallsyms step. KSYMS .tmp_vmlinux.kallsyms0.S # added AS .tmp_vmlinux.kallsyms0.o # added LD .tmp_vmlinux.btf BTF .btf.vmlinux.bin.o LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.o LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.o LD vmlinux Step 0 takes /dev/null as input, and generates .tmp_vmlinux.kallsyms0.o, which has a valid kallsyms format with the empty symbol list, and can be linked to vmlinux. Since it is really small, the added compile-time cost is negligible. Signed-off-by: Masahiro Yamada Acked-by: Ard Biesheuvel --- (no changes since v1) include/asm-generic/vmlinux.lds.h | 19 ------------------- kernel/kallsyms_internal.h | 5 ----- scripts/kallsyms.c | 6 ------ scripts/link-vmlinux.sh | 9 +++++++-- 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 5703526d6ebf..62b4cb0462e6 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -451,30 +451,11 @@ #endif #endif -/* - * Some symbol definitions will not exist yet during the first pass of the - * link, but are guaranteed to exist in the final link. Provide preliminary - * definitions that will be superseded in the final link to avoid having to - * rely on weak external linkage, which requires a GOT when used in position - * independent code. - */ -#define PRELIMINARY_SYMBOL_DEFINITIONS \ - PROVIDE(kallsyms_addresses = .); \ - PROVIDE(kallsyms_offsets = .); \ - PROVIDE(kallsyms_names = .); \ - PROVIDE(kallsyms_num_syms = .); \ - PROVIDE(kallsyms_relative_base = .); \ - PROVIDE(kallsyms_token_table = .); \ - PROVIDE(kallsyms_token_index = .); \ - PROVIDE(kallsyms_markers = .); \ - PROVIDE(kallsyms_seqs_of_names = .); - /* * Read only Data */ #define RO_DATA(align) \ . = ALIGN((align)); \ - PRELIMINARY_SYMBOL_DEFINITIONS \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h index 85480274fc8f..925f2ab22639 100644 --- a/kernel/kallsyms_internal.h +++ b/kernel/kallsyms_internal.h @@ -4,11 +4,6 @@ #include -/* - * These will be re-linked against their real values during the second link - * stage. Preliminary values must be provided in the linker script using the - * PROVIDE() directive so that the first link stage can complete successfully. - */ extern const unsigned long kallsyms_addresses[]; extern const int kallsyms_offsets[]; extern const u8 kallsyms_names[]; diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 47978efe4797..fa53b5eef553 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -259,12 +259,6 @@ static void shrink_table(void) } } table_cnt = pos; - - /* When valid symbol is not registered, exit to error */ - if (!table_cnt) { - fprintf(stderr, "No valid symbol.\n"); - exit(1); - } } static void read_map(const char *in) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index da3879469e53..6f2fdc9e4fbf 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -226,6 +226,10 @@ ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init init/version-timestamp.o kallsymso= btf_vmlinux_bin_o= +if is_enabled CONFIG_KALLSYMS; then + kallsyms /dev/null .tmp_vmlinux.kallsyms0 +fi + if is_enabled CONFIG_DEBUG_INFO_BTF; then if ! gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then echo >&2 "Failed to generate BTF for vmlinux" @@ -238,9 +242,10 @@ if is_enabled CONFIG_KALLSYMS; then # kallsyms support # Generate section listing all symbols and add it into vmlinux - # It's a three step process: + # It's a four step process: + # 0) Generate a dummy __kallsyms with empty symbol list. # 1) Link .tmp_vmlinux.kallsyms1 so it has all symbols and sections, - # but __kallsyms is empty. + # with a dummy __kallsyms. # Running kallsyms on that gives us .tmp_kallsyms1.o with # the right size # 2) Link .tmp_vmlinux.kallsyms2 so it now has a __kallsyms section of -- 2.43.0