Skip to content

fix: Move gnulib/lib/error.h to gnulib-error.h#23

Open
blorente wants to merge 5 commits intojmillikin:trunkfrom
blorente:blorente/add-repo-name-replacement
Open

fix: Move gnulib/lib/error.h to gnulib-error.h#23
blorente wants to merge 5 commits intojmillikin:trunkfrom
blorente:blorente/add-repo-name-replacement

Conversation

@blorente
Copy link

This is just an early attempt, you can probably think of a better way to fix it.

The problem I'm trying to solve: For good reasons, our gcc toolchain includes libc6 with -isystem on compilation. libc6 has a header, called error.h, which is guarded with the guard _ERROR_H.
M4's gnulib also has a header called error.h with the same guard. Because libc6 comes before gnulib in the -isystem inclusion order, we don't get the symbols from gnulib's error.h. Fun.

The solution we're using in the meantime is to add -I <path/to/gnulib> to the extra copts, because -I resolves as "last one wins", so gnulib gets picked up first: blorente@6238498#diff-64fffd7f2fee0a5a182cc297f3c260f7820729dd4f2855c52aeac25fa5d65271R37-R46

We'd like to avoid maintaining this patch, and instead rely on extra_copts. However, because we shouldn't depend on canonical names, we need to inject the repository name.

As I said, this is just an early attempt, happy to modify it to whatever suits you.

@jmillikin
Copy link
Owner

I'm not opposed to the feature as stated, but for the specific case of gnulib shadowing the global system <error.h> it might just be easier to rename that file to gnulib-error.h within the m4 build and patch the #include "error.h" lines accordingly. It can go onto the pile of other horrible gnulib build patches.

That approach would also be easier to maintain from a cross-platform perspective, since it would work the same regardless of compiler or system libc.

Note that error.h is being included with #include "error.h" and not #include <error.h>, and according to the GCC documentation I would expect the gnulib version of that header to be picked up before the libc6 version (since -iquote dirs are searched before -isystem). It's possible there are other headers that are also getting shadowed.

@blorente
Copy link
Author

Note that error.h is being included with #include "error.h" and not #include <error.h>, and according to the GCC documentation I would expect the gnulib version of that header to be picked up before the libc6 version (since -iquote dirs are searched before -isystem).

I don't see the same thing, In my compilation gnulib is included as an -isystem:

 -isystem external/rules_m4++m4_repository_ext+m4_v1.4.18__cfg02A699F7/gnulib/config-linux -isystem bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_m4++m4_repository_ext+m4_v1.4.18__cfg02A699F7/gnulib/config-linux -isystem bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_m4++m4_repository_ext+m4_v1.4.18__cfg02A699F7/gnulib/_virtual_includes/gnulib 

Whatever the reason, I think the solution you presented is worth a shot. The risk there is that the headers from libc6 introduce some symbol that they shouldn't, but it seems like a small risk.

@blorente blorente force-pushed the blorente/add-repo-name-replacement branch from 774f5ac to 4fa3d19 Compare March 26, 2026 14:27
@blorente blorente force-pushed the blorente/add-repo-name-replacement branch from 4fa3d19 to 17408f9 Compare March 26, 2026 14:28
@blorente
Copy link
Author

blorente commented Mar 26, 2026

@jmillikin I've made the changes and confirmed that it works with our use case. I'll fix the CI failures in a moment, but please let me know what you think.
I've also added a .bazelversion file, because the repo didn't work on Bazel 9 for me.

@blorente blorente changed the title feat: Add {REPO_NAME} template to extra_copts fix: Move gnulib/lib/error.h to gnulib-error.h Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants