From: Christian Brauner Date: Fri, 17 Jul 2020 20:50:51 +0000 (+0200) Subject: compiler: add and use __hidden visbility X-Git-Tag: lxc-5.0.0~388^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6822ba9be9b9d43b14298db082c3372f045b8527;p=thirdparty%2Flxc.git compiler: add and use __hidden visbility Closes: #3485. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 473bca5c1..10ef721e4 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -217,7 +217,6 @@ AM_CFLAGS = -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \ -I $(top_srcdir)/src/lxc \ -I $(top_srcdir)/src/lxc/storage \ -I $(top_srcdir)/src/lxc/cgroups - if ENABLE_APPARMOR AM_CFLAGS += -DHAVE_APPARMOR endif @@ -409,6 +408,7 @@ lxc_user_nic_SOURCES = cmd/lxc_user_nic.c \ log.c log.h \ memory_utils.h \ network.c network.h \ + nl.c nl.h \ parse.c parse.h \ process_utils.c process_utils.h \ syscall_numbers.h \ diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c index 4160565f3..06f195a37 100644 --- a/src/lxc/cmd/lxc_user_nic.c +++ b/src/lxc/cmd/lxc_user_nic.c @@ -35,6 +35,7 @@ #include "log.h" #include "memory_utils.h" #include "network.h" +#include "nl.h" #include "parse.h" #include "process_utils.h" #include "string_utils.h" diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h index 114fb81ba..1852f1c0a 100644 --- a/src/lxc/compiler.h +++ b/src/lxc/compiler.h @@ -75,4 +75,8 @@ #endif #endif +#ifndef __hidden +#define __hidden __attribute__((visibility("hidden"))) +#endif + #endif /* __LXC_COMPILER_H */ diff --git a/src/lxc/nl.c b/src/lxc/nl.c index dd94c09c8..81e9cbab4 100644 --- a/src/lxc/nl.c +++ b/src/lxc/nl.c @@ -19,7 +19,7 @@ lxc_log_define(nl, lxc); -size_t nlmsg_len(const struct nlmsg *nlmsg) +static size_t nlmsg_len(const struct nlmsg *nlmsg) { return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN; } diff --git a/src/lxc/nl.h b/src/lxc/nl.h index 7301ccf57..ab8368fe6 100644 --- a/src/lxc/nl.h +++ b/src/lxc/nl.h @@ -5,6 +5,7 @@ #include +#include "compiler.h" #include "memory_utils.h" /* @@ -59,7 +60,7 @@ struct nlmsg { * * Return 0 on success, < 0 otherwise */ -int netlink_open(struct nl_handler *handler, int protocol); +__hidden extern int netlink_open(struct nl_handler *handler, int protocol); /* * netlink_close : close a netlink socket, after this call, @@ -67,7 +68,7 @@ int netlink_open(struct nl_handler *handler, int protocol); * * @handler: a handler to the netlink socket */ -void netlink_close(struct nl_handler *handler); +__hidden extern void netlink_close(struct nl_handler *handler); define_cleanup_function(struct nl_handler *, netlink_close); /* @@ -80,8 +81,8 @@ define_cleanup_function(struct nl_handler *, netlink_close); * * Returns 0 on success, < 0 otherwise */ -int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg); -int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg); +__hidden extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg); +__hidden extern int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg); /* * netlink_send: send a netlink message to the kernel. It is up @@ -92,8 +93,8 @@ int __netlink_recv(struct nl_handler *handler, struct nlmsghdr *nlmsg); * * Returns 0 on success, < 0 otherwise */ -int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg); -int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg); +__hidden extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg); +__hidden extern int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg); /* * netlink_transaction: send a request to the kernel and read the response. @@ -106,10 +107,10 @@ int __netlink_send(struct nl_handler *handler, struct nlmsghdr *nlmsg); * * Returns 0 on success, < 0 otherwise */ -int netlink_transaction(struct nl_handler *handler, - struct nlmsg *request, struct nlmsg *answer); -int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request, - struct nlmsghdr *answer); +__hidden extern int netlink_transaction(struct nl_handler *handler, struct nlmsg *request, + struct nlmsg *answer); +__hidden extern int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request, + struct nlmsghdr *answer); /* * nla_put_string: copy a null terminated string to a netlink message @@ -121,7 +122,7 @@ int __netlink_transaction(struct nl_handler *handler, struct nlmsghdr *request, * * Returns 0 on success, < 0 otherwise */ -int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string); +__hidden int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string); /* * nla_put_buffer: copy a buffer with a specified size to a netlink @@ -178,7 +179,7 @@ int nla_put_attr(struct nlmsg *nlmsg, int attr); * Returns current nested pointer to be reused * to nla_end_nested. */ -struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr); +__hidden extern struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr); /* * nla_end_nested: end the nesting attribute @@ -188,7 +189,7 @@ struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr); * * Returns the current */ -void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); +__hidden extern void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); /* * nlmsg_allocate : allocate a netlink message. The netlink format message @@ -205,7 +206,7 @@ void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr); * * Returns a pointer to the newly allocated netlink message, NULL otherwise */ -struct nlmsg *nlmsg_alloc(size_t size); +__hidden extern struct nlmsg *nlmsg_alloc(size_t size); /* * nlmsg_alloc_reserve: like nlmsg_alloc(), but reserve the whole payload @@ -214,7 +215,7 @@ struct nlmsg *nlmsg_alloc(size_t size); * * @size: the capacity of the payload to be allocated. */ -struct nlmsg *nlmsg_alloc_reserve(size_t size); +__hidden extern struct nlmsg *nlmsg_alloc_reserve(size_t size); /* * Reserve room for additional data at the tail of a netlink message @@ -224,14 +225,14 @@ struct nlmsg *nlmsg_alloc_reserve(size_t size); * * Returns a pointer to newly reserved room or NULL */ -void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len); +__hidden extern void *nlmsg_reserve(struct nlmsg *nlmsg, size_t len); /* * nlmsg_free : free a previously allocate message * * @nlmsg: the netlink message to be freed */ -void nlmsg_free(struct nlmsg *nlmsg); +__hidden extern void nlmsg_free(struct nlmsg *nlmsg); define_cleanup_function(struct nlmsg *, nlmsg_free); /* @@ -241,9 +242,9 @@ define_cleanup_function(struct nlmsg *, nlmsg_free); * * Returns a pointer to the netlink data or NULL if there is no data */ -void *nlmsg_data(struct nlmsg *nlmsg); +__hidden extern void *nlmsg_data(struct nlmsg *nlmsg); -extern int addattr(struct nlmsghdr *n, size_t maxlen, int type, - const void *data, size_t alen); +__hidden extern int addattr(struct nlmsghdr *n, size_t maxlen, int type, + const void *data, size_t alen); #endif diff --git a/src/lxc/rtnl.c b/src/lxc/rtnl.c index 0712594d1..cea7336c1 100644 --- a/src/lxc/rtnl.c +++ b/src/lxc/rtnl.c @@ -16,12 +16,12 @@ #include "nl.h" #include "rtnl.h" -extern int rtnetlink_open(struct rtnl_handler *handler) +int rtnetlink_open(struct rtnl_handler *handler) { return netlink_open(&handler->nlh, NETLINK_ROUTE); } -extern void rtnetlink_close(struct rtnl_handler *handler) +void rtnetlink_close(struct rtnl_handler *handler) { netlink_close(&handler->nlh); } @@ -29,20 +29,19 @@ extern void rtnetlink_close(struct rtnl_handler *handler) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" -extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) +int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) { return netlink_rcv(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr); } -extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) +int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg) { return netlink_send(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr); } -extern int rtnetlink_transaction(struct rtnl_handler *handler, - struct rtnlmsg *request, - struct rtnlmsg *answer) +int rtnetlink_transaction(struct rtnl_handler *handler, struct rtnlmsg *request, + struct rtnlmsg *answer) { return netlink_transaction(&handler->nlh, (struct nlmsg *)&request->nlmsghdr, @@ -51,7 +50,7 @@ extern int rtnetlink_transaction(struct rtnl_handler *handler, #pragma GCC diagnostic pop -extern struct rtnlmsg *rtnlmsg_alloc(size_t size) +struct rtnlmsg *rtnlmsg_alloc(size_t size) { /* size_t len; @@ -63,4 +62,4 @@ extern struct rtnlmsg *rtnlmsg_alloc(size_t size) return NULL; } -extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg) { free(rtnlmsg); } +void rtnlmsg_free(struct rtnlmsg *rtnlmsg) { free(rtnlmsg); } diff --git a/src/lxc/rtnl.h b/src/lxc/rtnl.h index 66ce6bdd5..bfe66db05 100644 --- a/src/lxc/rtnl.h +++ b/src/lxc/rtnl.h @@ -3,6 +3,8 @@ #ifndef __LXC_RTNL_H #define __LXC_RTNL_H +#include + /* * Use this as a good size to allocate route netlink messages */ @@ -38,14 +40,14 @@ struct rtnlmsg { * * Returns 0 on success, < 0 otherwise */ -extern int rtnetlink_open(struct rtnl_handler *handler); +__hidden extern int rtnetlink_open(struct rtnl_handler *handler); /* * genetlink_close : close a route netlink socket * * @handler: the handler of the socket to be closed */ -extern void rtnetlink_close(struct rtnl_handler *handler); +__hidden extern void rtnetlink_close(struct rtnl_handler *handler); /* * rtnetlink_rcv : receive a route netlink socket, it is up @@ -56,7 +58,7 @@ extern void rtnetlink_close(struct rtnl_handler *handler); * * Returns 0 on success, < 0 otherwise */ -extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); +__hidden extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); /* * rtnetlink_send : send a route netlink socket, it is up @@ -67,12 +69,11 @@ extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); * * Returns 0 on success, < 0 otherwise */ -extern int rtnetlink_send(struct rtnl_handler *handler, - struct rtnlmsg *rtnlmsg); +__hidden extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg); -struct genlmsg *genlmsg_alloc(size_t size); +__hidden struct genlmsg *genlmsg_alloc(size_t size); -extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg); +__hidden extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg); /* * rtnetlink_transaction : send and receive a route netlink message in one shot @@ -83,8 +84,9 @@ extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg); * * Returns 0 on success, < 0 otherwise */ -extern int rtnetlink_transaction(struct rtnl_handler *handler, - struct rtnlmsg *request, - struct rtnlmsg *answer); +__hidden extern int rtnetlink_transaction(struct rtnl_handler *handler, struct rtnlmsg *request, + struct rtnlmsg *answer); + +__hidden struct rtnlmsg *rtnlmsg_alloc(size_t size); #endif /* __LXC_RTNL_H */