-
Notifications
You must be signed in to change notification settings - Fork 896
instrument functions: Satisfy bfd inclusion guard #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
instrument functions: Satisfy bfd inclusion guard #1362
Conversation
"adding the required automake command" ? |
My bad, that should be autoconf. |
In fact : autogen.sh |
362a08e
to
2fb994a
Compare
It's not just autoreconf. |
So, the Regarding "Ubuntu-based Linux CI", currently only the Coverity branch (which indeed uses Ubuntu) enables the instrument functions, regular builds do not do regardless of the OS and distribution. To that end, linux-aarch64 runs on Alpine Linux if that provides an easy way to reproduce the problem. Alternatively, it would not be difficult to reinstall linux-amd64 using Fedora, CentOS, AlmaLinux or Rocky Linux. The potential instrument functions test would likely need to be an off-by-default step with an environment variable such as |
The two changes here are separate; the CONTRIBUTING.md change should probably be a separate pull request. |
Not any more; I've changed CONTRIBUTING.md to have more steps, including an autogen.sh step. |
Given that bfd.h is, as far as I can tell, a public header file, exported for use by programs that use libbfd, why on earth would they do that? There is no guarantee, for example, that all code using libbfd even has a config.h file.
I don't know why they did that - or why they didn't push back on the binutils maintainers, if, as I suspect is the case, they found that it caused problems to users of binutils (as opposed to developersof binutils). |
+1 |
2fb994a
to
47cf89f
Compare
My reading of the original binutils PR 14072 (and its follow-ups 14243 and 15920) is that the inclusion guard is designed as some binutils-internal thing, and they didn't/don't expect other projects to directly use/include it. And those who are will need to work around the guard by supply any I deemed it best to just include the existing Rebased, dropped the now-superseeded docs change, and added a comment to the include. Not sure why the |
In 2012 [0] [1] binutils added an inclusion guard to bfd.h, requiring to include the autoconf config.h beforehand. This guard is triggered when enabling instrumentation and development mode: ``` % git clone https://github.com/the-tcpdump-group/tcpdump.git % cd tcpdump % touch .devel % ./autogen.sh % ./configure --enable-instrument-functions --enable-smb --quiet ./mkdep -c gcc -m -M -s . -DHAVE_CONFIG_H -I. fptype.c tcpdump.c print-smb.c smbutil.c instrument-functions.c <libnetdissect src list> In file included from ./instrument-functions.c:18: /usr/include/bfd.h:35:2: error: #error config.h must be included before this header 35 | #error config.h must be included before this header | ^~~~~ ``` Note than this does *not* happen on Debian-based systems, because they remove [2] that guard since 2012 [3]. That's also why the Ubuntu-based Linux CI is not affected. [0] https://sourceware.org/bugzilla/show_bug.cgi?id=14072 [1] https://sourceware.org/git/?p=binutils-gdb.git;a=blobdiff;f=bfd/bfd-in.h;h=ae8149a2;hp=d88bcb6c;hb=df7b86aa;hpb=134fa82e [2] https://salsa.debian.org/toolchain-team/binutils/-/blob/38415eb8/debian/rules#L1045-1048 [3] https://code.launchpad.net/~doko/binutils/pkg-2.23-debian
47cf89f
to
44586d1
Compare
I'm not sure anything needs to be changed. It's more up to the distributions maintainers to fix the problem in bfd.h with the package maintainers, or to apply the same fix as Debian. |
The "How To Use BFD" section of the libbfd documentation says "To use the library, include bfd.h and link with libbfd.a." I don't know who first made an exported library out of it - the binutils developers, one or more random Linux distributions, or somebody else, but whoever it was should have fixed that, either by making bfd.h a usable external header (moving that guard somewhere else), making a new suitable header for use by arbitrary programs using libbfd, or documenting that annoying requirement.
Or, rather, that it can use either autoconf or CMake, and both of them, as used in tcpdump, define a config.h file that defines the
One reason appears to be "the builder for it sometimes gets memory errors or something such as that, causing it to randomly crash". |
No include. |
Tested on Arch Linux with |
Would you mind sharing your reason(ing) for that opinion/decision? I am just trying to understand and learn. Lets forget for a moment that silly inclusion guard, and instead imagine that the Yes, that inclusion guard is questionable, and it sucks having to work around it downstream. But the objections back in 2012 were rejected, and by now I assume it's so accepted and entrenched that upstream will all the more not change it. You can pass the buck to distributions and package maintainers, but that won't help in the (maybe theoretical) scenario when building everything directly from upstream-source. |
As Guy had pointed out: To use the library, include bfd.h and link with libbfd.a. " There is nothing about "config.h" or "optimizations" in the documentation (link above). Thus, there is no reason to add unused macros. "silly inclusion" -> "workround hack" (like the Debian one).
Any links about the reasons of the reject?
Debian maintainers have done the work, Others could do the same... |
The ones I found are already posted above, especially the two follow-ups issues:
|
I guess that was then and this is now, as bfd.h appears to be exported on at least some Linux distributions, and documented in a libbfd manual that is not marked in any obvious way as "binutils developer documentation" rather than "documentation for people using libbfd even in third-party projects".
Anything that defines the appropriate macros, even if it's an in-line Now, if instrument-functions.c uses stuff from config.h or might use it in the future, then it should obviously be included there. If not, then just However, having some project's public headers depend in any way whatsoever on stuff defined in a config.h file is a truly horrible mistake. My experience with one instance of that mistake, as detailed in a long comment in code where I had to deal with said mistake, has left me with an extremely strong distaste for public headers that depend on a config.h file. (The problem there was eventually resolved by somebody replacing the code that depended on zlib's gz io routines with some sample code from zlib to support high-speed random access to gzipped files.) |
Fedora also patches out that inclusion guard since 2012. While Debian does it in the install phase (after compilation), here it is done before building binutils. The comments for the patch in the Fedora package spec reflect the same sentiment from the binutils bugtracker. Fun fact: Nick Clifton, who added that inclusion guard to |
No problem on AlmaLinux 9, no guard in bfd.h. |
No problem on Fedora 42, no guard in bfd.h. |
No problem on Rocky Linux 8, no guard in bfd.h. |
No problem on CentOS Linux 8, no guard in bfd.h. |
Arch Linux maintainers should do the same removal of the guard... |
The distribution-specific patching and the project-specific workaround are often not mutually exclusive, as seems to be in this case: it would work to open a bug report in Arch Linux and to add a
|
I took the issue to the binutils mailing list, lets see what they think of it. |
In 2012 binutils added an inclusion guard to
bfd.h
, requiring to include the automakeconfig.h
beforehand. This guard is triggered when enabling instrumentation and development mode:Note than this does *not* happen on Debian-based systems, because they remove that guard since 2012. That's also why the Ubuntu-based Linux CI is not affected. But on distributions using the vanilla source, like Arch Linux, it prevents the debug build.
Also a small update to the CONTRIBUTING docs, adding the required
automakeautoreconf invocation.