Bug 505233 - Build rules in memcheck apply CFLAGS after customizations made by configure, leading to unwanted configuration or errors
Summary: Build rules in memcheck apply CFLAGS after customizations made by configure, ...
Status: RESOLVED NOT A BUG
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (other bugs)
Version First Reported In: 3.25 GIT
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-05 12:55 UTC by James E. King III
Modified: 2025-06-05 16:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James E. King III 2025-06-05 12:55:30 UTC
In an environment where CFLAGS is set by default to include `-fstack-protector-strong`, a build of Valgrind 3.25.1 will fail because the memcheck configure-generated build places $(CFLAGS) after $(memcheck_amd64_linux_CFLAGS), causing stack protector to be enabled; for example this excerpt from the generated Makefile in memcheck:

```
memcheck_amd64_linux-mc_main_asm.obj: mc_main_asm.c
    $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(memcheck_amd64_linux_CPPFLAGS) $(CPPFLAGS) $(memcheck_amd64_linux_CFLAGS) $(CFLAGS) -MT memcheck_amd64_linux-mc_main_asm.obj -MD -MP -MF $(DEPDIR)/memcheck_amd64_linux-mc_main_asm.Tpo -c -o memcheck_amd64_linux-mc_main_asm.obj `if test -f 'mc_main_asm.c'; then $(CYGPATH_W) 'mc_main_asm.c'; else $(CYGPATH_W) '$(srcdir)/mc_main_asm.c'; fi`
    $(AM_V_at)$(am__mv) $(DEPDIR)/memcheck_amd64_linux-mc_main_asm.Tpo $(DEPDIR)/memcheck_amd64_linux-mc_main_asm.Po
```
Comment 1 Paul Floyd 2025-06-05 16:17:31 UTC
This is how automake works

https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

in particular

"The reason ‘$(CPPFLAGS)’ appears after ‘$(AM_CPPFLAGS)’ or ‘$(mumble_CPPFLAGS)’ in the compile command is that users should have the last say. In the example above, the desire is for the ‘CXXFLAGS=-O0’ to supersede any other switch from AM_CXXFLAGS or mumble_CXXFLAGS. "

This also applies to CFLAGS. Realistically I can't see what we can do. clang --help outputs over 1000 lines that start with spaces then a '-', a rough indication of the number of supported flags. How could we filter out all of the ones that we don't like?