This patch is the first one in the series that annotates relevant symbols across number of source files in order to expose or hide them when kernel is compiled to hide non-glibc symbols. Please note that none of this patches neither hides nor exposes any symbols. In essense it will only have an effect once we make changes to the makefile to allow compiling the kernel with most symbols hidden.
This patch adds new header - export.h - with new macros that either expose (__visibility__("default")) or hide (__visibility__("hidden")) the symbols. Please read the comments in the header file for more details. Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com> --- include/osv/export.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/osv/export.h diff --git a/include/osv/export.h b/include/osv/export.h new file mode 100644 index 00000000..605e8e10 --- /dev/null +++ b/include/osv/export.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 Waldemar Kozaczuk + * + * This work is open source software, licensed under the terms of the + * BSD license as described in the LICENSE file in the top-level directory. + */ + +#ifndef EXPORT_H +#define EXPORT_H + +// +// Please note that the macros below are used in the source files and +// are intended to expose the annotated symbols as public when the kernel +// files are compiled with the flag '-fvisibility=hidden'. When the kernel +// is compiled without visibility flag, these macro do not have any affect +// as all symbols in this case are exposed as public. So either way, the symbols +// annotated with these macros yield desired effect. +// We do not really need to define a macro for each Linux glibc library and we could +// have had single OSV_GLIBC_API macro instead of eight ones below. However by +// having a macro for each shared library file where a symbol is part of, +// we automatically self-document the code and in future could auto-generate some +// docs. +// More specifically, as an example, if given symbol is annotated with OSV_LIBC_API, it means +// that it physically part of the libc.so.6 file on Linux, etc. +#define OSV_LIBAIO_API __attribute__((__visibility__("default"))) +#define OSV_LIBC_API __attribute__((__visibility__("default"))) +#define OSV_LIBM_API __attribute__((__visibility__("default"))) +#define OSV_LIBBSD_API __attribute__((__visibility__("default"))) +#define OSV_LIBPTHREAD_API __attribute__((__visibility__("default"))) +#define OSV_LIBUTIL_API __attribute__((__visibility__("default"))) +#define OSV_LIBXENSTORE_API __attribute__((__visibility__("default"))) +#define OSV_LD_LINUX_x86_64_API __attribute__((__visibility__("default"))) + +// In some very few cases, when source files are compiled without visibility +// flag in order to expose most symbols in the corresponding file, there are some specific +// symbols in the same file that we want to hide and this is where we use this macro. +// Regardless if we hide most symbols in the kernel or not, the annotated symbols would +// be always hidden. +#define OSV_HIDDEN __attribute__((__visibility__("hidden"))) + +#endif /* EXPORT_H */ -- 2.31.1 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20211126205255.48031-2-jwkozaczuk%40gmail.com.