You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Makefile: add option to build kernel with most symbols hidden
This patch adds new build configuration option - conf_hide_symbols -
that allows to build OSv kernel with all non-glibc symbols hidden
when enabled (set to 1). By default the conf_hide_symbols is set to disabled
so the kernel is still built with all symbols exported. In order to build
kernel with most symbols hidden, one can use following command:
```
./scripts/build image=native-example fs=rofs conf_hide_symbols=1 -j$(nproc)
```
The main idea behind the changes to the makefile below, is to compile
all source files except the ones under musl/ and libc/ directories with
the special compiler flags - '-fvisibility=hidden' and
'-fvisibility-inlines-hidden' (C++ only) if conf_hide_symbols is
enabled. This makes the symbols in all those relevant files as hidden
except the ones annotated with OSV_***_API macros to expose them as
public.
On other hand, the musl sources come with its own symbol visibility
mechanism where the symbols to be hidden are annotated with the 'hidden'
macro and everything else is public. Therefore we do not need to compile
the musl files with the visibility flags. Same goes for the files under
libc/ that originate from musl.
Lastly, the C++ files under libc/ that have been written from scratch
to provide parts of glibc API (like libc/pthread.cc) are compiled with
the compatibility flags. They are part of the libc_to_hide set.
Also depending on conf_hide_symbols, the makefile uses different linker
flags to link the standard C++ and others fully or not.
Relatedly, when conf_hide_symbols is enabled, the OSv dynamic linker
(core/elf.cc) does not advertise libstdc++.so.6 anymore.
The symbol hiding mechanism enabled with conf_hide_symbols is powerful
enough to hide most non-glibc symbols and leaves under 1,700 symbols
exported including some vtable and typeinfo left C++ ones which is ~10%
of the original number. The remaining C++ symbols will be removed from symbols
table once we enable version script when linking in future patches.
With conf_hide_symbols on, the resulting kernel-stripped.elf is ~ 5.1 MB in
size, down from 6.7 MB, mainly due to libstdc++.a not linked fully. Once
we enable linker garbage collection, the size should go down even more.
Please note that the kernel with hidden symbols does not support
building ZFS images as some of the symbols libzfs.so, zfs.so and zpool.so
depend on are no longer visible. To fix this we will probably need to
change how this apps are linked so they do not depend on those symbols
exported by kernel.
In addition around 35 unit tests cannot run on the kernel with most
hidden symbols as they directly use OSv internal symbols. Finally most
OSv apps and modules like httpserver.so rely on OSv specific API symbols
and they will not work either. To address this, we will need to expose
some of the OSv C++ API as C.
It is not clear if this patch fully addresses the issue #97. We could
however close it and open smaller ones to address remaining gaps.
Refs #97
Signed-off-by: Waldemar Kozaczuk <[email protected]>
0 commit comments