-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Description
I am building a modified libunwind against a wasm32 target with the RelWithDebugInfo
build type.
When linking I get the following error:
1>wasm-ld : error : wasi-sysroot-17.0/wasi-sysroot/lib\libunwind.a(Unwind-wasm.c.o): undefined symbol: logAPIs
Inside of Unwind-wasm.c there is usage of the _LIBUNWIND_TRACE_API
which is only supposed to use the function logAPIs
in a debug build of libunwind.
I have tracked down the issue looking at the command invocation that CMake is not supplying the NDEBUG
macro by default. This causes the _LIBUNWIND_TRACE_API
macro to be defined causing the inclusion of the logAPIs
symbol.
There is a bit of nonsense inside of the libunwine CMake file that doesn't make a lot of sense to me and I think it might be wrong. The following code block
# Assert
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (LIBUNWIND_ENABLE_ASSERTIONS)
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
if (NOT MSVC)
add_compile_flags(-D_DEBUG)
endif()
# On Release builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_compile_flags(-UNDEBUG)
endif()
else()
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_compile_flags(-DNDEBUG)
endif()
endif()
The statement that CMake automatically defined NDEBUG appears to not always be true. And assuming that might actually be the case. The very last branch statement is supposed to add the NDEBUG flag, but the statement will only add that if the build is a debug build, which seems wrong. Should a debug build actually be defining NDEBUG?
I changed the statement from if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
to if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
and that has resolved the issue of NDEBUG missing from the define statements on the command line.
I'm not aware of any knock on effects that might have and I'm not aware of why libunwind would not have NDEBUG defined for it already by default if that is intended default behavior. But I figure I'd open this issue to raise my observations.
Alternatively, would it make more sense to change the #ifdef
statement in config.h from using NDEBUG
to checking for the presence of DEBUG
instead?
I have an easy workaround that is simply manually defining NDEBUG to appear on the command line through CMAKE_***_FLAGS
.