Pull Request Overview
- Opened on October 14, 2026
- Status Open
- Commit count 12 with first commit September 12, 2026
Total Delta
Open Days
Test Delta
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
[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
json11code - (38)
_Arrow*symbols fromnanoarrow - (6)
fmt::symbols fromfmt - (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)
- e.g. no risk of
lib_lightgbm'sfmt::symbols being found at load time by some other library that was compiled against a different version offmt:: - example (not from LightGBM, just showing that this is real thing): https://github.com/NVIDIA/cudf/pull/15483#discussion_r1670892743
- e.g. no risk of
- 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
Resolved Comment Threads
No resolved comments have been left on this PR.