Skip to content

Conversation

@mrdrivingduck
Copy link
Contributor

Purpose

When glog is built on systems with libunwind installed, it automatically detects and links against libunwind for stack unwinding support. However, the INTERFACE_LINK_LIBRARIES property was not set, causing undefined reference errors when linking static libraries:

/usr/bin/ld: ../../glog_ep-install/lib/libglog.a(stacktrace.cc.o): in function `google::glog_internal_namespace_::GetStackTrace(void**, int, int)':
stacktrace.cc:(.text+0x68): undefined reference to `_Ux86_64_getcontext'
/usr/bin/ld: stacktrace.cc:(.text+0x73): undefined reference to `_ULx86_64_init_local'
/usr/bin/ld: stacktrace.cc:(.text+0xa1): undefined reference to `_ULx86_64_get_reg'
/usr/bin/ld: stacktrace.cc:(.text+0xb4): undefined reference to `_ULx86_64_step'
/usr/bin/ld: stacktrace.cc:(.text+0xf7): undefined reference to `_ULx86_64_step'
collect2: error: ld returned 1 exit status

This change dynamically detects libunwind availability and adds it to glog's link interface only when present, ensuring portability across different build environments.

According to the docs of glog, libunwind is recommended.

Tests

For system without libunwind:

$ ldd ./usr/local/lib64/libpaimon.so 
        linux-vdso.so.1 (0x00007fff863ab000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f0b897cf000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f0b87c10000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f0b87aca000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f0b897b4000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0b87aa8000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0b878cc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f0b897ee000)

For system with libunwind:

$ ldd ./usr/local/lib64/libpaimon.so
        linux-vdso.so.1 (0x00007ffcf1b3e000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f52b4a12000)
        libunwind.so.8 => /lib64/libunwind.so.8 (0x00007f52b49f8000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f52b2e10000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f52b2cca000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f52b49dd000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f52b49bb000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f52b2aee000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f52b4a31000)

API and Format

Documentation

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes linking errors that occur when glog is built on systems with libunwind installed. When libunwind is present, glog automatically links against it for stack unwinding support, but the INTERFACE_LINK_LIBRARIES property was not being set, causing undefined reference errors during static library linking.

Changes:

  • Added dynamic detection of libunwind availability using CMake's find_library
  • Conditionally adds libunwind to glog's interface link libraries when present
  • Ensures portability across systems with and without libunwind

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1015 to 1019
set_property(TARGET glog
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES unwind)
endif()
endmacro()
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the variable ${LIBUNWIND_LIBRARY} instead of the bare library name "unwind". Since find_library stores the full path to the library in LIBUNWIND_LIBRARY, using ${LIBUNWIND_LIBRARY} ensures the exact library that was detected is linked. Alternatively, for better consistency with the codebase style at lines 474, 592, and 840, consider using target_link_libraries(glog INTERFACE ${LIBUNWIND_LIBRARY}) instead of set_property.

Suggested change
set_property(TARGET glog
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES unwind)
endif()
endmacro()
target_link_libraries(glog INTERFACE ${LIBUNWIND_LIBRARY})
endif()
endmacro()
endmacro()

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@zjw1111 zjw1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

When glog is built on systems with libunwind installed, it automatically
detects and links against libunwind for stack unwinding support. However,
the INTERFACE_LINK_LIBRARIES property was not set, causing undefined
reference errors (e.g., _Ux86_64_getcontext) when linking static libraries.

This change dynamically detects libunwind availability and adds it to
glog's link interface only when present, ensuring portability across
different build environments.
@mrdrivingduck
Copy link
Contributor Author

Seems to be broken by main branch...

@zjw1111
Copy link
Collaborator

zjw1111 commented Jan 19, 2026

Seems to be broken by main branch...

Thanks to find this problem! It's caused by a random number case, we will fix this. cc @lxy-9602

@lxy-9602 lxy-9602 merged commit d95bfae into alibaba:main Jan 19, 2026
8 of 9 checks passed
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.

3 participants