Skip to content

Make the libdw dependency of C++ backtraces optional - #6

Open
PerryLink wants to merge 1 commit into
deepseek-ai:mainfrom
PerryLink:fix/optional-libdw-dependency
Open

PerryLink wants to merge 1 commit into
deepseek-ai:mainfrom
PerryLink:fix/optional-libdw-dependency

Conversation

@PerryLink

Copy link
Copy Markdown

DeepJIT is header-only, and 17 of its 27 public headers transitively include include/deep_jit/utils/exception.hpp. That file unconditionally did #include <elfutils/libdwfl.h>, so on a machine that has the libdw runtime but not the elfutils development headers, no DeepJIT header compiles — including tests/test_exception.py, the only test that does not need a GPU. Stock Ubuntu 24.04 is exactly that case: libdw1t64 is installed, libdw-dev is not, and the requirement is not mentioned anywhere in the README.

Reproduction with the same flags as validate_header_self_containment in tests/test_cuda.py (Ubuntu 24.04.4, g++ 14.4.0, no libdw-dev):

include/deep_jit/utils/exception.hpp:3:10: fatal error: elfutils/libdwfl.h: No such file or directory
    3 | #include <elfutils/libdwfl.h>
      |          ^~~~~~~~~~~~~~~~~~~~

Sweeping include/deep_jit/**/*.hpp (excluding backend/ascend/) the same way, 13 headers fail on that single line.

The library already treats libdw as optional at runtime — DwflApi's constructor does dlopen("libdw.so.1", RTLD_LAZY | RTLD_LOCAL) and valid() gates every use of the loaded symbols. Only the header was an unconditional requirement.

This makes the include conditional on __has_include and supplies a no-op DwflApi when the headers are absent, so backtraces fall back to the existing dladdr path. The same sweep after the change:

PASS=17 FAIL=5
    0 failures on elfutils/libdwfl.h
    the remaining 5 are this machine lacking cusparse.h / Python.h, unrelated

Backtraces on a header-less machine keep demangled function names and the file:line in the panic message, and report ??:0 per frame. tests/test_exception.py needs no change — it still sees panic_leaf, panic_middle, panic_entry and .cpp: in the message. On a machine with libdw-dev the guarded branch is byte-identical to before, so nothing changes there; I could not build that variant locally because installing libdw-dev requires root.

exception.hpp unconditionally did `#include <elfutils/libdwfl.h>`, which
makes the elfutils development headers a hard build requirement for every
consumer even though the library is already loaded at runtime via
`dlopen("libdw.so.1")`. On a machine with the libdw runtime but without
those headers -- stock Ubuntu 24.04 ships libdw1t64 but not libdw-dev --
no DeepJIT header compiles at all, including tests/test_exception.py.

Guard the include with __has_include and provide a no-op DwflApi when the
headers are absent, so backtraces fall back to the existing dladdr path.
Machines that have the headers are unaffected.
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.

1 participant