bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
	<daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>, Yonghong Song <yhs@fb.com>
Subject: [PATCH v3 bpf-next 03/18] libbpf: suppress compiler warning when using SEC() macro with externs
Date: Fri, 23 Apr 2021 11:13:33 -0700	[thread overview]
Message-ID: <20210423181348.1801389-4-andrii@kernel.org> (raw)
In-Reply-To: <20210423181348.1801389-1-andrii@kernel.org>

When used on externs SEC() macro will trigger compilation warning about
inapplicable `__attribute__((used))`. That's expected for extern declarations,
so suppress it with the corresponding _Pragma.

Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/bpf_helpers.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index b904128626c2..75c7581b304c 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -25,9 +25,16 @@
 /*
  * Helper macro to place programs, maps, license in
  * different sections in elf_bpf file. Section names
- * are interpreted by elf_bpf loader
+ * are interpreted by libbpf depending on the context (BPF programs, BPF maps,
+ * extern variables, etc).
+ * To allow use of SEC() with externs (e.g., for extern .maps declarations),
+ * make sure __attribute__((unused)) doesn't trigger compilation warning.
  */
-#define SEC(NAME) __attribute__((section(NAME), used))
+#define SEC(name) \
+	_Pragma("GCC diagnostic push")					    \
+	_Pragma("GCC diagnostic ignored \"-Wignored-attributes\"")	    \
+	__attribute__((section(name), used))				    \
+	_Pragma("GCC diagnostic pop")					    \
 
 /* Avoid 'linux/stddef.h' definition of '__always_inline'. */
 #undef __always_inline
-- 
2.30.2


  parent reply	other threads:[~2021-04-23 18:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 18:13 [PATCH v3 bpf-next 00/18] BPF static linker: support externs Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 01/18] bpftool: support dumping BTF VAR's "extern" linkage Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 02/18] bpftool: dump more info about DATASEC members Andrii Nakryiko
2021-04-23 18:13 ` Andrii Nakryiko [this message]
2021-04-23 18:13 ` [PATCH v3 bpf-next 04/18] libbpf: mark BPF subprogs with hidden visibility as static for BPF verifier Andrii Nakryiko
2021-04-23 18:23   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 05/18] libbpf: allow gaps in BPF program sections to support overriden weak functions Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 06/18] libbpf: refactor BTF map definition parsing Andrii Nakryiko
2021-04-23 18:36   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 07/18] libbpf: factor out symtab and relos sanity checks Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 08/18] libbpf: make few internal helpers available outside of libbpf.c Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 09/18] libbpf: extend sanity checking ELF symbols with externs validation Andrii Nakryiko
2021-04-23 18:39   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 10/18] libbpf: tighten BTF type ID rewriting with error checking Andrii Nakryiko
2021-04-23 18:40   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 11/18] libbpf: add linker extern resolution support for functions and global variables Andrii Nakryiko
2021-04-23 18:46   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 12/18] libbpf: support extern resolution for BTF-defined maps in .maps section Andrii Nakryiko
2021-04-23 18:49   ` Yonghong Song
2021-04-23 18:13 ` [PATCH v3 bpf-next 13/18] selftests/bpf: use -O0 instead of -Og in selftests builds Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 14/18] selftests/bpf: omit skeleton generation for multi-linked BPF object files Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 15/18] selftests/bpf: add function linking selftest Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 16/18] selftests/bpf: add global variables " Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 17/18] selftests/bpf: add map " Andrii Nakryiko
2021-04-23 18:53   ` Yonghong Song
2021-04-23 21:23     ` Alexei Starovoitov
2021-04-23 21:39       ` Andrii Nakryiko
2021-04-23 18:13 ` [PATCH v3 bpf-next 18/18] selftests/bpf: document latest Clang fix expectations for linking tests Andrii Nakryiko
2021-04-23 18:51   ` Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210423181348.1801389-4-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).