This pull request's diff hasn't been prepared yet. Log in with GitHub to have us prepare it for review.

[c++] hide symbols that aren't in the C API #7496

Open
jameslamb opened 11:43pm on October 13, 2026 wants to merge 309 Ξ” into microsoft/lightgbm main from
fix/symbol-visibility

Pull Request Overview

  • Opened on October 14, 2026
  • Status Open
  • Commit count 12 with first commit September 12, 2026

Total Delta

309 Total Diff Delta

Open Days

Open 37 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
25.0 days Authoring 5 commits before pull request opened for review
 
0.0 days Awaiting first review
 
35.0 days Revising work with 7 commits in response to 0 reviews that left 2 comments

Total time for pull request still awaiting merge (longer than repo's target): 60.0 business days

Author avatar

[c++] hide symbols that aren't in the C API

Notes for Reviewers

Contributes to https://github.com/lightgbm-org/LightGBM/issues/7327

By convention, we consider the LGBM_* functions in the C API to be the full public API of lib_lightgbm.{dll,dylib,so}. Everything else is considered an internal implementation detail and not intended to be accessed directly.

I say "by convention" because today there are 1,000+ symbols exported from the shared library on macOS / Linux. On my Mac using clang, I saw:


  • (991) various LightGBM internals, including tons of C++ types and methods

  • (98) intentionally-public LGBM_ functions

  • (59) various symbols from the vendored json11 code

  • (38) _Arrow* symbols from nanoarrow

  • (6) fmt:: symbols from fmt

  • (1) global locking variable from OpenMP (_.gomp_critical_user_.reduction.var)

code to see them (click me)

```shell
cmake -B build -S .
cmake --build build --target _lightgbm -j4
nm -gU ./lib_lightgbm.* | c++filt
```

This proposes limiting the visibility of all those unintentionally-exported symbols.

Benefits of these changes


  • reduced risk of conflicts with other libraries (which can cause segfaults, correctness problems, and other runtime issues)



  • reduced memory needed to load the library

  • faster library loading

  • faster compiled code (e.g. because the compiler can be more aggressive handling inlines because it knows they won't need to be used outside the library)

  • reduced binary size

See "Why is the new C++ visibility support so useful?" at https://gcc.gnu.org/wiki/Visibility for more.

Notes for Reviewers

I have been wanting to do this for a looooong time 😊

Is this safe?

I think so. I had an AI agent check (and I manually spot-checked) all the projects listed in https://github.com/lightgbm-org/LightGBM#external-unofficial-repositories. All but 1 of them either do not call into lib_lightgbm.{dll,dylib,so} at all or do so only through the C API. There's plenty of software that isn't public on GitHub but still... I think we should make this change.

The only exception is https://github.com/microsoft/LightGBM-transform, but that was abandoned 3 years ago, and builds its own copy of lib_lightgbm anyway, AND I'd like to drop support for it soon anyway: #7381

There's more work to do after this

I'd hoped this would fix https://github.com/lightgbm-org/LightGBM/issues/6595 but it doesn't, the reproducible example from there still reproduces.

But still, this will help prevent stuff like that!

References

Comments Threads Pending Resolution

.ci/check-python-dists.sh
39
        pydistcheck \
40
            --inspect \
41
            --ignore 'compiled-objects-have-debug-symbols' \
42 42
            --max-allowed-size-compressed '
4M
' \
43 43
            --max-allowed-size-uncompressed '
10M
' \

Resolved Comment Threads

No resolved comments have been left on this PR.