From: David van Moolenbroek Date: Wed, 26 Aug 2015 05:33:06 +0000 (+0200) Subject: Do not instrument malloc implementation variables X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F3148%2F1;p=minix.git Do not instrument malloc implementation variables Since the heap is reconstructed upon state transfer, the old malloc state is discarded. In order to avoid state transfer errors, we can and in fact must discard the internal state of the malloc implementation. This patch achieves this by using the sectionify pass to mark the variables in the libminc malloc object as state that must be skipped during state transfer. Change-Id: Ie330f582c8bd45f37a878ea41fa0f9d4a18045e1 --- diff --git a/minix/lib/libminc/Makefile b/minix/lib/libminc/Makefile index 3239fa517..ece7b4758 100644 --- a/minix/lib/libminc/Makefile +++ b/minix/lib/libminc/Makefile @@ -263,6 +263,13 @@ CLEANFILES+= ${f:C/\.o/.bc/} CPPFLAGS.${i}+= -I${LIBCDIR}/stdlib .endfor +CPPFLAGS.malloc.c+= -D_LIBSYS +# Avoid magic instrumentation of the malloc data variables, since the heap is +# reconstructed upon state transfer. We do need to instrument the malloc +# functions, since we need to hook their mmap/munmap calls. +SECTIONIFY.malloc.c+= -sectionify-no-override \ + -sectionify-data-section-map=.*/magic_malloc_data + .for f in \ strcspn.o ${f} ${f:C/\.o/.bc/}: ${LIBCDIR}/string/${f:C/\.o/.c/} @@ -294,8 +301,6 @@ CLEANFILES+= ${f:C/\.o/.bc/} .endif # ${USE_BITCODE:Uno} == "yes" .endfor -CPPFLAGS.malloc.c+= -D_LIBSYS - .for f in \ brksize.o _do_kernel_call_intr.o get_minix_kerninfo.o _ipc.o ucontext.o ${f} ${f:C/\.o/.bc/}: ${LIBMINIXCARCHDIR}/sys/${f:C/\.o/.S/} diff --git a/minix/llvm/include/magic_common.h b/minix/llvm/include/magic_common.h index 7f9d2f1ed..7b1048d5b 100644 --- a/minix/llvm/include/magic_common.h +++ b/minix/llvm/include/magic_common.h @@ -55,6 +55,8 @@ #define MAGIC_HIDDEN_ARRAY_PREFIX ".arr.magic" #define MAGIC_HIDDEN_STR_PREFIX ".str.magic" +#define MAGIC_MALLOC_VARS_SECTION_PREFIX "magic_malloc_data" + /* Magic configuration. */ #ifndef MAGIC_OUTPUT_CTL #define MAGIC_OUTPUT_CTL 0 diff --git a/minix/llvm/passes/magic/MagicPass.cpp b/minix/llvm/passes/magic/MagicPass.cpp index 9badbddbc..3fb9d201d 100644 --- a/minix/llvm/passes/magic/MagicPass.cpp +++ b/minix/llvm/passes/magic/MagicPass.cpp @@ -68,7 +68,7 @@ MMAPCtlFunction("magic-mmap-ctlfunc", static cl::opt MagicDataSections("magic-data-sections", cl::desc("Specify all the colon-separated magic data section regexes not to instrument"), - cl::init("^" MAGIC_STATIC_VARS_SECTION_PREFIX ".*$:^" UNBL_SECTION_PREFIX ".*$"), cl::NotHidden, cl::ValueRequired); + cl::init("^" MAGIC_STATIC_VARS_SECTION_PREFIX ".*$:^" UNBL_SECTION_PREFIX ".*$:^" MAGIC_MALLOC_VARS_SECTION_PREFIX ".*$"), cl::NotHidden, cl::ValueRequired); static cl::opt MagicFunctionSections("magic-function-sections", diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index 08e3ec2ae..1eb4f2d7f 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -207,12 +207,17 @@ SHLIB_SHFLAGS+= -L ${DESTDIR}/usr/lib SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \ -Wl,-plugin-opt=-disable-opt +SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so + .S.bc: ${.TARGET:.bc=.o} rm -f ${.TARGET} ln ${.TARGET:.bc=.o} ${.TARGET} .c.bc: ${_MKTARGET_COMPILE} ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto + if [ -n '${SECTIONIFY.${.IMPSRC:T}}' ]; then \ + ${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}} -o ${.TARGET}.tmp ${.TARGET} && mv -f ${.TARGET}.tmp ${.TARGET}; \ + fi .cc.bc .cxx.bc .cpp.bc: ${_MKTARGET_COMPILE}