From 751adb6cd217bca14d4ec93d2a686c771ab89ffd Mon Sep 17 00:00:00 2001 From: Hajime Tazaki Date: Thu, 16 Jul 2015 12:33:22 +0900 Subject: [PATCH] lib: introduce symbol namespace for the symbols in Linux libos in some case, a symbol defined in a userspace application conflicts with the one in Linux kernel. usually it won't cause any problems but with libos it will. an example would be a symbol (genlmsg_put) in libnl and linux kernel, which have different signatures each other. - at libnl-3.2.25/lib/genl/genl.c void *genlmsg_put(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version) - at net-next-nuse/net/netlink/genetlink.c void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, struct genl_family *family, int flags, u8 cmd) so if the application calls genlmsg_put() then it will be puzzled. in fact, since liblinux.so is inserted by LD_PRELOAD in NUSE case, the libos symbol is used instead of libnl's one. by using the objcopy trick to redefine symbols with the prefix 'rumpns_', all the libos (kernel) symbols need to be called with rumpns_ABC, with some exceptions like tool-generated symbols. The whole idea is derived from rumpkernel. Signed-off-by: Hajime Tazaki --- arch/lib/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/lib/Makefile b/arch/lib/Makefile index 40749982c3df..a205a62e4540 100644 --- a/arch/lib/Makefile +++ b/arch/lib/Makefile @@ -169,9 +169,19 @@ KERNEL_BUILTIN=$(addprefix $(srctree)/,$(addsuffix builtin.o,$(dirs))) OBJS=$(LIB_OBJ) $(foreach builtin,$(KERNEL_BUILTIN),$(if $($(builtin)),$($(builtin)))) export OBJS KERNEL_LIB COV covl_yes covl_no +# objcopy trick is taken from rumpkernel +EXP_SYMRENAME=rump|RUMP|lib_|g_imported|g_kernel|__initcall_start|__initcall_end|_GLOBAL_OFFSET_TABLE'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}} + quiet_cmd_cc = CC $@ cmd_cc = mkdir -p $(dir $@); \ - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@; \ + ${NM} -go $@ | awk ' \ + $$NF!~/^'${_PQ}'(${EXP_SYMRENAME})/ \ + {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\ + | sort | uniq > $@.renametab; \ + objcopy --preserve-dates --redefine-syms $@.renametab $@; \ + rm -f $@.renametab + quiet_cmd_linkko = KO $@ cmd_linkko = $(CC) -shared -o $@ -nostdlib $^ quiet_cmd_builtin = BUILTIN $@