]> Zhao Yanbai Git Server - minix.git/commitdiff
Do not instrument malloc implementation variables 48/3148/1
authorDavid van Moolenbroek <david@minix3.org>
Wed, 26 Aug 2015 05:33:06 +0000 (07:33 +0200)
committerDavid van Moolenbroek <david@minix3.org>
Thu, 17 Sep 2015 14:03:47 +0000 (14:03 +0000)
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

minix/lib/libminc/Makefile
minix/llvm/include/magic_common.h
minix/llvm/passes/magic/MagicPass.cpp
share/mk/bsd.lib.mk

index 3239fa51733993702110b7070937266a8409e76c..ece7b4758799702cde1545a90fcb7e4d716dfc6a 100644 (file)
@@ -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/}
index 7f9d2f1ed3f3404c6109261222af7c7e3bbf16da..7b1048d5b150d1009a968f6782fed99918e8ae0f 100644 (file)
@@ -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
index 9badbddbcc8d40e9afecd5582e5aa01b41187b19..3fb9d201def68ee15ca9479e396724784c26d652 100644 (file)
@@ -68,7 +68,7 @@ MMAPCtlFunction("magic-mmap-ctlfunc",
 static cl::opt<std::string>
 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<std::string>
 MagicFunctionSections("magic-function-sections",
index 08e3ec2aeee6ced341172623a34be193bd83ab33..1eb4f2d7f019c066573238590a2b9254969297fc 100644 (file)
@@ -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}