-
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <jwkozaczuk@gmail.com>
- Loading branch information
Showing
4 changed files
with
76 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ conf-logger_debug=0 | |
conf-DEBUG_BUILD=0 | ||
|
||
conf-debug_elf=0 | ||
conf_hide_symbols=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters