Skip to content

build: Move SpinLock and SpinLockHolder into s2internal (#689) - #702

Open
Fedomn wants to merge 1 commit into
google:masterfrom
Fedomn:issue-689-fix-spinlock-odr
Open

Fedomn wants to merge 1 commit into
google:masterfrom
Fedomn:issue-689-fix-spinlock-odr

Conversation

@Fedomn

@Fedomn Fedomn commented Oct 22, 2026 •

Copy link
Copy Markdown

They are implementation details of MutableS2ShapeIndex and EncodedS2ShapeIndex, yet were defined in the global namespace. gperftools defines its own global SpinLock and SpinLockHolder with a different layout and locking protocol, so linking both libraries into one program violates the ODR: in unoptimized builds the inline members are emitted as weak symbols with identical mangled names and the linker keeps an arbitrary copy.

Move both classes into namespace s2internal and expose the unqualified names through using declarations, so no S2 source or client code needs to change. The emitted symbols are now s2internal::*, which no longer collide with gperftools.

Fix #689

They are implementation details of MutableS2ShapeIndex and
EncodedS2ShapeIndex, yet were defined in the global namespace. gperftools
defines its own global SpinLock and SpinLockHolder with a different layout
and locking protocol, so linking both libraries into one program violates
the ODR: in unoptimized builds the inline members are emitted as weak
symbols with identical mangled names and the linker keeps an arbitrary
copy.

Move both classes into namespace s2internal and expose the unqualified
names through using declarations, so no S2 source or client code needs to
change. The emitted symbols are now s2internal::*, which no longer
collide with gperftools.
@google-cla

google-cla Bot commented Oct 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Fedomn Fedomn closed this Nov 14, 2026
@Fedomn Fedomn reopened this Nov 14, 2026

This branch has not been deployed

No deployments
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.

Global SpinLock/SpinLockHolder in s2/base/spinlock.h collide with gperftools (ODR violation, startup hang in debug builds)

1 participant