diff --git a/.gitignore b/.gitignore index 74501df4..686d4d83 100644 --- a/.gitignore +++ b/.gitignore @@ -735,6 +735,9 @@ valgrind/fjalar/rundoxy # Ignore shell scripts for compiling fjalar valgrind/fjalar/*.sh +# Stamp file for the fjalar_core_decls.h consistency check +valgrind/fjalar/fjalar_core_decls.stamp + # Documentation valgrind-merge.aux valgrind-merge.cp diff --git a/doc/valgrind-merge.texinfo b/doc/valgrind-merge.texinfo index f71a2478..f2b0c839 100644 --- a/doc/valgrind-merge.texinfo +++ b/doc/valgrind-merge.texinfo @@ -495,6 +495,11 @@ changes in Valgrind API/functionality. For the most part Valgrind maintains a relatively stable interface to its tools. Any tool-visible changes should be noted in the change logs. +If the build fails in the rule for +@file{fjalar_core_decls.stamp}, then a core declaration has changed. +Update the copy in @file{valgrind/fjalar/fjalar_core_decls.h} to match +the core header that it names. + A somewhat more problematic area are changes in the VEX IR. DynComp makes heavy use of the VEX IR, so any changes in it need to be reflected. Most of the changes to the public VEX IR can be discovered diff --git a/valgrind/fjalar/Makefile.am b/valgrind/fjalar/Makefile.am index a7ae83ad..e19ac0ba 100644 --- a/valgrind/fjalar/Makefile.am +++ b/valgrind/fjalar/Makefile.am @@ -99,7 +99,8 @@ fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CPPFLAGS = \ fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \ $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_DEPENDENCIES = \ - $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_PRI_CAPS@) + $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_PRI_CAPS@) \ + fjalar_core_decls.stamp fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDADD = \ $(TOOL_LDADD_@VGCONF_PLATFORM_PRI_CAPS@) fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \ @@ -119,7 +120,8 @@ fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CPPFLAGS = \ fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \ $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_DEPENDENCIES = \ - $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_SEC_CAPS@) + $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_SEC_CAPS@) \ + fjalar_core_decls.stamp fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDADD = \ $(TOOL_LDADD_@VGCONF_PLATFORM_SEC_CAPS@) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \ @@ -177,3 +179,31 @@ vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_LDFLAGS = \ $(LIBREPLACEMALLOC_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) endif + +#---------------------------------------------------------------------------- +# Consistency check for fjalar_core_decls.h +#---------------------------------------------------------------------------- + +# fjalar_core_decls.h copies declarations from coregrind headers, which +# tool files must not include. Compile it together with those headers, so +# that the build fails if a Valgrind merge makes the copies wrong. The +# test program is piped to the compiler rather than stored in a .c file, +# because tests/check_headers_and_includes forbids tool .c files from +# including pub_core headers. Each fjalar program depends on the stamp, +# so the check runs whenever a program is built. +CLEANFILES = fjalar_core_decls.stamp + +fjalar_core_decls.stamp: $(srcdir)/fjalar_core_decls.h \ + $(top_srcdir)/coregrind/pub_core_aspacemgr.h \ + $(top_srcdir)/coregrind/pub_core_mallocfree.h + { echo '#include "fjalar_core_decls.h"'; \ + echo 'enum { fjalar_ar_demangle = VG_AR_DEMANGLE };'; \ + echo '#undef VG_AR_DEMANGLE'; \ + echo '#include "pub_core_aspacemgr.h"'; \ + echo '#include "pub_core_mallocfree.h"'; \ + echo '_Static_assert(fjalar_ar_demangle == VG_AR_DEMANGLE,'; \ + echo ' "VG_AR_DEMANGLE in fjalar_core_decls.h is wrong");'; \ + } | $(CC) $(fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CPPFLAGS) \ + $(fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \ + -I$(srcdir) -I$(top_srcdir)/coregrind -fsyntax-only -x c - + touch $@ diff --git a/valgrind/fjalar/fjalar_core_decls.h b/valgrind/fjalar/fjalar_core_decls.h new file mode 100644 index 00000000..25e21852 --- /dev/null +++ b/valgrind/fjalar/fjalar_core_decls.h @@ -0,0 +1,41 @@ +/* + This file is part of Fjalar, a dynamic analysis framework for C/C++ + programs. + + Copyright (C) 2007-2026 University of Washington Computer Science & Engineering Department, + Programming Languages and Software Engineering Group + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. +*/ + +/* fjalar_core_decls.h: + +Declarations of the few Valgrind core (non-tool) entities that Fjalar +uses. Fjalar code (e.g., mc_main.c and typedata.c) includes this file +to call those entities. Tool files must not include coregrind/pub_core_*.h (see +tests/check_headers_and_includes), so these are copied here instead. +The build checks that the copies agree with the originals (see the +fjalar_core_decls.stamp rule in Makefile.am). + +*/ + +#ifndef FJALAR_CORE_DECLS_H +#define FJALAR_CORE_DECLS_H + +#include "pub_tool_basics.h" + +// From coregrind/pub_core_aspacemgr.h. +// mc_check_readable uses this to accept readable memory that Valgrind +// owns, which VG_(am_is_valid_for_client) rejects. +extern Bool VG_(am_is_valid_for_valgrind)(Addr start, SizeT len, UInt prot); + +// From coregrind/pub_core_mallocfree.h. +// Used to release the demanglers' results, which are allocated in the +// VG_AR_DEMANGLE arena. ArenaId is a typedef for Int. +extern void VG_(arena_free)(Int arena, void* ptr); +#define VG_AR_DEMANGLE 3 + +#endif /* FJALAR_CORE_DECLS_H */ diff --git a/valgrind/fjalar/mc_main.c b/valgrind/fjalar/mc_main.c index 51da087c..6cbc2d8c 100644 --- a/valgrind/fjalar/mc_main.c +++ b/valgrind/fjalar/mc_main.c @@ -69,7 +69,7 @@ #include "kvasir/kvasir_main.h" #include "kvasir/dyncomp_main.h" #include "fjalar_main.h" -#include "../coregrind/pub_core_aspacemgr.h" // needed for am_is_valid_for_client +#include "fjalar_core_decls.h" // for VG_(am_is_valid_for_valgrind) #include "mc_include.h" #include "memcheck.h" /* for client requests */ diff --git a/valgrind/fjalar/typedata.c b/valgrind/fjalar/typedata.c index b96e81ee..aefb8829 100644 --- a/valgrind/fjalar/typedata.c +++ b/valgrind/fjalar/typedata.c @@ -40,7 +40,7 @@ // For name demangling. #include "../coregrind/m_demangle/demangle.h" // For VG_(arena_free), to release the demanglers' results. -#include "../coregrind/pub_core_mallocfree.h" +#include "fjalar_core_decls.h" // Most of the following information is taken from "DWARF Debugging // Information Format Version 4". Published by the DWARF Debugging