Guard ABSL_HAVE_ELF_MEM_IMAGE on <link.h> availability, not a deny-list - #2156
Open
afonsojanu wants to merge 1 commit into
Open
Guard ABSL_HAVE_ELF_MEM_IMAGE on <link.h> availability, not a deny-list#2156afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
Any __ELF__ target without a real dynamic loader has no <link.h>, and this header unconditionally includes it once ABSL_HAVE_ELF_MEM_IMAGE is turned on. Bare-metal ELF toolchains such as arm-none-eabi-g++ with newlib produce ELF objects but never ship link.h, so the build fails with a fatal "link.h: No such file or directory" before it even gets to using anything from it. The existing guard tries to work around this with a deny-list of platforms (__QNX__, __asmjs__, __wasm__, __HAIKU__, __VXWORKS__, __hexagon__, __XTENSA__), each added one at a time as it hit the same wall. Every new bare-metal ELF target has to send its own PR to add itself to the list. Added a __has_include(<link.h>) check alongside the existing guard, so the feature is only enabled where the header it depends on actually exists, rather than only where we remembered to exclude. Kept a fallback for preprocessors that predate __has_include.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2153.
ABSL_HAVE_ELF_MEM_IMAGEis turned on for every__ELF__target except an explicit deny-list, and once it's on,elf_mem_image.hunconditionally includes<link.h>. That header is a glibc/dynamic-linker thing, not part of the ELF format itself, so any bare-metal ELF toolchain without a real dynamic loader (the reported case isarm-none-eabi-g++with newlib) hits a fatallink.h: No such file or directorybefore compilation even gets to using anything from it.The deny-list (
__QNX__,__asmjs__,__wasm__,__HAIKU__,__VXWORKS__,__hexagon__,__XTENSA__) is really just a running list of platforms that hit this one at a time, each needing its own PR to add itself.Added
__has_include(<link.h>)to the guard so the feature turns on based on whether the header it needs is actually there, with a fallback for preprocessors that don't support__has_include(there's already a precedent for this inabsl/base/config.h).Verified two ways since I don't have the reporter's exact
arm-none-eabi-g++/newlib setup handy:link.h: the current code reproduces the exact reported error, the fix compiles clean and simply doesn't defineABSL_HAVE_ELF_MEM_IMAGE.link.hpresent on the include path: confirms the fix still definesABSL_HAVE_ELF_MEM_IMAGEand includes the header, so real ELF/glibc targets are unaffected.I didn't touch the deny-list itself, it's harmless now (each of those platforms also lacks
link.h, so the new check alone would already exclude them), but removing it felt like a separate cleanup from the actual bug fix.