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
This commit is contained in:
parent
abf8a7e7b3
commit
9b9bea921f
4 changed files with 15 additions and 3 deletions
|
@ -263,6 +263,13 @@ CLEANFILES+= ${f:C/\.o/.bc/}
|
||||||
CPPFLAGS.${i}+= -I${LIBCDIR}/stdlib
|
CPPFLAGS.${i}+= -I${LIBCDIR}/stdlib
|
||||||
.endfor
|
.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 \
|
.for f in \
|
||||||
strcspn.o
|
strcspn.o
|
||||||
${f} ${f:C/\.o/.bc/}: ${LIBCDIR}/string/${f:C/\.o/.c/}
|
${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"
|
.endif # ${USE_BITCODE:Uno} == "yes"
|
||||||
.endfor
|
.endfor
|
||||||
|
|
||||||
CPPFLAGS.malloc.c+= -D_LIBSYS
|
|
||||||
|
|
||||||
.for f in \
|
.for f in \
|
||||||
brksize.o _do_kernel_call_intr.o get_minix_kerninfo.o _ipc.o ucontext.o
|
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/}
|
${f} ${f:C/\.o/.bc/}: ${LIBMINIXCARCHDIR}/sys/${f:C/\.o/.S/}
|
||||||
|
|
|
@ -55,6 +55,8 @@
|
||||||
#define MAGIC_HIDDEN_ARRAY_PREFIX ".arr.magic"
|
#define MAGIC_HIDDEN_ARRAY_PREFIX ".arr.magic"
|
||||||
#define MAGIC_HIDDEN_STR_PREFIX ".str.magic"
|
#define MAGIC_HIDDEN_STR_PREFIX ".str.magic"
|
||||||
|
|
||||||
|
#define MAGIC_MALLOC_VARS_SECTION_PREFIX "magic_malloc_data"
|
||||||
|
|
||||||
/* Magic configuration. */
|
/* Magic configuration. */
|
||||||
#ifndef MAGIC_OUTPUT_CTL
|
#ifndef MAGIC_OUTPUT_CTL
|
||||||
#define MAGIC_OUTPUT_CTL 0
|
#define MAGIC_OUTPUT_CTL 0
|
||||||
|
|
|
@ -68,7 +68,7 @@ MMAPCtlFunction("magic-mmap-ctlfunc",
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
MagicDataSections("magic-data-sections",
|
MagicDataSections("magic-data-sections",
|
||||||
cl::desc("Specify all the colon-separated magic data section regexes not to instrument"),
|
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>
|
static cl::opt<std::string>
|
||||||
MagicFunctionSections("magic-function-sections",
|
MagicFunctionSections("magic-function-sections",
|
||||||
|
|
|
@ -207,12 +207,17 @@ SHLIB_SHFLAGS+= -L ${DESTDIR}/usr/lib
|
||||||
SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \
|
SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \
|
||||||
-Wl,-plugin-opt=-disable-opt
|
-Wl,-plugin-opt=-disable-opt
|
||||||
|
|
||||||
|
SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so
|
||||||
|
|
||||||
.S.bc: ${.TARGET:.bc=.o}
|
.S.bc: ${.TARGET:.bc=.o}
|
||||||
rm -f ${.TARGET}
|
rm -f ${.TARGET}
|
||||||
ln ${.TARGET:.bc=.o} ${.TARGET}
|
ln ${.TARGET:.bc=.o} ${.TARGET}
|
||||||
.c.bc:
|
.c.bc:
|
||||||
${_MKTARGET_COMPILE}
|
${_MKTARGET_COMPILE}
|
||||||
${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
|
${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:
|
.cc.bc .cxx.bc .cpp.bc:
|
||||||
${_MKTARGET_COMPILE}
|
${_MKTARGET_COMPILE}
|
||||||
|
|
Loading…
Reference in a new issue