Skip to content

Guard ABSL_HAVE_ELF_MEM_IMAGE on <link.h> availability, not a deny-list - #2156

Open
afonsojanu wants to merge 1 commit into
abseil:masterfrom
afonsojanu:fix/elf-mem-image-has-include-link-h
Open

Guard ABSL_HAVE_ELF_MEM_IMAGE on <link.h> availability, not a deny-list#2156
afonsojanu wants to merge 1 commit into
abseil:masterfrom
afonsojanu:fix/elf-mem-image-has-include-link-h

Conversation

@afonsojanu

Copy link
Copy Markdown

Fixes #2153.

ABSL_HAVE_ELF_MEM_IMAGE is turned on for every __ELF__ target except an explicit deny-list, and once it's on, elf_mem_image.h unconditionally 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 is arm-none-eabi-g++ with newlib) hits a fatal link.h: No such file or directory before 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 in absl/base/config.h).

Verified two ways since I don't have the reporter's exact arm-none-eabi-g++/newlib setup handy:

  • Isolated the guard logic in a standalone header with a fake include path that has no link.h: the current code reproduces the exact reported error, the fix compiles clean and simply doesn't define ABSL_HAVE_ELF_MEM_IMAGE.
  • Same setup but with a link.h present on the include path: confirms the fix still defines ABSL_HAVE_ELF_MEM_IMAGE and 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.

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.
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.

[Bug]: ABSL_HAVE_ELF_MEM_IMAGE assumes every ELF target ships <link.h>

1 participant