From: Nadav Har'El <[email protected]> Committer: Waldemar Kozaczuk <[email protected]> Branch: master
Add new mechanism for function aliases - outside original source file For a long time, adding an alias to a function required us to use the "weak_alias" macro in the *same* source file as the original function. This caused us to modify some Musl files we didn't want to modify. In this patch I add a new mechanism for creating an alias for functions without modifying their original file. The original symbol's address is only known at link time, not compile time, so we do this symbol copying via a linker script - we have a new file libc/aliases.ld with a simple list of symbol assignments. To demonstrate the easiness and useful of this feature, we drop one file which we had to change from musl - res_init.c - just because we wanted to add an alias to it. With the new aliases.ld - we no longer need to modify the original file. In followup patches we can move a lot of the aliases we added in other ways (weak_alias / alias in modified files, wrappers in libc/math/aliases.cc) to the new aliases.ld. Signed-off-by: Nadav Har'El <[email protected]> Message-Id: <[email protected]> --- diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -1375,7 +1375,7 @@ musl += network/getservbyport.o libc += network/getifaddrs.o libc += network/if_nameindex.o musl += network/if_freenameindex.o -libc += network/res_init.o +musl += network/res_init.o musl += prng/rand.o musl += prng/rand_r.o diff --git a/arch/aarch64/loader.ld b/arch/aarch64/loader.ld --- a/arch/aarch64/loader.ld +++ b/arch/aarch64/loader.ld @@ -8,6 +8,7 @@ */ INCLUDE "loader_options.ld" +INCLUDE "libc/aliases.ld" SECTIONS { /* Set the initial program counter to one page beyond the minimal diff --git a/arch/x64/loader.ld b/arch/x64/loader.ld --- a/arch/x64/loader.ld +++ b/arch/x64/loader.ld @@ -6,6 +6,7 @@ */ INCLUDE "loader_options.ld" +INCLUDE "libc/aliases.ld" SECTIONS { /* Set the initial program counter to one page beyond the minimal diff --git a/libc/aliases.ld b/libc/aliases.ld --- a/libc/aliases.ld +++ b/libc/aliases.ld @@ -0,0 +1,12 @@ +/* This file defines symbols as *aliases* to other symbols. The linker + * statically-linking the OSv kernel will set the alias's address to be + * the same one as the original symbol. + * + * This technique is more powerful than the C compiler's "alias(...)" + * attribute - the compiler-only technique is only usable when the alias + * and original symbol are defined in the same translation unit, because + * it is the compiler - not the linker - who need to copy the symbol's + * address. + */ + +__res_init = res_init; diff --git a/libc/network/res_init.c b/libc/network/res_init.c --- a/libc/network/res_init.c +++ b/libc/network/res_init.c @@ -1,7 +0,0 @@ -#include "libc.h" - -int res_init() -{ - return 0; -} -weak_alias(res_init, __res_init); -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000a1550b05ac21a7cc%40google.com.
