Skip to content

fix(openswath): resolve duplicate TLS init symbol on macOS clang - #9223

Merged
timosachsenberg merged 4 commits into
developfrom
fix/picker-pool-tls-dup-symbol
Apr 27, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
fix/picker-pool-tls-dup-symbol

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes duplicate symbol 'thread-local initialization routine for OpenMS::g_picker_pool_shared' #9222: duplicate symbol 'thread-local initialization routine for OpenMS::g_picker_pool_shared' on macOS arm64 introduced by (osw): Speed up OpenSwathWorkflow for Large Libraries #9190.
  • Root cause: PickerPoolShared g_picker_pool_shared was declared inline thread_local at namespace scope in MRMTransitionGroupPicker.h. The type has a non-trivial constructor (vector members), so the compiler must emit a thread-local initialization wrapper. macOS Mach-O / clang does not always emit that wrapper as weak/COMDAT for inline thread_local, so every translation unit including the header (MRMFeatureFinderScoring.cpp, OpenSwathWorkflow.cpp, …) defined its own copy and the linker rejected the duplicates.
  • Fix: standard pattern — extern thread_local declaration in the header, single definition in MRMTransitionGroupPicker.cpp. One TU emits the init wrapper, semantics unchanged (one instance per thread, lazy init on first access), no callsite changes.

Test plan

  • Linux build clean: cmake --build OpenMS-build --target OpenMS → [100%] Built target OpenMS
  • macOS arm64 CI link succeeds (was failing pre-fix)
  • Existing OpenSwath tests still green

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal thread-safe resource management for enhanced library compatibility and stability.

`PickerPoolShared g_picker_pool_shared` was declared `inline thread_local`
at namespace scope in MRMTransitionGroupPicker.h. Because the type has a
non-trivial constructor (vector members), the compiler must emit a
thread-local initialization wrapper. macOS Mach-O / clang does not always
emit that wrapper as weak/COMDAT for `inline thread_local`, so every TU
that transitively included the header (MRMFeatureFinderScoring.cpp,
OpenSwathWorkflow.cpp, ...) defined its own copy and the linker rejected
the duplicates on arm64.

Switch to the standard pattern: an `extern thread_local` declaration in
the header and a single definition in MRMTransitionGroupPicker.cpp. One
TU emits the init wrapper, semantics are unchanged (one instance per
thread, lazy init on first access), no callsite changes.

Fixes #9222

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The change replaces a namespace-scope inline thread_local variable with a function-local thread_local instance accessed via an inline accessor function. This refactoring moves the thread-local storage definition from global to function scope to resolve duplicate symbol linker errors across translation units while maintaining per-thread semantics.

Changes

Cohort / File(s) Summary
Thread-Local Pool Accessor Refactor
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h
Changed g_picker_pool_shared from a namespace-scope inline thread_local variable to a function-local thread_local instance via an inline accessor function. All existing call sites updated to invoke the accessor before accessing pool members (picked_chroms, all_ints, mean_shapes, mean_coel, left_borders, right_borders).

Poem

🐰 A tangled thread unraveled fast,
Duplicate symbols broke at last,
Now scoped within the function's keep,
Each thread gets storage, safe and deep! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: fixing a duplicate TLS initialization symbol issue on macOS clang.
Linked Issues check ✅ Passed The code changes directly address the linked issue #9222 by replacing inline thread_local with an accessor function that returns function-local thread_local, eliminating duplicate TLS init symbols.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to resolving the duplicate TLS initialization symbol issue on macOS; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/picker-pool-tls-dup-symbol

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h`:
- Around line 74-78: Add the OPENMS_DLLAPI export macro to the header
declaration of the thread-local shared pool: change the header's declaration of
g_picker_pool_shared to use "extern OPENMS_DLLAPI thread_local PickerPoolShared
g_picker_pool_shared" so downstream consumers (e.g., pickTransitionGroup and
computeQuality_) can import the symbol from the DLL; leave the definition in
MRMTransitionGroupPicker.cpp as just "thread_local PickerPoolShared
g_picker_pool_shared" (no OPENMS_DLLAPI) to keep a single definition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3487f42e-be13-4662-b130-fe27f655015f

📥 Commits

Reviewing files that changed from the base of the PR and between b9c67c9 and 361558d.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h
  • src/openms/source/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.cpp

The previous commit moved `g_picker_pool_shared` to a single TU
definition, but `-fvisibility=hidden` keeps the symbol out of
libOpenMS's dynamic symbol table. The header has inline template
member functions (`pickTransitionGroup`, `computeQuality_`) that
reference the variable, so any consumer that instantiates them in
its own translation unit (TOPP tools like `src/topp/MRMTransitionGroupPicker.cpp`,
class tests like `MRMTransitionGroupPicker_test.cpp`) emits an
external relocation that the linker cannot resolve from libOpenMS.

Annotate the declaration and definition with OPENMS_DLLAPI so the
symbol and its TLS init wrapper are exported with default visibility.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Pushed follow-up: extern thread_local alone wasn't enough on Linux because -fvisibility=hidden keeps the symbol out of libOpenMS's dynamic symbol table. The header has inline template member functions (pickTransitionGroup, computeQuality_) that reference g_picker_pool_shared, so consumers that instantiate them in another target (src/topp/MRMTransitionGroupPicker.cpp, MRMTransitionGroupPicker_test.cpp, …) emit an external relocation that the linker can't resolve. Added OPENMS_DLLAPI to declaration and definition; reproduced the MRMTransitionGroupPicker_test link failure locally and confirmed it links after the change. nm now shows OpenMS::g_picker_pool_shared and its TLS init function as global default-visibility entries in libOpenMS.so.

`extern OPENMS_DLLAPI thread_local` resolved the macOS dup-symbol and
the Linux hidden-visibility issue, but MSVC still failed with LNK2019
when linking the TOPP MRMTransitionGroupPicker tool: MSVC does not
reliably support `__declspec(dllexport)` on `thread_local` variables
of a non-trivial type.

Replace the namespace-scope variable with a function-local
`thread_local static` returned by an inline accessor. Function-local
statics are single-instance per program by language guarantee and
don't need a DLL export annotation, so this works uniformly on macOS
clang, Linux gcc/clang, and MSVC. Updated the six callsites in the
header to use `g_picker_pool_shared()` and verified
`MRMTransitionGroupPicker_test` plus the four TOPP tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Pushed b11b7fd4c8: Windows MSVC was still failing with LNK2019 linking the TOPP MRMTransitionGroupPicker tool — MSVC does not reliably support __declspec(dllexport) on a thread_local variable of a non-trivial type.

Replaced the namespace-scope extern OPENMS_DLLAPI thread_local with a function-local thread_local static returned by an inline accessor (Meyers'-singleton style). That avoids cross-DLL TLS export entirely and gives uniform behavior on macOS clang, Linux gcc/clang, and MSVC. Updated the six callsites in the header (most chained off a single auto &pool = g_picker_pool_shared();) and confirmed locally that MRMTransitionGroupPicker_test and all four TOPP_MRMTransitionGroupPicker_test_* tests still pass.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h (1)

80-80: Optional: rename to follow lowerCamelCase now that it's a function.

The g_ prefix and snake_case made sense when this was a namespace-scope global variable. As a function (effectively the only API for the pool), pickerPoolShared() (or similar) would align with the OpenMS "Methods must use lowerCamelCase" convention used elsewhere in this very file (e.g., areaBackgroundLevel(), findWidestPeakIndices). Skip if the small callsite churn isn't worth it.

As per coding guidelines: "Methods must use lowerCamelCase".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h` at
line 80, Rename the function g_picker_pool_shared() to follow lowerCamelCase
(suggested name: pickerPoolShared()) and update its declaration and definition
(the inline function returning PickerPoolShared&) along with all callsites;
ensure you replace exact symbol g_picker_pool_shared with pickerPoolShared in
headers and sources, update any forward declarations or includes that reference
it, and run the build/tests to confirm no linkage or API breakages — keep the
return type (PickerPoolShared&) and behavior unchanged to avoid semantic
changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h`:
- Around line 74-84: Add a Doxygen comment with an `@brief` for the public
accessor g_picker_pool_shared() describing its purpose (returns the per-thread
PickerPoolShared instance used by the MRMTransitionGroupPicker pool system) and
keep the existing rationale comment as detailed remarks if desired; place the
comment immediately above the inline PickerPoolShared& g_picker_pool_shared()
function and reference the function name and the PickerPoolShared type in the
doc block so it satisfies the header's public API documentation guidelines.

---

Nitpick comments:
In `@src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h`:
- Line 80: Rename the function g_picker_pool_shared() to follow lowerCamelCase
(suggested name: pickerPoolShared()) and update its declaration and definition
(the inline function returning PickerPoolShared&) along with all callsites;
ensure you replace exact symbol g_picker_pool_shared with pickerPoolShared in
headers and sources, update any forward declarations or includes that reference
it, and run the build/tests to confirm no linkage or API breakages — keep the
return type (PickerPoolShared&) and behavior unchanged to avoid semantic
changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1599d62e-98ab-4250-886e-e258dd8f975f

📥 Commits

Reviewing files that changed from the base of the PR and between c22ccec and b11b7fd.

📒 Files selected for processing (1)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h

Comment on lines +74 to +84
// Per-thread instance of the shared pools. Wrapped in a function so the
// function-local `thread_local static` is the single point of definition
// across all translation units / DLLs and we don't have to deal with
// platform-specific behavior of namespace-scope `inline thread_local`
// (duplicate TLS init wrapper on macOS clang) or `extern thread_local`
// exported from a DLL (MSVC LNK2019 on TOPP-tool consumers).
inline PickerPoolShared& g_picker_pool_shared()
{
thread_local PickerPoolShared instance;
return instance;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a Doxygen @brief for the new public accessor.

The header sits under src/openms/include/OpenMS/... and the accessor is part of the public API of this header. The comment block explains rationale well but lacks the required @brief tag.

📝 Proposed doc tweak
-  // Per-thread instance of the shared pools. Wrapped in a function so the
-  // function-local `thread_local static` is the single point of definition
-  // across all translation units / DLLs and we don't have to deal with
-  // platform-specific behavior of namespace-scope `inline thread_local`
-  // (duplicate TLS init wrapper on macOS clang) or `extern thread_local`
-  // exported from a DLL (MSVC LNK2019 on TOPP-tool consumers).
+  /**
+    `@brief` Accessor for the per-thread shared pool used by MRMTransitionGroupPicker.
+
+    Wrapped in an inline function so the function-local `thread_local` instance
+    is the single point of definition across all translation units / DLLs.
+    This avoids platform-specific issues with namespace-scope
+    `inline thread_local` (duplicate TLS init wrapper on macOS clang) and
+    `extern thread_local` exported from a DLL (MSVC LNK2019 on TOPP-tool
+    consumers).
+
+    `@return` Reference to the calling thread's `PickerPoolShared` instance.
+  */
   inline PickerPoolShared& g_picker_pool_shared()

As per coding guidelines: src/openms/include/OpenMS/**/*.h — "Add Doxygen comments for new public methods and classes" and "Always use @brief for class and method documentation".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h`
around lines 74 - 84, Add a Doxygen comment with an `@brief` for the public
accessor g_picker_pool_shared() describing its purpose (returns the per-thread
PickerPoolShared instance used by the MRMTransitionGroupPicker pool system) and
keep the existing rationale comment as detailed remarks if desired; place the
comment immediately above the inline PickerPoolShared& g_picker_pool_shared()
function and reference the function name and the PickerPoolShared type in the
doc block so it satisfies the header's public API documentation guidelines.

@timosachsenberg
timosachsenberg merged commit 33188be into develop Apr 27, 2026
20 checks passed
@timosachsenberg
timosachsenberg deleted the fix/picker-pool-tls-dup-symbol branch April 27, 2026 13:01
timosachsenberg pushed a commit that referenced this pull request Apr 28, 2026
Add missing entries for:
- #9221: pyOpenMS standalone/cibuildwheel Arrow 24.x CMake fix
- #9218: PercolatorAdapter in-process Percolator rescoring backend
- #9224: ProSE/FragmentIndex SNES X/B/Z mother truncation fix
- #9223: OpenSwathWorkflow macOS arm64 duplicate TLS symbol fix

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Apr 28, 2026
Add missing CHANGELOG entries for 4 recent code PRs that were not yet
documented:

- #9218: feat(Percolator) in-process backend — new OpenMS::Percolator
  class (vendored Percolator 3.08 + TRON solver) and PercolatorAdapter
  -use_subprocess flag; entries added under OpenMS Library Added and
  TOPP tools PercolatorAdapter sections.

- #9221: fix(cmake) Arrow 24.x in pyOpenMS standalone build — the
  cibuildwheel CMakeLists.txt version pin now dropped like #9196;
  entry added under Dependencies.

- #9223: fix(openswath) duplicate TLS init symbol on macOS arm64/clang —
  g_picker_pool_shared moved from inline thread_local in header to a
  single .cpp definition; entry added under OpenSwathWorkflow.

- #9224: fix(FragmentIndex) SNES mothers truncated at X/B/Z residues —
  proteins with ambiguous residues split into unambiguous spans for SNES
  indexing; entry added under ProSE.

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>
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.

duplicate symbol 'thread-local initialization routine for OpenMS::g_picker_pool_shared'

1 participant