Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2051846lqe; Tue, 9 Apr 2024 08:15:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVy+2ezsU4A6eA3Q7wadmaHyilDaGYZUdtmBmGZaQ2Q7/weh6zRMEMD1+S3dj1PUVLg3hzLHdbwt93qBIiNG2AmmWatt+TtXgzHV/5OGQ== X-Google-Smtp-Source: AGHT+IHd11vs2oBMebXSF2J38GPI23QGB3VYs0ysaE/0AH8y56wlXjj4b2s/RHUa7vLeZHvNCgG3 X-Received: by 2002:a05:6359:14cb:b0:183:fb08:7fcf with SMTP id lz11-20020a05635914cb00b00183fb087fcfmr190086rwb.7.1712675730872; Tue, 09 Apr 2024 08:15:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712675730; cv=pass; d=google.com; s=arc-20160816; b=kew5yFE1FyugaaiWSCzYQ2lpSSIfeGbdAnaxRSmZw6hECJQlnea+ZB7YZCM5b19Vd9 DnxjXcDNq+83qAW6CZDZ1tRTfJauRODJU4CqPKQ0zihsqP1SOSPfwOYNLYH1QrRYAqiz ulLF9IchyiU+6B0WtV9+CZrb2VYm2Bq+ckoMFW3wCu+49kN8HTwRXPWjfIKwNlIMa+RR VUO6qcj+ml9rsasZT/bQ6gfFXZN56e4x7CDx1CYpvxFxcnLcOfoxpu1s8VaqfvfwJRuv yNxHOcnA4+AEC3gS09KSbmZCixlb4m9H6tPF04zo2o61RRGTmqSaFQicDtdgMfBL8DRr A6GA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=+c7Nae7lWjUxFMlj/H2Ns6fhkmPqVh4ydm9u7CZiONI=; fh=MaAnUuq8iqXPiTVvqFB8Yae/m/Oex4hVT+gabuDSVzA=; b=R+ZK1PuTv4jggGGCaz8HspcEJLZSzPaHUVTLKAS6EYmpLRjD1EP00C+BUtf8ObhCV+ 9Vu9jM6eLK8gNGXrgCbERvDbd1FMC8y84rYkDk9PRcrE/nV+pVrRWHyJz608DgePRDgN HunRV94fxLStwPPaiT5EOhODIf10xGTfOaM3U/f0C/ysk6Sc3srjFxgSjaz1G5otzJih jCh4C9VqHLE+u5faj6eOj3OicTbQcXeBRICvF5rEZa6q0b3O1ZKSRmNcVDfZKqU4Xld2 6j1ZuSY9fPS6ndAxKtL3b5woqWazoUHtNJh4RZw7XyL8CK+7QBbMK61IrWtnWgN5l3w4 3gDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Xjvwx9k3; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-137151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n66-20020a634045000000b005f07209a2efsi8523840pga.760.2024.04.09.08.15.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:15:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Xjvwx9k3; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-137151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D100128E1A6 for ; Tue, 9 Apr 2024 15:03:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D37C6136668; Tue, 9 Apr 2024 15:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xjvwx9k3" 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 D1E8F134CFE for ; Tue, 9 Apr 2024 15:01:48 +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=1712674911; cv=none; b=F5hXfJfhztOgJvELVAT/GAWYK1I0H2Wey6CPlOUeYf0ogqxGCl8q8BQdGDPdHr8EIPSB4RrfR3EAtJautq0tL5psNg55rCH0HdcDPlFz22shYCzGyX+w+1Tc4Jilot9R2i72wkZB6UjhTA8GFE+W5jwrKcfU6y3vwpeSlX71vq0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712674911; c=relaxed/simple; bh=2XRLBMqkeM5HXNl5EWou8ZB0E0TV13o8LSI5x8BSvlY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qCos7Q8O8cP6KV5brnmLaSZWPjYwn8QZUK0+21X4GaIE+DIly6kc3XGwwjst8Zp1hqtWKLAhqliFeYd11XRlXV4RBCQwG27UZr+Jr3EDyutAJfzFUa/7++MrUcoFD7F2t2rhdxymiG47KQSozZYmlZ6rtaAzX0su3oOfDTTOpww= 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=Xjvwx9k3; 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 Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4166b96002dso10630765e9.0 for ; Tue, 09 Apr 2024 08:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712674907; x=1713279707; 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=+c7Nae7lWjUxFMlj/H2Ns6fhkmPqVh4ydm9u7CZiONI=; b=Xjvwx9k3qQCxCqCPdMfNuiDIs0K/ej3onc8KTfYn8pWkSS4Ix8PnySLBwYMt+aAEh1 SEM5HwkuUPwEC3ftN0Oy07gEsbmWLfeJiIgRlLOH7x0d4mtVAyzQJDLOU8i18LT7XCHY bkwFtdSFCB/IIwPMfeJ4sk8WJ9HJ5fW+PELHzkz2BCRvaOH05GVK+gLYDJTZYha9kHz1 NDCN5F64Q2PVakeKVNLpSLHssJ9xB+pegmXosI5DAgv7USVVBmaYNZAq4Q24DNrozqJi Qt5kkFfMs/CpNDW9/gUToAkQRRnTrbsPkQ2vR2kO+Br5wSUsxVruyIMZ8CVGMoK/0XKi 10NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712674907; x=1713279707; 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=+c7Nae7lWjUxFMlj/H2Ns6fhkmPqVh4ydm9u7CZiONI=; b=GsfPADCgej8qA3IMmeDEgc7KY49xW1fKHNEJWwXBC14BziPrz00shE2gKyBttHT4fC aICffvTyac0s4cZjCZmoZANYCP7yF+5TBx52ugCazQrD+eMmyzcmqNR6fMOmD6Da3mQN HdV8c3JD34/ZXu643lyPDDjFZzhzoa8FZXPLeSzlvPiWF5kiGcmYe/F5MIke7nkMMdfu g+LXAES3a2bpKUEaZ9OmaiLfMx+fsHepZnubg920TvRsU5SM6iY824ASrZNkns1q72xw W+qyfftYhZUa8fYsQ7QSvkMzsAy8muSp3wCK1CyERDNKHQeXAAqqPexgbcayT9K4EBhR ywyQ== X-Gm-Message-State: AOJu0Yw9gUa7mAUK2yCBF2SOKqvQdti0r68YDcayX5nmiIf20DGl4PuK BGmuCY/tKz0fRWsYXaChN0SpT5iupBcIDrEjox1zBMaPITfeQR5KwlSKCCqJsCnn/wzNQj7cBDL MITbic3OUgI9uJkyqAbAAYIJvan2U0o6rFSRRUrflwTOAKfKa103tkn5i1Ym77A07YDMB4WSsww tyPUqFx+zC5EGWmQJkMCZqHoIsvENG2Q== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:3b29:b0:414:a0c:a82c with SMTP id m41-20020a05600c3b2900b004140a0ca82cmr31439wms.4.1712674907499; Tue, 09 Apr 2024 08:01:47 -0700 (PDT) Date: Tue, 9 Apr 2024 17:01:36 +0200 In-Reply-To: <20240409150132.4097042-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240409150132.4097042-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=3124; i=ardb@kernel.org; h=from:subject; bh=AkRYLBTm6VuFUE4hRnB+rntHpPOXzattnmr7pMUxTAQ=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIU00IkD3NPOKFTu0Hs7W2XPVxMPG4eyLtet0z14zVlho3 KFyPPBNRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZgINw/D/5zHBY8Yjzz8ViLP eCfHpP8DU+J8q72OZiqLNCeGfRA3es/IMIf9kPTBh1IGWxLPFGtVLXWe99aYPWVPvPNpXZv3S38 6MgIA X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240409150132.4097042-8-ardb+git@google.com> Subject: [PATCH v2 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, Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" 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. Make the preliminary definitions dependent on CONFIG_DEBUG_INFO_BTF so that inadvertent references to this section will trigger a link failure if they occur in code that does not honour CONFIG_DEBUG_INFO_BTF. Note that Clang will notice that taking the address of__start_BTF cannot yield NULL any longer, so testing for that condition is no longer needed. Acked-by: Andrii Nakryiko Signed-off-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 9 +++++++++ kernel/bpf/btf.c | 4 ++-- kernel/bpf/sysfs_btf.c | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index e8449be62058..4cb3d88449e5 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -456,6 +456,7 @@ * independent code. */ #define PRELIMINARY_SYMBOL_DEFINITIONS \ + PRELIMINARY_BTF_DEFINITIONS \ PROVIDE(kallsyms_addresses = .); \ PROVIDE(kallsyms_offsets = .); \ PROVIDE(kallsyms_names = .); \ @@ -466,6 +467,14 @@ PROVIDE(kallsyms_markers = .); \ PROVIDE(kallsyms_seqs_of_names = .); +#ifdef CONFIG_DEBUG_INFO_BTF +#define PRELIMINARY_BTF_DEFINITIONS \ + PROVIDE(__start_BTF = .); \ + PROVIDE(__stop_BTF = .); +#else +#define PRELIMINARY_BTF_DEFINITIONS +#endif + /* * Read only Data */ 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) diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c index ef6911aee3bb..fedb54c94cdb 100644 --- a/kernel/bpf/sysfs_btf.c +++ b/kernel/bpf/sysfs_btf.c @@ -9,8 +9,8 @@ #include /* See scripts/link-vmlinux.sh, gen_btf() func for details */ -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[]; static ssize_t btf_vmlinux_read(struct file *file, struct kobject *kobj, @@ -32,7 +32,7 @@ static int __init btf_vmlinux_init(void) { bin_attr_btf_vmlinux.size = __stop_BTF - __start_BTF; - if (!__start_BTF || bin_attr_btf_vmlinux.size == 0) + if (bin_attr_btf_vmlinux.size == 0) return 0; btf_kobj = kobject_create_and_add("btf", kernel_kobj); -- 2.44.0.478.gd926399ef9-goog