From patchwork Fri Mar 29 09:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13610489 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D51240866 for ; Fri, 29 Mar 2024 09:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704856; cv=none; b=Pz14oBV95aWQiRyyfTIeh93MvHq/osEZG7ohFbEjkuXDRqf5hH67Z/wYjBp4CqJVaczUC+bC6e1+942NXa0ysHSaOf+llVqjWOE4MHcjrQZjcvAMFgIFmZEzlVR17zkfALRfpSe94WKgYhw6nDSY4BRllYbdmYWK9TMctGOdEZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704856; c=relaxed/simple; bh=7xZ8SeIpLR8unxHGJ2waGwWOo71Rkq91p6J16D7wil4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B3weQUjodEQEFFbRHbWttrgoNjFwFGUY+RE8S3K2tONNnmTItCxeK0FGUC0c4rhzPybE/8oA2/6JNSE6l3Se81C3RkL9uhAX1W2OrccmAlH/2g+QB7zPLKuk42ThsJPwhEfYAZ/7x+yYBauqOKAtDITJmPCy5xp8e4/siHfwOuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xdBIRzPx; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xdBIRzPx" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so3022672276.2 for ; Fri, 29 Mar 2024 02:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711704852; x=1712309652; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fcRm/bqwNQMHH+e8ox8c6p1gyU6LuJWVGjxyAVGlxGQ=; b=xdBIRzPxASDpXxfQyffaW9n09aLkGXLW6RIh/qJzQ0Sr9yzGG+MWT88y3ag2R3Uj40 A55TBeliLa2Em4urkNfUs7XdFsdeiddLRzaekgovUe+9JqLUNo5OTnQ757LfWLJG8QyF 1WEmLsRLzLflywU7/RJbqijp0wnTfYE2PiLO1HIRGJcLy8jargxaCRCnV9Yd8U3PTm/c 1EFmeOT8YB5SzhwurfDK/LiYokZESvPGyiND7QJ/TmUo/qJ/eYkLARDU4aDCqNkn6Ur5 KCqi0w0hY7drGSM6tc12ar/eeBkefUkbAZfsxZceBFwESKtX3Fl36feybDuQF5V37IBl YdRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711704852; x=1712309652; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fcRm/bqwNQMHH+e8ox8c6p1gyU6LuJWVGjxyAVGlxGQ=; b=C9uPZE0k1eXsU7JnAwuq34B71fVFPjxJMHZ33KfcygTe7BmKwqfbVvShwOUMOpxpDo mcb1Onwucp8AfDIBC5I2UgmEjeGk6aJFa6xeR8RmIhS8x2lHmYuVgioYasGVstUWzUJh tTbw8UqCzFE4/wvZ723XfuLb3i6De7Jug/Pdg8XQQkJmDoLQC/20rnB2biGh9hs9HZTk zANPyEjZSGy8ENkTwd+1C35UXJ1eHv+RDLCO1PkQt+R0suOcU9DRXMhulPNoP1O/a4u6 hCzHXAP0DmQOm9o1TAVnFrGP+f2p9yiwMpKvStM38nS7FBeqOghofR9m7nP31DWl7Oiq X2RA== X-Forwarded-Encrypted: i=1; AJvYcCUJ7lho1299AVVopkuy9lGG8EQ8BTJO8f86LEhP7bhMJ5jm+G6FaIWRXR3WyoXYP0EXwZO+nNrMKVtJ+FdJQg+H/cwV X-Gm-Message-State: AOJu0Yyn/qu8KZzKjY6vVtmyX+eQ6tVZbzRKgmuS8TgdPYjNprsGHpTn U1caEQwLhGvwH0iUTm5L1V/Aeg9krnmvQh0l4JB+PfYvvfaN0Hmwh8a9fbZr0M62Jc+oQw== X-Google-Smtp-Source: AGHT+IFEwfUbLHTvkc8MJMJvLtHR8bnLhlr/Akn25B9EgNmxsaSATpfpG0uSKrZVv8v1js7hDQE3EGer X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1888:b0:dda:c57c:b69b with SMTP id cj8-20020a056902188800b00ddac57cb69bmr570656ybb.0.1711704852336; Fri, 29 Mar 2024 02:34:12 -0700 (PDT) Date: Fri, 29 Mar 2024 10:33:58 +0100 In-Reply-To: <20240329093356.276289-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329093356.276289-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5349; i=ardb@kernel.org; h=from:subject; bh=bi9e/PWpqNvBy6Iv3Xzt+OhmpfAYnnfD/65oU75l2lY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIY2tm00x2uq7Idudy4Er3V7GfTVv3fhVhfl+pYyr8bq5W pza3qkdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCKGLxl+s31SeLyG/9XPMqFv fiJi1exiV39eiVXKW6lf2sfdpMtVxMjwtiuhyFi/YVq8kULm6uyOFvOWV5/mLosszbCbJ/pM350 PAA== X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329093356.276289-6-ardb+git@google.com> Subject: [PATCH 1/3] kallsyms: Avoid weak references for kallsyms symbols From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , Martin KaFai Lau , linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org, Nick Desaulniers , Kees Cook From: Ard Biesheuvel kallsyms is a directory of all the symbols in the vmlinux binary, and so creating it is somewhat of a chicken-and-egg problem, as its non-zero size affects the layout of the binary, and therefore the values of the symbols. For this reason, the kernel is linked more than once, and the first pass does not include any kallsyms data at all. For the linker to accept this, the symbol declarations describing the kallsyms metadata are emitted as having weak linkage, so they can remain unsatisfied. During the subsequent passes, the weak references are satisfied by the kallsyms metadata that was constructed based on information gathered from the preceding passes. Weak references lead to somewhat worse codegen, because taking their address may need to produce NULL (if the reference was unsatisfied), and this is not usually supported by RIP or PC relative symbol references. Given that these references are ultimately always satisfied in the final link, let's drop the weak annotation, and instead, provide fallback definitions in the linker script that are only emitted if an unsatisfied reference exists. While at it, drop the FRV specific annotation that these symbols reside in .rodata - FRV is long gone. Tested-by: Nick Desaulniers # Boot Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Link: https://lkml.kernel.org/r/20230504174320.3930345-1-ardb%40kernel.org Signed-off-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 19 +++++++++++++ kernel/kallsyms.c | 6 ---- kernel/kallsyms_internal.h | 30 ++++++++------------ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index f7749d0f2562..e8449be62058 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -448,11 +448,30 @@ #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.c b/kernel/kallsyms.c index 18edd57b5fe8..22ea19a36e6e 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -325,12 +325,6 @@ static unsigned long get_symbol_pos(unsigned long addr, unsigned long symbol_start = 0, symbol_end = 0; unsigned long i, low, high, mid; - /* This kernel should never had been booted. */ - if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE)) - BUG_ON(!kallsyms_addresses); - else - BUG_ON(!kallsyms_offsets); - /* Do a binary search on the sorted kallsyms_addresses array. */ low = 0; high = kallsyms_num_syms; diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h index 27fabdcc40f5..85480274fc8f 100644 --- a/kernel/kallsyms_internal.h +++ b/kernel/kallsyms_internal.h @@ -5,27 +5,21 @@ #include /* - * These will be re-linked against their real values - * during the second link stage. + * 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[] __weak; -extern const int kallsyms_offsets[] __weak; -extern const u8 kallsyms_names[] __weak; +extern const unsigned long kallsyms_addresses[]; +extern const int kallsyms_offsets[]; +extern const u8 kallsyms_names[]; -/* - * Tell the compiler that the count isn't in the small data section if the arch - * has one (eg: FRV). - */ -extern const unsigned int kallsyms_num_syms -__section(".rodata") __attribute__((weak)); - -extern const unsigned long kallsyms_relative_base -__section(".rodata") __attribute__((weak)); +extern const unsigned int kallsyms_num_syms; +extern const unsigned long kallsyms_relative_base; -extern const char kallsyms_token_table[] __weak; -extern const u16 kallsyms_token_index[] __weak; +extern const char kallsyms_token_table[]; +extern const u16 kallsyms_token_index[]; -extern const unsigned int kallsyms_markers[] __weak; -extern const u8 kallsyms_seqs_of_names[] __weak; +extern const unsigned int kallsyms_markers[]; +extern const u8 kallsyms_seqs_of_names[]; #endif // LINUX_KALLSYMS_INTERNAL_H_ From patchwork Fri Mar 29 09:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13610490 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 158124F20C for ; Fri, 29 Mar 2024 09:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704857; cv=none; b=GoT1L+0KPh9wpVuofOVg19zlheRCnMbmCrGvwzpUNIPGSAeswuLzENCeNtebLqqeNBcdVQZFBW78uTFR0iV2G7BsaNxpupnlOY2SeliGaKQ/V1gBO+GSVMkV4JtDmw4G1tUaohVpssZEx8jXo7+u66an/Y/2Yjg2dEqFgRW7E/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704857; c=relaxed/simple; bh=ne1nIh0Qwrvg61AZAr4OTz8Z0LGxASlvMGm2cM6SR1I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KcQ47tBvL4L3pGxzOFvQHf5sZEFaYNnW2+4NmyqJ9vNVoOQkKQhDqdVIAjfX2vTfX0aKpbsLcqqpDUXr4T7JKA6NyEH+8qpAeghcVDicA6uWDovlvESj+zV3wT9pNbsTye0X1n1czmsSlg3KQBx04vUiAaLSTo/rZ9xKaVBB66E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Dlk4AmJd; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dlk4AmJd" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-40e4478a3afso9405245e9.1 for ; Fri, 29 Mar 2024 02:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711704854; x=1712309654; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=24D5emD5FgWK1X1kR0N5gec4wW0lY0v4XxqAgq53xkE=; b=Dlk4AmJdYHMZwZboC4rO5mMhtdndQIzNjUynYqSw3qMVV3d1PLIvcP9cxXDWGkDXaO dpo8wsza87cWt270/bZYj7vxmUUZNM2fhP/IxJENaV5SRhPMjcGsuH4zaWRDzG50qe9A fjk1cUW1XL6FmG/7E8J+tUbnyC6DFS7D11XBQvG2deoo5Qjd13R8OEJ1vrFVg5DLLmT0 WZGUVViY0cD7NQiCuYqLaC0HA7y50yt+PrdSpGD+TYm31SJqcRyOAGHYW6dPCscaaWt2 d/tPoavHG6vSUhWfQjlZ/wTk72ii+asGCdLl0UfCUwxXlI9EdRxzUP+yDA58wiXSnTqm c6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711704854; x=1712309654; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=24D5emD5FgWK1X1kR0N5gec4wW0lY0v4XxqAgq53xkE=; b=dQ2iM9tCpvbSvCM/PT1pjVYBjUiik1Lvlet1VuIr6U9isSgW1JFxspeU4f/qyuwg6f oZGlwjeBdAb/uhimR19A1mCVSEHjH6jpyZhBO1jb+ajlldMlwizHRgQmWXYQs8vPxocI 5z0/Wd/M8JZ/HOAaLx7DylSxKYOBaxBsGXrNH9nSAg5IPBiDgIxG9mnH2hh9c/1jBTzZ L5bC7KEsio1K4MO+MfmZnjlLDzy9C+M8xv1iMaPwX22wd6g0J3eUX6T0o7CuWSU3xouc bEd+fCH//VjwGf1UeKtREBgm9zhBjzGy5q7opw/+sd6uRBjrA0tvyRuHYo4aHLI+1Mqk jNIg== X-Forwarded-Encrypted: i=1; AJvYcCXzwFmhMu+699uBePao18v3dbOgoO+Bp9Ey2+I/N52vDPKz4sbcf0F0GLeF5uJMsu6XdySmAzpo0OnxPFCPciD90E7W X-Gm-Message-State: AOJu0YxVX1gl41aEClyxArnkqOPBdXZaspFnk3Se+e2Yz426aJxY67+O f8LWmICUGimOKRzWTK1awSg4RPLaTeIHaax0srD6L44bovih87cHxjVwkIUGOjcocA18yA== X-Google-Smtp-Source: AGHT+IERC/xlx8lH+yq6bq8yyIt9cEBvXeqlbzaAJ1b5JFraFrYGAoAaIl2LTkJk5C+U336G9ed99TBB X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:5114:b0:413:f62a:aaf8 with SMTP id o20-20020a05600c511400b00413f62aaaf8mr58714wms.4.1711704854514; Fri, 29 Mar 2024 02:34:14 -0700 (PDT) Date: Fri, 29 Mar 2024 10:33:59 +0100 In-Reply-To: <20240329093356.276289-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329093356.276289-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1618; i=ardb@kernel.org; h=from:subject; bh=ORZChgCpQukYWaId1hq+FAluQSgY7FsL4Hz5iVd1jE8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIY2tm51pL9M1t7Sty6RbsvftP5R05JPTl/bSvhflPYdjj uy5XCjfUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZSc4CRYQJjuz+PZ9rFEKu2 +t2GcpNi7xqs4OGL4PA34HglprvnEsM/hY23dhiJF2lWfq2SYn16s9jzF3vsjmqBE99mHezX/3m BGwA= X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329093356.276289-7-ardb+git@google.com> Subject: [PATCH 2/3] vmlinux: Avoid weak reference to notes section From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , Martin KaFai Lau , linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org From: Ard Biesheuvel Weak references are references that are permitted to remain unsatisfied in the final link. This means they cannot be implemented using place relative relocations, resulting in GOT entries when using position independent code generation. The notes section should always exist, so the weak annotations can be omitted. Signed-off-by: Ard Biesheuvel --- kernel/ksysfs.c | 4 ++-- lib/buildid.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index 495b69a71a5d..07fb5987b42b 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -228,8 +228,8 @@ KERNEL_ATTR_RW(rcu_normal); /* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ -extern const void __start_notes __weak; -extern const void __stop_notes __weak; +extern const void __start_notes; +extern const void __stop_notes; #define notes_size (&__stop_notes - &__start_notes) static ssize_t notes_read(struct file *filp, struct kobject *kobj, diff --git a/lib/buildid.c b/lib/buildid.c index 898301b49eb6..7954dd92e36c 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -182,8 +182,8 @@ unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init; */ void __init init_vmlinux_build_id(void) { - extern const void __start_notes __weak; - extern const void __stop_notes __weak; + extern const void __start_notes; + extern const void __stop_notes; unsigned int size = &__stop_notes - &__start_notes; build_id_parse_buf(&__start_notes, vmlinux_build_id, size); From patchwork Fri Mar 29 09:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13610491 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A763B5102A for ; Fri, 29 Mar 2024 09:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704859; cv=none; b=ECA7czsI2C6taE3l+Ed3uN5kCt5SJxxVNk2jqoPVbWOEOXkvvLrYfTJDFem16FsOyEEuOurqAzv/0Dx+rqRlXpvh6JY/uv6AYKNhXgxQrMgQpO2aCrYoapVq8DrMht6biwlriyhrK/xsHcQsn9JJb8C+N/jp4euzAzNIZxqBYCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704859; c=relaxed/simple; bh=KUC09wtYmay5oVx7+9C+OUpDt1KQS0U9lKvW1u+lUzg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mwjmX8HhaIMs7y8rhtnnJR2f/2TtGcNCBRFwS59Q708/cYUc03NBKzh2E0VqE3jK97ZDFrkU9CCit6IyOyexZ1U7N687XOHTldM/Xs4c9N3huYMgNoelxZ5OPdlKXd8IW/wWfqmYfHwyz362lA8TMAs2AaFSG5fT9qMLLR1RWXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=s+I6ES4A; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s+I6ES4A" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-610b96c8ca2so34297867b3.2 for ; Fri, 29 Mar 2024 02:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711704856; x=1712309656; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dw09Gs88ogil/diQ6Vr0EqHQANsVVhIyP+7ZdKbyIx8=; b=s+I6ES4AxBivvRDaHcnmARZ5DuByeyfrx7ret5p6QdLqpF4G5hBbJD7OM6QquLzzGN nQZJnG704OtoxB/YvIv/j4LWqYHRjl3vE+bNJhD+FcyIOzq6KfNwYz8ofy3ht11skszm vJHQFbiOsYLQygbAGN5Bf0BOuzsWekUxq0idM0WfK4LE0WMbrIW7XqNc+ug7nqk8VhXo 7pxLt7sToGvZxirUO2fRPZPbUMfQsxFJPYNdMS78ORalL/uoHMZ1rdWWzh55eNKtNRws LY6mSdec3zxiLVCulWyL1FYVpMH8N+Ynj0Gqi5onHgcAiXddad9rjBZKVg/f09rA4GCK YN0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711704856; x=1712309656; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dw09Gs88ogil/diQ6Vr0EqHQANsVVhIyP+7ZdKbyIx8=; b=wdbtyBfYOJlcSrubZ2vwDzkS6tFYMEjdVWRHQH8pfzRc5JvYqLY7RuRuBv+Xikkfp6 Wj+Q91dbH4Yi8NxuDqQufWwfaDrp4ruj4wZRduqvRSzBPKvfHabgcMwV5j8+Gh5ldW8k jfe0TYQe85BFHwUeLzOHADpZNqj61TJRO10Lxe+m5aLrbitFFTGBU+QnMIb8QapimMzo 5Kws934+u8nEXqO4a3E5LBtykSZ0T2JTGryhwCWNihccmLg/GN5c44/vA7yjlu1wjLdw blbZhAx4/id/UPBpXQU0of7xvT46G8uQOaQ0FI1rqnbdMMgcK6qePR0YJaMBVD+R8hY3 kg0Q== X-Forwarded-Encrypted: i=1; AJvYcCWVyhl/WWYUmnunpOI+HnTZVWGa09l8oL6UZfjSVNe4YTvfQINQbyKPHSIjRh/vxUoiili5KVNwYN5h2O3+Im32WMlg X-Gm-Message-State: AOJu0YxVrgymLDG93daLmla3HHiR436QbEXB8KZ2XFVRwVwK9WuLLke/ 6IrOaABlWcS7pTz25dyAA4SJhBi40SdBOV48j9WGAy0NDm78nNGPzM+I2CkrET34nCvsfg== X-Google-Smtp-Source: AGHT+IHww5cAwsi1pr9pBu+czX3UmFai9nj7XcxpaVhRpi1LgYQNcAUBxrSuXEicaf9NQtedota600ow X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a0d:dd03:0:b0:611:7573:72b9 with SMTP id g3-20020a0ddd03000000b00611757372b9mr538832ywe.5.1711704856741; Fri, 29 Mar 2024 02:34:16 -0700 (PDT) Date: Fri, 29 Mar 2024 10:34:00 +0100 In-Reply-To: <20240329093356.276289-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329093356.276289-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1581; i=ardb@kernel.org; h=from:subject; bh=q5UGicb35M6dvlAOCgO0axQESJYA1rUn+GPk9ZrI1w0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIY2tm2OlVN6iHxUr9jYWMgmymJk94z0V9u5k6qIdE5rSD 26LOdPVUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbSb8fwPzp8VsaB3SU2Br47 13TyqzMf+HazQXOCcIe1VeufXy6Jrxn+Cj68+VHg2BXetLa8nEmMt64kzV5teF7ibP27fVkbfDK XsQEA X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329093356.276289-8-ardb+git@google.com> Subject: [PATCH 3/3] btf: Avoid weak external references From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , Martin KaFai Lau , linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Ard Biesheuvel If the BTF code is enabled in the build configuration, the start/stop BTF markers are guaranteed to exist in the final link but not during the first linker pass. Avoid GOT based relocations to these markers in the final executable by providing preliminary definitions that will be used by the first linker pass, and superseded by the actual definitions in the subsequent ones. Signed-off-by: Ard Biesheuvel Acked-by: Andrii Nakryiko --- include/asm-generic/vmlinux.lds.h | 2 ++ kernel/bpf/btf.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index e8449be62058..141bddb511ee 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -456,6 +456,8 @@ * independent code. */ #define PRELIMINARY_SYMBOL_DEFINITIONS \ + PROVIDE(__start_BTF = .); \ + PROVIDE(__stop_BTF = .); \ PROVIDE(kallsyms_addresses = .); \ PROVIDE(kallsyms_offsets = .); \ PROVIDE(kallsyms_names = .); \ diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 90c4a32d89ff..46a56bf067a8 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5642,8 +5642,8 @@ static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr, u32 uat return ERR_PTR(err); } -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[]; extern struct btf *btf_vmlinux; #define BPF_MAP_TYPE(_id, _ops)