Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/valgrind-merge.texinfo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions generate-fjalar-makefile.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion generate-patch-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions make-fjalar-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion plan-upgrade-readelf.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions plan-upgrade-valgrind.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
127 changes: 18 additions & 109 deletions valgrind/fjalar/Makefile.am
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = \
Expand All @@ -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 = \
Expand All @@ -138,8 +75,6 @@ endif
# vgpreload_fjalar-<platform>.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
Expand All @@ -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 = \
Expand All @@ -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 = \
Expand All @@ -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
19 changes: 11 additions & 8 deletions valgrind/fjalar/docs/fjalar-www/fjalar_manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h2><a name="getting-started">Getting Started</a></h2>
<li>fjalar/
<ul>
<li>Makefile.am
<li>fjalar.am
<li>fjalar_tool.h
<li>fjalar_include.h
<li>mc_main.c
Expand Down Expand Up @@ -88,26 +89,28 @@ <h2><a name="programming">Creating Fjalar tools</a></h2>
<li>Create a sub-directory in the <tt>valgrind-3/valgrind/fjalar</tt>
directory and place all of your tool's source files in there.

<li>Edit <tt>Makefile.am</tt> in <tt>valgrind-3/valgrind/fjalar</tt>
<li>Edit <tt>fjalar.am</tt> in <tt>valgrind-3/valgrind/fjalar</tt>
to include all the .c files of your tool by adding them to the
list of files assigned to the
<tt>FJALAR_SOURCES_COMMON</tt> variable. (Feel free to tweak
other variables in that file. For instance, you can adjust
<tt>AM_CFLAGS_X86_LINUX</tt> to add optimizations to boost
list of files that are added to the
<tt>FJALAR_SOURCES_COMMON</tt> variable. (Do not edit
<tt>Makefile.am</tt>, which is generated from Memcheck's
<tt>Makefile.am</tt> and includes <tt>fjalar.am</tt>. Feel free to tweak
other variables in <tt>fjalar.am</tt>. For instance, you can remove
the <tt>-O0</tt> from <tt>EXTRA_CFLAGS</tt> 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
<tt>kvasir/kvasir_main.c \</tt> from the file list. In essence, you
are replacing the kvasir tool with your own.

<li>Run <tt>auto-everything.sh</tt> to create a new <tt>Makefile</tt>
from your modified <tt>Makefile.am</tt> and re-compile
from <tt>Makefile.am</tt> and your modified <tt>fjalar.am</tt> and re-compile
everything. You only need to run <tt>auto-everything.sh</tt>
whenever you make a change to <tt>Makefile.am</tt>. (Notice
whenever you make a change to <tt>fjalar.am</tt>. (Notice
Comment thread
coderabbitai[bot] marked this conversation as resolved.
that directly editing <tt>Makefile</tt> and
<tt>Makefile.in</tt> is probably futile because they are
auto-generated from <tt>Makefile.am</tt> every time
<tt>auto-everything.sh</tt> is run.) If you do not
subsequently change <tt>Makefile.am</tt>, you can simply use
subsequently change <tt>fjalar.am</tt>, you can simply use
<tt>make</tt> and <tt>make install</tt> to compile and install,
respectively.

Expand Down
Loading
Loading