diff --git a/doc/valgrind-merge.texinfo b/doc/valgrind-merge.texinfo index 9b4ddb419..4abdcab6d 100644 --- a/doc/valgrind-merge.texinfo +++ b/doc/valgrind-merge.texinfo @@ -499,6 +499,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..90c67a292 --- /dev/null +++ b/generate-fjalar-makefile.sh @@ -0,0 +1,62 @@ +#!/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 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 +# 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 +# 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. 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 +# 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" +# 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 +# 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 7fe77a4d6..88c8c855f 100755 --- a/generate-patch-files.sh +++ b/generate-patch-files.sh @@ -110,7 +110,9 @@ run_diff() { } run_diff coregrind.patch -ur --unidirectional-new-file -x.git valgrind-old valgrind-new -run_diff memcheck.patch -ur --unidirectional-new-file -x.git -xdocs -xtests valgrind-old/memcheck valgrind-new/memcheck +# generate-fjalar-makefile.sh generates Fjalar's version of +# memcheck/Makefile.am, so memcheck.patch omits it. +run_diff memcheck.patch -ur --unidirectional-new-file -x.git -xdocs -xtests -xMakefile.am valgrind-old/memcheck valgrind-new/memcheck # fjalar/valgrind is usually built in place. To keep build products out of # the Fjalar diffs, diff a copy of the files that git does not ignore. The 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 fcc37b8ef..28425eb64 100644 --- a/plan-upgrade-valgrind.md +++ b/plan-upgrade-valgrind.md @@ -110,8 +110,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 `$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`, + 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/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/