Skip to content

Conversation

@at445
Copy link

@at445 at445 commented Jan 31, 2026

Summary

  • Detect and link libtinfo (terminfo) explicitly for cpptest and tvm_allvisible when found.
  • Prevents link-time failures for test binaries when llvm-config does not export -ltinfo, which can happen with some LLVM packages (observed with LLVM 18 in Ubuntu 24.04.3 LTS (x86_64-linux-gnu) ).

Problem

  • With USE_LLVM=ON, the build produced undefined references to terminfo symbols (e.g. tgetstr, setupterm) when linking cpptest. ldd /usr/lib/llvm-18/lib/libLLVM-18.so shows it depends on libedit and libtinfo, but llvm-config --libs --link-static did not include -ltinfo, so CMake didn't add it to the final link.

Change

  • Minimal, portable CMake change:
    • find_library(TINFO_LIB tinfo) and, if found, target_link_libraries(cpptest PRIVATE ${TINFO_LIB}) and, when present, target_link_libraries(tvm_allvisible PRIVATE ${TINFO_LIB}).

Reproduction

  • Steps:
    1. cmake -S . -B build-llvm_ON-hide_OFF -DUSE_LLVM=ON -DHIDE_PRIVATE_SYMBOLS=OFF -DUSE_GTEST=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
    2. cmake --build build-llvm_ON-hide_OFF --target cpptest
  • Expected:
    • Before: link errors referencing terminfo symbols and no cpptest binary produced.
    • After: cpptest links and is produced.

Rationale

  • Safer and more portable than relying on consumers to fix package-level llvm-config exports.
  • No behavioral changes unless tinfo is required and available.

Logs

…libedit\n\nDetect and link libtinfo explicitly to avoid missing terminfo symbols when llvm-config does not export -ltinfo. This fixes cpptest link failures observed with USE_LLVM=ON on some systems (e.g. LLVM 18 packaged without propagating terminfo).\n\nReproduction: cmake -S . -B build-llvm_ON-hide_OFF -DUSE_LLVM=ON -DHIDE_PRIVATE_SYMBOLS=OFF -DUSE_GTEST=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build build-llvm_ON-hide_OFF --target cpptest\n\nVerified: cpptest now links successfully when libtinfo is present on the system and was added as a conditional link target.,
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @at445, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a specific build issue encountered when compiling with LLVM, particularly affecting the cpptest and tvm_allvisible targets. It introduces a robust CMake-based solution to explicitly locate and link the libtinfo library, which is sometimes a missing dependency when llvm-config fails to export it. This ensures that these targets can link successfully across various LLVM configurations, enhancing the overall stability of the build system.

Highlights

  • Terminfo Linking: Explicitly links libtinfo (terminfo) to cpptest and tvm_allvisible targets in CMake when detected.
  • Build Fix: Resolves link-time failures for test binaries, specifically cpptest, that occur when llvm-config does not export -ltinfo, as observed with LLVM 18 on Ubuntu.
  • Portability: Improves build portability and reliability by not relying solely on llvm-config to provide all necessary link flags.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds logic to link libtinfo when building tests with LLVM to fix link-time failures on some systems. The change is correct in principle. My review includes a suggestion to improve the implementation by making the logic conditional on LLVM being used and by using a more portable CMake command to find the required library. This will improve maintainability and portability.

# Ensure we link terminfo when required by LLVM / libedit at link time.
find_package(Curses)
if(CURSES_FOUND)
message(STATUS "Found Curses/terminfo library: ${CURSES_LIBRARIES}")
Copy link
Member

Choose a reason for hiding this comment

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

i think llvm only requires tinfo but not curses library? we do want to avoid dependency bloat in this case

Copy link
Member

Choose a reason for hiding this comment

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

The dependency should also be specified and captured through llvm config in findllm instead of here

Copy link
Author

Choose a reason for hiding this comment

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

i think llvm only requires tinfo but not curses library? we do want to avoid dependency bloat in this case
this is suggested by gemini-code-assist, but I could switch back tinfo if you insist ^_^

image

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, tqchen raises a good point about dependency bloat. While find_package(Curses) often works because libtinfo is frequently bundled with ncurses, explicitly searching for libtinfo is more precise if that's the only required dependency. This helps avoid pulling in unnecessary parts of the Curses library.

My initial suggestion aimed for a common, robust way to find terminal-related libraries, but find_library(TINFO_LIB tinfo) directly addresses the specific missing dependency (libtinfo) as indicated by your problem description. This is a medium severity suggestion to improve precision and minimize dependencies.

Regarding tqchen's second point, ideally, llvm-config should provide all necessary linker flags for its dependencies. If it doesn't include -ltinfo on certain systems, then explicitly finding and linking it as a workaround is a pragmatic approach for now. The long-term solution would involve ensuring FindLLVM.cmake or the llvm-config output itself correctly reports this dependency.

Suggested change
message(STATUS "Found Curses/terminfo library: ${CURSES_LIBRARIES}")
find_library(TINFO_LIB tinfo)
if(TINFO_LIB)
message(STATUS "Found terminfo library: ${TINFO_LIB}")
target_link_libraries(cpptest PRIVATE ${TINFO_LIB})
if(TARGET tvm_allvisible)
target_link_libraries(tvm_allvisible PRIVATE ${TINFO_LIB})
endif()
endif()

Copy link
Author

Choose a reason for hiding this comment

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

The dependency should also be specified and captured through llvm config in findllm instead of here

you are right! I will rethink about it

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.

2 participants