Skip to contentSkip to conversation

libbpf: Per-symbol visibility for DSO

PATCH Applied Andrey Ignatov 2 participants 2 messages Oct 16, 2018 – Oct 17, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Per-symbol visibility for DSO

Make global symbols in libbpf DSO hidden by default with -fvisibility=hidden and export symbols that are part of ABI explicitly with __attribute__((visibility("default"))).

This is common practice that should prevent from accidentally exporting a symbol, that is not supposed to be a part of ABI what, in turn, improves both libbpf developer- and user-experiences. See [1] for more details.

Export control becomes more important since more and more projects use libbpf.

The patch doesn't export a bunch of netlink related functions since as agreed in [2] they'll be reworked. That doesn't break bpftool since bpftool links libbpf statically.

[1] https://www.akkadia.org/drepper/dsohowto.pdf (2.2 Export Control)
[2] https://www.mail-archive.com/[email protected]/msg251434.html

---
 tools/lib/bpf/Makefile |   1 +
 tools/lib/bpf/bpf.h    | 118 ++++++++++++++------------
 tools/lib/bpf/btf.h    |  22 +++--
 tools/lib/bpf/libbpf.h | 186 ++++++++++++++++++++++-------------------
 4 files changed, 179 insertions(+), 148 deletions(-)
tools/lib/bpf/Makefile +1 -0
index 79d84413ddf2..425b480bda75 100644
@@ -125,6 +125,7 @@ override CFLAGS += $(EXTRA_WARNINGS)
 override CFLAGS += -Werror -Wall
 override CFLAGS += -fPIC
 override CFLAGS += $(INCLUDES)
+override CFLAGS += -fvisibility=hidden
 
 ifeq ($(VERBOSE),1)
   Q =
tools/lib/bpf/bpf.h +65 -53

136 lines not on this page · raw message

tools/lib/bpf/btf.h +14 -8
index 6db5462bb2ef..b77e7080f7e7 100644
@@ -6,6 +6,10 @@
 
 #include <linux/types.h>
 
+#ifndef LIBBPF_API
+#define LIBBPF_API __attribute__((visibility("default")))
+#endif
+
 #define BTF_ELF_SEC ".BTF"
 
 struct btf;
@@ -14,13 +18,15 @@ struct btf_type;
 typedef int (*btf_print_fn_t)(const char *, ...)
 	__attribute__((format(printf, 1, 2)));
 
-void btf__free(struct btf *btf);
-struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
-__s32 btf__find_by_name(const struct btf *btf, const char *type_name);
-const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 id);
-__s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
-int btf__resolve_type(const struct btf *btf, __u32 type_id);
-int btf__fd(const struct btf *btf);
-const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
+LIBBPF_API void btf__free(struct btf *btf);
+LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
+LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
+				   const char *type_name);
+LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
+						  __u32 id);
+LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
+LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
+LIBBPF_API int btf__fd(const struct btf *btf);
+LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
 
 #endif /* __LIBBPF_BTF_H */
tools/lib/bpf/libbpf.h +99 -87

283 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 12 lines · Andrey Ignatov

Make global symbols in libbpf DSO hidden by default with -fvisibility=hidden and export symbols that are part of ABI explicitly with __attribute__((visibility("default"))).

This is common practice that should prevent from accidentally exporting a symbol, that is not supposed to be a part of ABI what, in turn, improves both libbpf developer- and user-experiences. See [1] for more details.

Export control becomes more important since more and more projects use libbpf.

Quoted 8 lines

The patch doesn't export a bunch of netlink related functions since as agreed in [2] they'll be reworked. That doesn't break bpftool since bpftool links libbpf statically.

[1] https://www.akkadia.org/drepper/dsohowto.pdf (2.2 Export Control)
[2] https://www.mail-archive.com/[email protected]/msg251434.html

Applied, Thanks