Skip to content

Commit

Permalink
lib: introduce symbol namespace for the symbols in Linux libos
Browse files Browse the repository at this point in the history
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 <tazaki@sfc.wide.ad.jp>
  • Loading branch information
thehajime committed Jul 16, 2015
1 parent 4d508e2 commit 751adb6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion arch/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
Expand Down

0 comments on commit 751adb6

Please sign in to comment.