rename SEC() to SECTION()
The only purpose of this is to break cut-and-paste of examples
that use SEC() causing people to think things through, look
at Android bpf program examples and use a better macro.
In particular programs with SEC("license") / SEC("maps") need to be
changed to use LICENSE("license") and the map helpers or the map
section is wrong and cannot be correctly parsed by the bpfloader.
Generated via:
git grep 'SEC\(' | cut -d: -f1-2 | while read i; do mcedit $i; done
and manually editting found locations
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idb333967e054e096fe74f910a5f8aaf1d6c5dc81
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index b7f38ce..529c69c 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -81,10 +81,13 @@
/*
* Map section name prefixes to program types, the section name will be:
- * SEC(<prefix>/<name-of-program>)
+ * SECTION(<prefix>/<name-of-program>)
* For example:
- * SEC("tracepoint/sched_switch_func") where sched_switch_funcs
+ * SECTION("tracepoint/sched_switch_func") where sched_switch_funcs
* is the name of the program, and tracepoint is the type.
+ *
+ * However, be aware that you should not be directly using the SECTION() macro.
+ * Instead use the DEFINE_(BPF|XDP)_(PROG|MAP)... & LICENSE/CRITICAL macros.
*/
sectionType sectionNameTypes[] = {
{"kprobe", BPF_PROG_TYPE_KPROBE},
diff --git a/progs/include/bpf_helpers.h b/progs/include/bpf_helpers.h
index abd19c6..97cb012 100644
--- a/progs/include/bpf_helpers.h
+++ b/progs/include/bpf_helpers.h
@@ -12,7 +12,7 @@
* *
* THIS WILL LIKELY RESULT IN BRICKED DEVICES AT SOME ARBITRARY FUTURE TIME *
* *
- * THAT GOES ESPECIALLY FOR THE 'SEC' 'LICENSE' AND 'CRITICAL' MACRO DEFINES *
+ * THAT GOES ESPECIALLY FOR THE 'SECTION' 'LICENSE' AND 'CRITICAL' MACROS *
* *
* We strongly suggest that if you need changes to bpfloader functionality *
* you get your changes reviewed and accepted into aosp/master. *
@@ -20,7 +20,7 @@
******************************************************************************/
/* place things in different elf sections */
-#define SEC(NAME) __attribute__((section(NAME), used))
+#define SECTION(NAME) __attribute__((section(NAME), used))
/* Must be present in every program, example usage:
* LICENSE("GPL"); or LICENSE("Apache 2.0");
@@ -41,18 +41,18 @@
* If missing, bpfloader_{min/max}_ver default to 0/0x10000 ie. [v0.0, v1.0),
* while size_of_bpf_{map/prog}_def default to 32/20 which are the v0.0 sizes.
*/
-#define LICENSE(NAME) \
- unsigned int _bpfloader_min_ver SEC("bpfloader_min_ver") = DEFAULT_BPFLOADER_MIN_VER; \
- unsigned int _bpfloader_max_ver SEC("bpfloader_max_ver") = DEFAULT_BPFLOADER_MAX_VER; \
- size_t _size_of_bpf_map_def SEC("size_of_bpf_map_def") = sizeof(struct bpf_map_def); \
- size_t _size_of_bpf_prog_def SEC("size_of_bpf_prog_def") = sizeof(struct bpf_prog_def); \
- char _license[] SEC("license") = (NAME)
+#define LICENSE(NAME) \
+ unsigned int _bpfloader_min_ver SECTION("bpfloader_min_ver") = DEFAULT_BPFLOADER_MIN_VER; \
+ unsigned int _bpfloader_max_ver SECTION("bpfloader_max_ver") = DEFAULT_BPFLOADER_MAX_VER; \
+ size_t _size_of_bpf_map_def SECTION("size_of_bpf_map_def") = sizeof(struct bpf_map_def); \
+ size_t _size_of_bpf_prog_def SECTION("size_of_bpf_prog_def") = sizeof(struct bpf_prog_def); \
+ char _license[] SECTION("license") = (NAME)
/* flag the resulting bpf .o file as critical to system functionality,
* loading all kernel version appropriate programs in it must succeed
* for bpfloader success
*/
-#define CRITICAL(REASON) char _critical[] SEC("critical") = (REASON)
+#define CRITICAL(REASON) char _critical[] SECTION("critical") = (REASON)
/*
* Helper functions called from eBPF programs written in C. These are
@@ -103,7 +103,7 @@
/* type safe macro to declare a map and related accessor functions */
#define DEFINE_BPF_MAP_UGM(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries, usr, grp, md) \
- const struct bpf_map_def SEC("maps") the_map = { \
+ const struct bpf_map_def SECTION("maps") the_map = { \
.type = BPF_MAP_TYPE_##TYPE, \
.key_size = sizeof(TypeOfKey), \
.value_size = sizeof(TypeOfValue), \
@@ -155,7 +155,7 @@
#define DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \
opt) \
- const struct bpf_prog_def SEC("progs") the_prog##_def = { \
+ const struct bpf_prog_def SECTION("progs") the_prog##_def = { \
.uid = (prog_uid), \
.gid = (prog_gid), \
.min_kver = (min_kv), \
@@ -164,7 +164,7 @@
.bpfloader_min_ver = DEFAULT_BPFLOADER_MIN_VER, \
.bpfloader_max_ver = DEFAULT_BPFLOADER_MAX_VER, \
}; \
- SEC(SECTION_NAME) \
+ SECTION(SECTION_NAME) \
int the_prog
// Programs (here used in the sense of functions/sections) marked optional are allowed to fail
diff --git a/progs/include/bpf_map_def.h b/progs/include/bpf_map_def.h
index 647c813..02b2096 100644
--- a/progs/include/bpf_map_def.h
+++ b/progs/include/bpf_map_def.h
@@ -116,10 +116,10 @@
* uses this structure from eBPF object to create maps at boot time.
*
* The eBPF C program should define structure in the maps section using
- * SEC("maps") otherwise it will be ignored by the eBPF loader.
+ * SECTION("maps") otherwise it will be ignored by the eBPF loader.
*
* For example:
- * const struct bpf_map_def SEC("maps") mymap { .type=... , .key_size=... }
+ * const struct bpf_map_def SECTION("maps") mymap { .type=... , .key_size=... }
*
* See 'bpf_helpers.h' for helpful macros for eBPF program use.
*/
diff --git a/progs/include/test/mock_bpf_helpers.h b/progs/include/test/mock_bpf_helpers.h
index ffe8951..e6ffaa9 100644
--- a/progs/include/test/mock_bpf_helpers.h
+++ b/progs/include/test/mock_bpf_helpers.h
@@ -86,7 +86,7 @@
#endif
/* place things in different elf sections */
-#define SEC(NAME) __attribute__((section(NAME), used))
+#define SECTION(NAME) __attribute__((section(NAME), used))
/* Example use: LICENSE("GPL"); or LICENSE("Apache 2.0"); */
-#define LICENSE(NAME) char _license[] SEC("license") = (NAME)
+#define LICENSE(NAME) char _license[] SECTION("license") = (NAME)