From: Florian Krohm Date: Sat, 21 Apr 2012 03:34:54 +0000 (+0000) Subject: We incorrectly stored the archinfo_host argument of iselSB_S390 into X-Git-Tag: svn/VALGRIND_3_8_1^2~181 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dea74cdec4a1e468734c3b7cac701987dd593c08;p=thirdparty%2Fvalgrind.git We incorrectly stored the archinfo_host argument of iselSB_S390 into a global variable not realising it points to a stack-allocated variable. This caused s390_archinfo_host->hwcaps member to change its value randomly over time. It could have caused invalid code to be generated. Curious that it did not surface. git-svn-id: svn://svn.valgrind.org/vex/trunk@2297 --- diff --git a/VEX/priv/host_s390_defs.c b/VEX/priv/host_s390_defs.c index f46a1bed1f..8bcfb39620 100644 --- a/VEX/priv/host_s390_defs.c +++ b/VEX/priv/host_s390_defs.c @@ -49,7 +49,7 @@ Until then, we use a global variable. This variable is set as a side effect of iselSB_S390. This is safe because instructions are selected before they are emitted. */ -const VexArchInfo *s390_archinfo_host; +UInt s390_host_hwcaps; /*------------------------------------------------------------*/ diff --git a/VEX/priv/host_s390_defs.h b/VEX/priv/host_s390_defs.h index ad99c4ffcf..ce4a197260 100644 --- a/VEX/priv/host_s390_defs.h +++ b/VEX/priv/host_s390_defs.h @@ -547,21 +547,21 @@ VexInvalRange patchProfInc_S390(void *code_to_patch, ULong *location_of_counter); /* KLUDGE: See detailled comment in host_s390_defs.c. */ -extern const VexArchInfo *s390_archinfo_host; +extern UInt s390_host_hwcaps; /* Convenience macros to test installed facilities */ #define s390_host_has_ldisp \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_LDISP)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_LDISP)) #define s390_host_has_eimm \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_EIMM)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_EIMM)) #define s390_host_has_gie \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_GIE)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_GIE)) #define s390_host_has_dfp \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_DFP)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_DFP)) #define s390_host_has_fgx \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_FGX)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_FGX)) #define s390_host_has_etf2 \ - (s390_archinfo_host->hwcaps & (VEX_HWCAPS_S390X_ETF2)) + (s390_host_hwcaps & (VEX_HWCAPS_S390X_ETF2)) #endif /* ndef __VEX_HOST_S390_DEFS_H */ diff --git a/VEX/priv/host_s390_isel.c b/VEX/priv/host_s390_isel.c index 9400012ad7..35226f9963 100644 --- a/VEX/priv/host_s390_isel.c +++ b/VEX/priv/host_s390_isel.c @@ -2619,7 +2619,9 @@ iselNext(ISelEnv *env, IRExpr *next, IRJumpKind jk, int offsIP) /*--- Insn selector top-level ---*/ /*---------------------------------------------------------*/ -/* Translate an entire SB to s390 code. */ +/* Translate an entire SB to s390 code. + Note: archinfo_host is a pointer to a stack-allocated variable. + Do not assign it to a global variable! */ HInstrArray * iselSB_S390(IRSB *bb, VexArch arch_host, VexArchInfo *archinfo_host, @@ -2632,8 +2634,8 @@ iselSB_S390(IRSB *bb, VexArch arch_host, VexArchInfo *archinfo_host, ISelEnv *env; UInt hwcaps_host = archinfo_host->hwcaps; - /* KLUDGE: export archinfo_host. */ - s390_archinfo_host = archinfo_host; + /* KLUDGE: export hwcaps. */ + s390_host_hwcaps = hwcaps_host; /* Do some sanity checks */ vassert((VEX_HWCAPS_S390X(hwcaps_host) & ~(VEX_HWCAPS_S390X_ALL)) == 0);