[PATCH] libctf,libsframe: remove include of config.h
Andrew Burgess
aburgess@redhat.com
Tue Aug 11 16:18:11 GMT 2026
While testing the upcoming GDB 18 release an issue was reported
relating to libsframe/sframe.c and its use of libctf/swap.h. The
original report can be found here:
https://inbox.sourceware.org/gdb-patches/865x1j1z61.fsf@gnu.org
What happens is that during the first build of GDB everything builds
fine without any warnings. But if for any reason we need to recompile
libsframe/sframe.c then we would see compiler warnings like this:
CC libsframe_la-sframe.lo
In file included from ./../libctf/swap.h:23,
from sframe.c:27:
./../libctf/config.h:127: warning: "PACKAGE" redefined
127 | #define PACKAGE "libctf"
|
This is just one of the warnings, we actually get many similar
warnings for the various things defined in libctf/config.h.
After investigation I discovered that this issue only occurs when
building in the source tree.
Here's what happens, starting from a clean source tree.
>From Makefile.def we see that the 'all-bfd' target depends on
'all-libsframe', and the 'configure-libctf' target depends on
'all-bfd'. The dependency chain then is:
all-libsframe → all-bfd → configure-libctf
This means that, when libsframe is first built libctf/config.h will
not yet have been created by the configure-libctf build target. Due
to the include search paths added to the gcc compilation command, the
include of config.h from libctf/swap.h will be satisfied by
libsframe/config.h.
If we allow the 'configure-libctf' target to complete then
libctf/config.h will be created.
If we now recompile libsframe/sframe.c then we run into the problem,
sframe.c includes config.h which will be satisfied by
libsframe/config.h, and then sframe.c includes libctf/swap.h which
also includes config.h.
However, now libctf/config.h exists, and this is used to satisfy the
include from swap.h, this is a different config.h than was used in the
original build, and conflicts with the config.h included from
sframe.c.
Here are exact steps to reproduce:
cd /path/to/binutils-gdb/src
./configure
make configure-libctf
touch libsframe/sframe.c
make all-libsframe
I considered two possible fixes for this issue.
Currently the includes are written as: #include "config.h". The use
of quotes around the file name mean gcc will first check the directory
of the including file and will then check the paths passed using -I to
the compiler. This is why we find libctf/config.h.
If we switch to: #include <config.h> then we skip the check of the
source directory, and go straight to checking the -I paths. When
compiling libsframe/sframe.c this will mean we find libsframe/config.h
first, which does indeed fix the issue.
However, in most cases we would expect the main source file to already
pull in config.h, so it feels easier to just make that the requirement
and remove the include of config.h from libctf/swap.h.
Removing the include of config.h seemed risky so I looked at all the
files currently pulling in libctf/swap.h, there are not many:
libctf/ctf-endian.h:
- Includes config.h before including swap.h
libctf/ctf-open-bfd.c:
libctf/ctf-open.c:
- Both include ctf-impl.h, which includes config.h before including
swap.h
libsframe/sframe.c:
- This is our problem case, pulls in its own local config.h before
including libctf/swap.h.
So I think making this change should be safe, and resolves the
warnings when performing an in tree build.
---
libctf/swap.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/libctf/swap.h b/libctf/swap.h
index 15cc61c8b59..d23f5895ad2 100644
--- a/libctf/swap.h
+++ b/libctf/swap.h
@@ -20,7 +20,6 @@
#ifndef _CTF_SWAP_H
#define _CTF_SWAP_H
-#include "config.h"
#include <stdint.h>
#include <assert.h>
base-commit: a80fede20bc1330eca5e419392c6595bb3a6ac1d
--
2.25.4
More information about the Binutils
mailing list