From bb607f747a5d02364248f5bd531fab9fc5668dd7 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sat, 17 Oct 2026 11:41:31 -0700 Subject: [PATCH 1/8] Generate valgrind/fjalar/Makefile.am from Memcheck's Almost every line of Fjalar's Makefile.am renames Memcheck to Fjalar, so most upstream changes to memcheck/Makefile.am conflict when they are patched in. generate-fjalar-makefile.sh instead generates it from valgrind/memcheck/Makefile.am, and Fjalar's changes to the build are in valgrind/fjalar/fjalar.am, which the generated file includes. That includes the fjalar_core_decls.h consistency check. memcheck.patch omits Makefile.am, and the merge doc and the upgrade plans say to run the script after the Memcheck merge. Split out of #103. --- doc/valgrind-merge.texinfo | 24 ++++ generate-fjalar-makefile.sh | 55 ++++++++ generate-patch-files.sh | 4 +- make-fjalar-release.sh | 5 +- plan-upgrade-readelf.md | 4 +- plan-upgrade-valgrind.md | 8 +- valgrind/fjalar/Makefile.am | 127 +++--------------- valgrind/fjalar/fjalar.am | 115 ++++++++++++++++ .../fjalar/notes/fjalar-release-notes.txt | 5 +- 9 files changed, 230 insertions(+), 117 deletions(-) create mode 100755 generate-fjalar-makefile.sh create mode 100644 valgrind/fjalar/fjalar.am diff --git a/doc/valgrind-merge.texinfo b/doc/valgrind-merge.texinfo index f2b0c839d..dc4d515bb 100644 --- a/doc/valgrind-merge.texinfo +++ b/doc/valgrind-merge.texinfo @@ -440,6 +440,30 @@ cd $INV/fjalar/valgrind/fjalar patch -p2 -lu < $INV/memcheck.patch @end example +The Memcheck merge does not patch Fjalar's build file +@file{valgrind/fjalar/Makefile.am}; @file{memcheck.patch} omits +@file{Makefile.am}. Instead, regenerate it from +@file{valgrind/memcheck/Makefile.am}, which the Coregrind merge updated: + +@example +cd $INV/fjalar +./generate-fjalar-makefile.sh +@end example + +@file{generate-fjalar-makefile.sh} renames Memcheck to Fjalar. Fjalar +builds every Memcheck source file, so a new upstream source file is built +automatically. The generated file includes +@file{valgrind/fjalar/fjalar.am}, which holds Fjalar's changes, such as +its additional source files and compiler flags. Review +@command{git diff valgrind/fjalar/Makefile.am}, and update +@file{fjalar.am} if an upstream change conflicts with Fjalar's changes. +The script lists any line of the generated file that still mentions +Memcheck or docs, or that is a conflict marker, and then exits with +status 2. Such a line may mean that the renaming in +@file{generate-fjalar-makefile.sh} needs to handle a new upstream +construct. After changing @file{generate-fjalar-makefile.sh} or +@file{fjalar.am}, rerun it. + @node Memcheck Conflicts @section Memcheck Conflicts diff --git a/generate-fjalar-makefile.sh b/generate-fjalar-makefile.sh new file mode 100755 index 000000000..fe57fd7e8 --- /dev/null +++ b/generate-fjalar-makefile.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# This script generates Fjalar's build file valgrind/fjalar/Makefile.am from +# Memcheck's, valgrind/memcheck/Makefile.am, by renaming Memcheck to Fjalar. +# Fjalar's changes to the build are in valgrind/fjalar/fjalar.am, which the +# generated file includes. Run this script after the Memcheck merge (see +# doc/valgrind-merge.texinfo), and after changing it or fjalar.am. +# Usage: generate-fjalar-makefile.sh [OUTPUT] +# OUTPUT defaults to valgrind/fjalar/Makefile.am. The script prints each +# line of the generated file that may need a change to the renaming, and +# then it exits with status 2. It exits with status 1 if it fails. + +set -e +set -o pipefail +# A failing command, such as sed, may itself exit with status 2. +trap 'exit 1' ERR + +top=$(dirname "$0") +output=${1:-$top/valgrind/fjalar/Makefile.am} +# Write to a temporary file, so that a failure leaves OUTPUT unchanged. +tmp=$output.tmp +trap 'rm -f "$tmp"' EXIT + +# Fjalar's version is generated instead of patched, because almost every +# line of it renames Memcheck to Fjalar, so most upstream changes would +# conflict. Fjalar builds every Memcheck source file. +# The sed command renames only Memcheck's program and variable names, not +# file names such as memcheck.h, and it removes the assignment, including +# its continuation lines, that adds Memcheck's docs, which Fjalar lacks, to +# EXTRA_DIST. +{ + echo "## Generated by generate-fjalar-makefile.sh from ../memcheck/Makefile.am." + echo "## Do not edit this file; put Fjalar's changes in fjalar.am." + echo + sed -e 's/memcheck\([-_]\)/fjalar\1/g; s/MEMCHECK_/FJALAR_/g' \ + -e '/^EXTRA_DIST *= *docs\//{:a;/\\$/{N;ba};d}' \ + "$top/valgrind/memcheck/Makefile.am" + echo + echo 'include $(srcdir)/fjalar.am' +} > "$tmp" +mv "$tmp" "$output" + +# An upstream change that the renaming does not handle needs a change to +# this script. Conflict markers mean that the Coregrind merge left +# valgrind/memcheck/Makefile.am unresolved. Each memcheck.h is removed +# before the check, so that the rest of its line is still checked. +problems=$(awk '/^##/ { next } + { line = tolower($0); gsub(/memcheck\.h/, "", line) } + line ~ /memcheck|docs\// || /^(<<<<<<<|\|\|\|\|\|\|\||=======|>>>>>>>)/ { print FNR ":" $0 }' "$output") +if [ -n "$problems" ]; then + echo "Lines of $output that may need a change to the renaming" + echo "in $0 or a resolution of a conflict:" + echo "$problems" + exit 2 +fi diff --git a/generate-patch-files.sh b/generate-patch-files.sh index 006836ab8..2c1f4e452 100755 --- a/generate-patch-files.sh +++ b/generate-patch-files.sh @@ -7,7 +7,9 @@ rm -f coregrind.patch diff -ur --unidirectional-new-file -x.git valgrind-old valgrind-new > coregrind.patch rm -f memcheck.patch -diff -ur --unidirectional-new-file -x.git -xdocs -xtests valgrind-old/memcheck valgrind-new/memcheck > memcheck.patch +# generate-fjalar-makefile.sh generates Fjalar's version of +# memcheck/Makefile.am, so memcheck.patch omits it. +diff -ur --unidirectional-new-file -x.git -xdocs -xtests -xMakefile.am valgrind-old/memcheck valgrind-new/memcheck > memcheck.patch rm -f coregrind-Fjalar.diff diff -ur -xinst -x.git -xfjalar -xMakefile.in -xfjalar/html valgrind-old fjalar/valgrind > coregrind-Fjalar.diff diff --git a/make-fjalar-release.sh b/make-fjalar-release.sh index 2a0f66e35..c26167d9e 100755 --- a/make-fjalar-release.sh +++ b/make-fjalar-release.sh @@ -37,9 +37,10 @@ find . -type d -name CVS | xargs rm -rf # - Change mc_pre_clo_init() in mc_main.c to not print out the heading # that says Kvasir/DynComp but instead print out something # Fjalar-related. And also change the contact info. and version number. -# - Change fjalar/Makefile.am to build basic-tool instead of kvasir by +# - Change fjalar/fjalar.am to build basic-tool instead of kvasir by # removing kvasir/ source files and adding 'basic-tool/basic-tool.c' to -# FJALAR_SOURCES_COMMON +# FJALAR_SOURCES_COMMON, and by removing kvasir/dyncomp_wrappers.c from +# VGPRELOAD_FJALAR_SOURCES_COMMON. (fjalar/Makefile.am is generated.) # Uncomment the following if you need to regenerate the patch; diff --git a/plan-upgrade-readelf.md b/plan-upgrade-readelf.md index 858e5a1c0..8d48bb103 100644 --- a/plan-upgrade-readelf.md +++ b/plan-upgrade-readelf.md @@ -96,7 +96,9 @@ Kvasir tests after each step. `include/`, `include/elf/`, or `binutils/`) that Fjalar does not yet have, and whether they call into new helper files (e.g. new code split out of `dwarf.c`). Copy any new needed headers into `valgrind/fjalar/include/` - and add any new needed `.c` files to `valgrind/fjalar/Makefile.am`. + and add any new needed `.c` files to `FJALAR_SOURCES_COMMON` in + `valgrind/fjalar/fjalar.am`. (Do not edit `valgrind/fjalar/Makefile.am`, + which `generate-fjalar-makefile.sh` regenerates at each Valgrind merge.) (`demanguse.h` and the CTF headers were added this way in the 2.39 merge.) - Known case: Binutils 2.40 added `readelf --sframe`, which includes `sframe-api.h` and calls into libsframe. Fjalar does not need it: diff --git a/plan-upgrade-valgrind.md b/plan-upgrade-valgrind.md index 2638a5331..7a806ea24 100644 --- a/plan-upgrade-valgrind.md +++ b/plan-upgrade-valgrind.md @@ -107,8 +107,12 @@ it completely (merged, CI green) before starting this one. That plan's - In `mc_translate.c`'s `MC_(instrument)`, check that every case has matching DynComp code and that new cases get a DynComp counterpart. - Check `mc_main.c` still has Fjalar's options/version info. - - New memcheck source files: decide whether Fjalar needs them; if so, - add to `valgrind/fjalar/Makefile.am`. + - Run `./generate-fjalar-makefile.sh`, which regenerates + `valgrind/fjalar/Makefile.am` from `valgrind/memcheck/Makefile.am`, so + Fjalar builds every new Memcheck source file. Review the diff of + `valgrind/fjalar/Makefile.am`, and update `valgrind/fjalar/fjalar.am`, + which holds Fjalar's changes to the build, if an upstream change + conflicts with them. 7. **DynComp / Fjalar / Kvasir updates.** - `diff -b valgrind-old/VEX/pub/libvex_ir.h valgrind-new/VEX/pub/libvex_ir.h` diff --git a/valgrind/fjalar/Makefile.am b/valgrind/fjalar/Makefile.am index e19ac0baf..1be6e093d 100644 --- a/valgrind/fjalar/Makefile.am +++ b/valgrind/fjalar/Makefile.am @@ -1,46 +1,8 @@ -## -# 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. -## +## Generated by generate-fjalar-makefile.sh from ../memcheck/Makefile.am. +## Do not edit this file; put Fjalar's changes in fjalar.am. include $(top_srcdir)/Makefile.tool.am -#Fjalar has no 'tests' subdir -SUBDIRS = . - -# PG - Build Fjalar with Kvasir (in the kvasir sub-directory) - -## Build Fjalar at a higher optimisation level -# PG - don't do optimizations for the sake of debugging, instead add debugging info. -# Also disable the -Wmissing-prototypes warnings to prevent extra annoyances - -#AM_CFLAGS_X86_LINUX += -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall -#AM_CFLAGS_X86_LINUX := $(AM_CFLAGS_X86_LINUX: -O2=-O0) -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall -Wno-format -Wno-format-zero-length -Wno-pointer-sign -Wno-long-long - -# AM_CFLAGS_AMD64_LINUX += -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall - -# get all binutil .h files from include; get config.h from .. (markro) -EXTRA_CFLAGS = -Iinclude -I../VEX/pub -I../include -I.. - -# for debugging versions -#EXTRA_CFLAGS += -O0 -finstrument-functions -EXTRA_CFLAGS += -O0 - -# Compile fjalar without -Wcast-qual -CFLAGS += -Wno-cast-qual -CXXFLAGS += -Wno-cast-qual - -# Compile fjalar without --fno-common (gcc version 10 default) -CFLAGS += -fcommon -CXXFLAGS += -fcommon #---------------------------------------------------------------------------- # Headers @@ -67,40 +29,16 @@ FJALAR_SOURCES_COMMON = \ mc_main.c mc_main_asm.c \ mc_translate.c \ mc_machine.c \ - mc_errors.c \ - fjalar_dwarf.c \ - fjalar_main.c \ - fjalar_runtime.c \ - fjalar_select.c \ - generate_fjalar_entries.c \ - GenericHashtable.c \ - fjalar_traversal.c \ - readelf.c \ - dwarf.c \ - libiberty/dwarfnames.c \ - elfcomm.c \ - typedata.c \ - disambig.c \ - my_libc.c \ - my_libc_float.c \ - tsearch.c \ - kvasir/kvasir_main.c \ - kvasir/decls-output.c \ - kvasir/dtrace-output.c \ - kvasir/union_find.c \ - kvasir/dyncomp_main.c \ - kvasir/dyncomp_runtime.c \ - kvasir/dyncomp_translate.c + mc_errors.c fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_SOURCES = \ - $(FJALAR_SOURCES_COMMON) + $(FJALAR_SOURCES_COMMON) fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CPPFLAGS = \ - $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@: -O2=-O0) -fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \ - $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) + $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) +fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \ + $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) -O2 fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_DEPENDENCIES = \ - $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_PRI_CAPS@) \ - fjalar_core_decls.stamp + $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_PRI_CAPS@) fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDADD = \ $(TOOL_LDADD_@VGCONF_PLATFORM_PRI_CAPS@) fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \ @@ -114,14 +52,13 @@ fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \ if VGCONF_HAVE_PLATFORM_SEC fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_SOURCES = \ - $(FJALAR_SOURCES_COMMON) + $(FJALAR_SOURCES_COMMON) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CPPFLAGS = \ - $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@: -O2=-O0) + $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \ - $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) + $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) -O2 fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_DEPENDENCIES = \ - $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_SEC_CAPS@) \ - fjalar_core_decls.stamp + $(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_SEC_CAPS@) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDADD = \ $(TOOL_LDADD_@VGCONF_PLATFORM_SEC_CAPS@) fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \ @@ -138,8 +75,6 @@ endif # vgpreload_fjalar-.so #---------------------------------------------------------------------------- - - noinst_PROGRAMS += vgpreload_fjalar-@VGCONF_ARCH_PRI@-@VGCONF_OS@.so if VGCONF_HAVE_PLATFORM_SEC noinst_PROGRAMS += vgpreload_fjalar-@VGCONF_ARCH_SEC@-@VGCONF_OS@.so @@ -151,14 +86,14 @@ endif # mc_replace_strmem.c runs on the simulated CPU, and is built with # AM_CFLAGS_PSO_* (see $(top_srcdir)/Makefile.all.am). -VGPRELOAD_FJALAR_SOURCES_COMMON = mc_replace_strmem.c kvasir/dyncomp_wrappers.c +VGPRELOAD_FJALAR_SOURCES_COMMON = mc_replace_strmem.c vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_SOURCES = \ $(VGPRELOAD_FJALAR_SOURCES_COMMON) vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CPPFLAGS = \ - $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@: -O2=-O0) + $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CFLAGS = \ - $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) + $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@) -O2 vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_DEPENDENCIES = \ $(LIBREPLACEMALLOC_@VGCONF_PLATFORM_PRI_CAPS@) vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \ @@ -169,9 +104,9 @@ if VGCONF_HAVE_PLATFORM_SEC vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_SOURCES = \ $(VGPRELOAD_FJALAR_SOURCES_COMMON) vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_CPPFLAGS = \ - $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@: -O2=-O0) + $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_CFLAGS = \ - $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_SEC_CAPS@: -O2=-O0) $(EXTRA_CFLAGS) + $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_SEC_CAPS@) -O2 vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_DEPENDENCIES = \ $(LIBREPLACEMALLOC_@VGCONF_PLATFORM_SEC_CAPS@) vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_LDFLAGS = \ @@ -180,30 +115,4 @@ vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_LDFLAGS = \ 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 $@ +include $(srcdir)/fjalar.am diff --git a/valgrind/fjalar/fjalar.am b/valgrind/fjalar/fjalar.am new file mode 100644 index 000000000..9532c719e --- /dev/null +++ b/valgrind/fjalar/fjalar.am @@ -0,0 +1,115 @@ +## +# 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's changes to the Memcheck build. Makefile.am, which includes +## this file at its end, is generated from ../memcheck/Makefile.am by +## generate-fjalar-makefile.sh; see its header comment. + +#Fjalar has no 'tests' subdir +SUBDIRS = . + +# PG - Build Fjalar with Kvasir (in the kvasir sub-directory) + +## Build Fjalar at a higher optimisation level +# PG - don't do optimizations for the sake of debugging, instead add debugging info. +# Also disable the -Wmissing-prototypes warnings to prevent extra annoyances + +#AM_CFLAGS_X86_LINUX += -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall +#AM_CFLAGS_X86_LINUX := $(AM_CFLAGS_X86_LINUX: -O2=-O0) -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall -Wno-format -Wno-format-zero-length -Wno-pointer-sign -Wno-long-long + +# AM_CFLAGS_AMD64_LINUX += -g -O0 -fno-omit-frame-pointer -Iinclude -W -Wall + +# get all binutil .h files from include; get config.h from .. (markro) +EXTRA_CFLAGS = -Iinclude -I../VEX/pub -I../include -I.. + +# for debugging versions +#EXTRA_CFLAGS += -O0 -finstrument-functions +EXTRA_CFLAGS += -O0 + +# Compile fjalar without -Wcast-qual +CFLAGS += -Wno-cast-qual +CXXFLAGS += -Wno-cast-qual + +# Compile fjalar without --fno-common (gcc version 10 default) +CFLAGS += -fcommon +CXXFLAGS += -fcommon + +# Fjalar's sources, in addition to the Memcheck sources. +FJALAR_SOURCES_COMMON += \ + fjalar_dwarf.c \ + fjalar_main.c \ + fjalar_runtime.c \ + fjalar_select.c \ + generate_fjalar_entries.c \ + GenericHashtable.c \ + fjalar_traversal.c \ + readelf.c \ + dwarf.c \ + libiberty/dwarfnames.c \ + elfcomm.c \ + typedata.c \ + disambig.c \ + my_libc.c \ + my_libc_float.c \ + tsearch.c \ + kvasir/kvasir_main.c \ + kvasir/decls-output.c \ + kvasir/dtrace-output.c \ + kvasir/union_find.c \ + kvasir/dyncomp_main.c \ + kvasir/dyncomp_runtime.c \ + kvasir/dyncomp_translate.c + +VGPRELOAD_FJALAR_SOURCES_COMMON += kvasir/dyncomp_wrappers.c + +# The -O0 in EXTRA_CFLAGS overrides the -O2 or -O earlier in these flags. +fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS += $(EXTRA_CFLAGS) +vgpreload_fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CFLAGS += $(EXTRA_CFLAGS) +if VGCONF_HAVE_PLATFORM_SEC +fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS += $(EXTRA_CFLAGS) +vgpreload_fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_so_CFLAGS += $(EXTRA_CFLAGS) +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_@VGCONF_ARCH_PRI@_@VGCONF_OS@_DEPENDENCIES += fjalar_core_decls.stamp +if VGCONF_HAVE_PLATFORM_SEC +fjalar_@VGCONF_ARCH_SEC@_@VGCONF_OS@_DEPENDENCIES += fjalar_core_decls.stamp +endif + +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/notes/fjalar-release-notes.txt b/valgrind/fjalar/notes/fjalar-release-notes.txt index 8f17386a3..953cd1436 100644 --- a/valgrind/fjalar/notes/fjalar-release-notes.txt +++ b/valgrind/fjalar/notes/fjalar-release-notes.txt @@ -45,9 +45,10 @@ Fjalar-related. And also change the contact info. and version number. - Remove kvasir/ sub-directory within fjalar/, leaving only basic-tool -- Change fjalar/Makefile.am to build basic-tool instead of kvasir by +- Change fjalar/fjalar.am to build basic-tool instead of kvasir by removing kvasir/ source files and adding 'basic-tool/basic-tool.c' to -FJALAR_SOURCES_COMMON +FJALAR_SOURCES_COMMON, and by removing kvasir/dyncomp_wrappers.c from +VGPRELOAD_FJALAR_SOURCES_COMMON. (fjalar/Makefile.am is generated.) - ln -s valgrind-3/valgrind/fjalar/ fjalar-source to create a convenient link from the top level to the Fjalar source code directory From 102666342eda6bfebed228c09076ba2bfdf32874 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sat, 17 Oct 2026 11:58:53 -0700 Subject: [PATCH 2/8] Use MOSTLYCLEANFILES for the stamp; clarify the generator's exit status --- generate-fjalar-makefile.sh | 7 ++++--- valgrind/fjalar/fjalar.am | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/generate-fjalar-makefile.sh b/generate-fjalar-makefile.sh index fe57fd7e8..9caa25f82 100755 --- a/generate-fjalar-makefile.sh +++ b/generate-fjalar-makefile.sh @@ -6,9 +6,10 @@ # generated file includes. Run this script after the Memcheck merge (see # doc/valgrind-merge.texinfo), and after changing it or fjalar.am. # Usage: generate-fjalar-makefile.sh [OUTPUT] -# OUTPUT defaults to valgrind/fjalar/Makefile.am. The script prints each -# line of the generated file that may need a change to the renaming, and -# then it exits with status 2. It exits with status 1 if it fails. +# OUTPUT defaults to valgrind/fjalar/Makefile.am. If any line of the +# generated file may need a change to the renaming, the script prints each +# such line and exits with status 2. Otherwise it exits with status 0, or +# with status 1 if it fails. set -e set -o pipefail diff --git a/valgrind/fjalar/fjalar.am b/valgrind/fjalar/fjalar.am index 9532c719e..069c0fb8e 100644 --- a/valgrind/fjalar/fjalar.am +++ b/valgrind/fjalar/fjalar.am @@ -92,7 +92,7 @@ endif # 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 +MOSTLYCLEANFILES = fjalar_core_decls.stamp fjalar_@VGCONF_ARCH_PRI@_@VGCONF_OS@_DEPENDENCIES += fjalar_core_decls.stamp if VGCONF_HAVE_PLATFORM_SEC From d9623177d1fa82d433323261b4e32da01716dbff Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 18 Oct 2026 07:43:49 -0700 Subject: [PATCH 3/8] Valgrind plan, step 6: run generate-fjalar-makefile.sh by its absolute path, since the step's shell is in valgrind/fjalar --- plan-upgrade-valgrind.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plan-upgrade-valgrind.md b/plan-upgrade-valgrind.md index 7a806ea24..3308a8999 100644 --- a/plan-upgrade-valgrind.md +++ b/plan-upgrade-valgrind.md @@ -107,7 +107,7 @@ it completely (merged, CI green) before starting this one. That plan's - In `mc_translate.c`'s `MC_(instrument)`, check that every case has matching DynComp code and that new cases get a DynComp counterpart. - Check `mc_main.c` still has Fjalar's options/version info. - - Run `./generate-fjalar-makefile.sh`, which regenerates + - Run `$INV/fjalar/generate-fjalar-makefile.sh`, which regenerates `valgrind/fjalar/Makefile.am` from `valgrind/memcheck/Makefile.am`, so Fjalar builds every new Memcheck source file. Review the diff of `valgrind/fjalar/Makefile.am`, and update `valgrind/fjalar/fjalar.am`, From e44758a9505cafca26daca9f539bc14f0a1f6e86 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 19 Oct 2026 11:51:35 -0700 Subject: [PATCH 4/8] Merge doc: set DAIKONDIR when cloning, explain removing memcheck files, describe patch -b --- doc/valgrind-merge.texinfo | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/doc/valgrind-merge.texinfo b/doc/valgrind-merge.texinfo index 4abdcab6d..d156f61c2 100644 --- a/doc/valgrind-merge.texinfo +++ b/doc/valgrind-merge.texinfo @@ -131,6 +131,7 @@ repositories: @example export INV=`pwd` +export DAIKONDIR=$INV/daikon git clone https://github.com/codespecs/daikon.git git clone https://github.com/codespecs/fjalar.git @end example @@ -352,18 +353,29 @@ Fjalar has two copies of memcheck: an unmodified one in @file{$INV/fjalar/valgrind/memcheck/}, and a modified one (the @file{mc_*} files and @file{memcheck.h}) in @file{$INV/fjalar/valgrind/fjalar/}. The command above omits the -modified copy. The following command lists the files in the modified -copy that have no counterpart in the target Valgrind's memcheck. Except -for @file{mc_translate.h}, which is Fjalar's own, check each one for -Fjalar changes, then remove it: +modified copy. The Memcheck merge (@pxref{Memcheck Merge}) does not +remove files from the modified copy, either: @command{patch} ignores the +files that the Valgrind developers removed. The following command lists +the files in the modified copy that the base Valgrind's memcheck has but +the target Valgrind's memcheck does not: @example cd $INV/fjalar/valgrind/fjalar for f in mc_*.[ch] memcheck.h; do - [ -e $INV/valgrind-new/memcheck/$f ] || echo $f + [ -e $INV/valgrind-old/memcheck/$f ] \ + && [ ! -e $INV/valgrind-new/memcheck/$f ] && echo $f done @end example +@noindent +For each listed file @var{f}, run +@code{diff -u $INV/valgrind-old/memcheck/@var{f} @var{f}} +to see whether Fjalar changed it. If there is no output, remove +@var{f} with @command{rm}. Otherwise, save the output, for example in +@file{$INV/@var{f}-Fjalar.diff}, and then remove @var{f}. The Valgrind +developers probably moved the code of @var{f} to another file; after the +Memcheck merge, make Fjalar's changes in that file. + This step could be done later, but we do it now to reduce the size of the patch and diff files. @@ -411,7 +423,14 @@ Now we can merge the changes from the created diffs. The Coregrind patch should apply with very little conflicts. It can be difficult to undo a patch operation, so you should first attempt -a dry run. +a dry run. When you apply a patch, you may also add the @option{-b} +option, which saves the original version of each file that +@command{patch} modifies, in a file whose name ends in @file{.orig}. +(Without @option{-b}, @command{patch} saves a @file{.orig} file only when +the patch does not match a file exactly.) The @file{.orig} files are useful for +reviewing the changes and for undoing them, and you can give them to a +visual merge tool such as @command{meld}. This applies to every patch +in this document. @example cd $INV/fjalar/valgrind @@ -859,8 +878,8 @@ For these two, a visual merge tool (such as @command{meld}) will be helpful. If you plan to use such a tool, you should make copies of these two files prior to applying the patch. Alternatively, you could add the -"-b" option to the @file{binutils} patch command to backup all the files -modified by the patch. +@option{-b} option (@pxref{Coregrind Merge}) to the @file{binutils.patch} +command to back up all the files that the patch modifies. @example cp -pf dwarf.c dwarf.c.orig From 5a4ec0690cb1e54ef5b412f190d965c4b0775246 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 19 Oct 2026 12:34:52 -0700 Subject: [PATCH 5/8] Fjalar manual: to create a tool, edit fjalar.am, not the generated Makefile.am --- .../fjalar/docs/fjalar-www/fjalar_manual.html | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/valgrind/fjalar/docs/fjalar-www/fjalar_manual.html b/valgrind/fjalar/docs/fjalar-www/fjalar_manual.html index 45e0b42e7..a3eb47c88 100644 --- a/valgrind/fjalar/docs/fjalar-www/fjalar_manual.html +++ b/valgrind/fjalar/docs/fjalar-www/fjalar_manual.html @@ -33,6 +33,7 @@

Getting Started

  • fjalar/
    • Makefile.am +
    • fjalar.am
    • fjalar_tool.h
    • fjalar_include.h
    • mc_main.c @@ -88,26 +89,28 @@

      Creating Fjalar tools

    • Create a sub-directory in the valgrind-3/valgrind/fjalar directory and place all of your tool's source files in there. -
    • Edit Makefile.am in valgrind-3/valgrind/fjalar +
    • Edit fjalar.am in valgrind-3/valgrind/fjalar to include all the .c files of your tool by adding them to the - list of files assigned to the - FJALAR_SOURCES_COMMON variable. (Feel free to tweak - other variables in that file. For instance, you can adjust - AM_CFLAGS_X86_LINUX to add optimizations to boost + list of files that are added to the + FJALAR_SOURCES_COMMON variable. (Do not edit + Makefile.am, which is generated from Memcheck's + Makefile.am and includes fjalar.am. Feel free to tweak + other variables in fjalar.am. For instance, you can remove + the -O0 from EXTRA_CFLAGS to enable optimizations that boost run-time performance. The default is to turn off all optimizations in order to ease debugging.) IMPORTANT: you must also remove the line kvasir/kvasir_main.c \ from the file list. In essence, you are replacing the kvasir tool with your own.
    • Run auto-everything.sh to create a new Makefile - from your modified Makefile.am and re-compile + from Makefile.am and your modified fjalar.am and re-compile everything. You only need to run auto-everything.sh - whenever you make a change to Makefile.am. (Notice + whenever you make a change to fjalar.am. (Notice that directly editing Makefile and Makefile.in is probably futile because they are auto-generated from Makefile.am every time auto-everything.sh is run.) If you do not - subsequently change Makefile.am, you can simply use + subsequently change fjalar.am, you can simply use make and make install to compile and install, respectively. From ee4b2c1eb9809b4447eb2eb69098f2d47b8cc10e Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 19 Oct 2026 12:34:52 -0700 Subject: [PATCH 6/8] Revert the merge doc changes of e44758a, which are unrelated to generating Makefile.am --- doc/valgrind-merge.texinfo | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/doc/valgrind-merge.texinfo b/doc/valgrind-merge.texinfo index d156f61c2..4abdcab6d 100644 --- a/doc/valgrind-merge.texinfo +++ b/doc/valgrind-merge.texinfo @@ -131,7 +131,6 @@ repositories: @example export INV=`pwd` -export DAIKONDIR=$INV/daikon git clone https://github.com/codespecs/daikon.git git clone https://github.com/codespecs/fjalar.git @end example @@ -353,29 +352,18 @@ Fjalar has two copies of memcheck: an unmodified one in @file{$INV/fjalar/valgrind/memcheck/}, and a modified one (the @file{mc_*} files and @file{memcheck.h}) in @file{$INV/fjalar/valgrind/fjalar/}. The command above omits the -modified copy. The Memcheck merge (@pxref{Memcheck Merge}) does not -remove files from the modified copy, either: @command{patch} ignores the -files that the Valgrind developers removed. The following command lists -the files in the modified copy that the base Valgrind's memcheck has but -the target Valgrind's memcheck does not: +modified copy. The following command lists the files in the modified +copy that have no counterpart in the target Valgrind's memcheck. Except +for @file{mc_translate.h}, which is Fjalar's own, check each one for +Fjalar changes, then remove it: @example cd $INV/fjalar/valgrind/fjalar for f in mc_*.[ch] memcheck.h; do - [ -e $INV/valgrind-old/memcheck/$f ] \ - && [ ! -e $INV/valgrind-new/memcheck/$f ] && echo $f + [ -e $INV/valgrind-new/memcheck/$f ] || echo $f done @end example -@noindent -For each listed file @var{f}, run -@code{diff -u $INV/valgrind-old/memcheck/@var{f} @var{f}} -to see whether Fjalar changed it. If there is no output, remove -@var{f} with @command{rm}. Otherwise, save the output, for example in -@file{$INV/@var{f}-Fjalar.diff}, and then remove @var{f}. The Valgrind -developers probably moved the code of @var{f} to another file; after the -Memcheck merge, make Fjalar's changes in that file. - This step could be done later, but we do it now to reduce the size of the patch and diff files. @@ -423,14 +411,7 @@ Now we can merge the changes from the created diffs. The Coregrind patch should apply with very little conflicts. It can be difficult to undo a patch operation, so you should first attempt -a dry run. When you apply a patch, you may also add the @option{-b} -option, which saves the original version of each file that -@command{patch} modifies, in a file whose name ends in @file{.orig}. -(Without @option{-b}, @command{patch} saves a @file{.orig} file only when -the patch does not match a file exactly.) The @file{.orig} files are useful for -reviewing the changes and for undoing them, and you can give them to a -visual merge tool such as @command{meld}. This applies to every patch -in this document. +a dry run. @example cd $INV/fjalar/valgrind @@ -878,8 +859,8 @@ For these two, a visual merge tool (such as @command{meld}) will be helpful. If you plan to use such a tool, you should make copies of these two files prior to applying the patch. Alternatively, you could add the -@option{-b} option (@pxref{Coregrind Merge}) to the @file{binutils.patch} -command to back up all the files that the patch modifies. +"-b" option to the @file{binutils} patch command to backup all the files +modified by the patch. @example cp -pf dwarf.c dwarf.c.orig From 1577c7440f1401eabbb2b9caae31b203a6b8161f Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 19 Oct 2026 12:50:34 -0700 Subject: [PATCH 7/8] generate-fjalar-makefile.sh: a change to fjalar.am needs only automake The generated Makefile.am includes fjalar.am, and this script does not read fjalar.am, so the header comment's advice to rerun the script after changing fjalar.am was wrong. --- generate-fjalar-makefile.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generate-fjalar-makefile.sh b/generate-fjalar-makefile.sh index 9caa25f82..0356da72b 100755 --- a/generate-fjalar-makefile.sh +++ b/generate-fjalar-makefile.sh @@ -4,7 +4,9 @@ # Memcheck's, valgrind/memcheck/Makefile.am, by renaming Memcheck to Fjalar. # Fjalar's changes to the build are in valgrind/fjalar/fjalar.am, which the # generated file includes. Run this script after the Memcheck merge (see -# doc/valgrind-merge.texinfo), and after changing it or fjalar.am. +# doc/valgrind-merge.texinfo), and after changing this script. A change to +# fjalar.am needs only a rerun of automake, such as by auto-everything.sh, +# because the generated file includes fjalar.am. # Usage: generate-fjalar-makefile.sh [OUTPUT] # OUTPUT defaults to valgrind/fjalar/Makefile.am. If any line of the # generated file may need a change to the renaming, the script prints each From fc34e6dc3dde81ef7b0f844754b037f4be5890a4 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 19 Oct 2026 14:09:50 -0700 Subject: [PATCH 8/8] generate-fjalar-makefile.sh: create the temporary file with mktemp A predictable OUTPUT.tmp could be a symlink planted by another user in a shared directory. Addresses a CodeRabbit review comment on #103. --- generate-fjalar-makefile.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/generate-fjalar-makefile.sh b/generate-fjalar-makefile.sh index 0356da72b..90c67a292 100755 --- a/generate-fjalar-makefile.sh +++ b/generate-fjalar-makefile.sh @@ -20,8 +20,9 @@ trap 'exit 1' ERR top=$(dirname "$0") output=${1:-$top/valgrind/fjalar/Makefile.am} -# Write to a temporary file, so that a failure leaves OUTPUT unchanged. -tmp=$output.tmp +# Write to a temporary file, so that a failure leaves OUTPUT unchanged. mktemp +# creates it exclusively, with an unpredictable name. +tmp=$(mktemp "$output.XXXXXX") trap 'rm -f "$tmp"' EXIT # Fjalar's version is generated instead of patched, because almost every @@ -41,6 +42,9 @@ trap 'rm -f "$tmp"' EXIT echo echo 'include $(srcdir)/fjalar.am' } > "$tmp" +# mktemp creates the file readable only by its owner; give it the usual +# permissions, as a plain redirection would. +chmod "$(printf '%o' $((0666 & ~0$(umask))))" "$tmp" mv "$tmp" "$output" # An upstream change that the renaming does not handle needs a change to