Skip to content

Macro incompatibility experiment#1335

Draft
Lectem wants to merge 3 commits intowolfpld:masterfrom
siliceum:feature/check-macros-mismatch
Draft

Macro incompatibility experiment#1335
Lectem wants to merge 3 commits intowolfpld:masterfrom
siliceum:feature/check-macros-mismatch

Conversation

@Lectem
Copy link
Copy Markdown
Collaborator

@Lectem Lectem commented Apr 14, 2026

We redirect GetProfiler() (most likely used by any project consuming tracy, since it's used by tracy::ScopedZone) to its implementation which now has a different function name based on the macros that can impact ABI or would create incompatible behaviour (for example mixing time sources). That way, when linking with mismatched defines you'd get an error such as

main.obj : error LNK2019: unresolved external symbol "int __cdecl GetProfiler_CFG_E0_OD0_DI0_ML0_F0_DHT0_TF0(void)" (?GetProfiler_CFG_E0_OD0_DI0_ML0_F0_DHT0_TF0@@yahxz) referenced in function "int __cdecl GetProfiler(void)" (?GetProfiler@@yahxz)

Or

[build] /usr/bin/ld: CMakeFiles/app.dir/main.cpp.o: in function GetProfiler()': [build] /..../TracyProfiler.hpp:143: undefined reference to GetProfiler_CFG_E1_OD0_DI0_ML0_F0_DHT0_TF0()'

Reason for going with acronym+0/1 instead of just acronym when enabled is for us to be able to tell users easily which define is wrong by just looking at the error if needed.

The only thing we don't really detect is user not having TRACY_ENABLE but tracy having been built with it. (opposite is detected though, if tracy was built without TRACY_ENABLE and consumer with) This is because macros become noops in that case, with no reference to GetProfiler. There may be a way to do it by introducing a local variable into each TU, but I don't really like that idea. We could also add pragma detect mismatch for a more user-friendly error on windows (https://learn.microsoft.com/en-us/cpp/preprocessor/detect-mismatch?view=msvc-170).

There may be better ways to do that I'm unaware of, but most I've seen rely on introducing new globals or would discard the diagnostic under optimizations, which I didn't really like.

This pollutes a bit the header, but given the number of users reporting "bugs" due to mismatched defines (especially TRACY_ON_DEMAND) this could be worth it. Could also move the whole MANGLED_NAME_BASED_ON_DEFINES into its own header.
This is an ABI break and may break some users, if this even matters considering it could be hiding bugs.

Will also need to update docs.

We redirect GetProfiler() (most likely used by any project consuming tracy, since it's used by `tracy::ScopedZone`) to its implementation which now has a different function name based on the macros that can impact ABI (and enabled/disabled).
That way, when linking with mismatched defines you'd get an error such as

> main.obj : error LNK2019: unresolved external symbol "int __cdecl GetProfiler_CFG_E0_OD0_DI0_ML0_F0_DHT0_TF0(void)" (?GetProfiler_CFG_E0_OD0_DI0_ML0_F0_DHT0_TF0@@yahxz) referenced in function "int __cdecl GetProfiler(void)" (?GetProfiler@@yahxz)

Or

>[build] /usr/bin/ld: CMakeFiles/app.dir/main.cpp.o: in function `GetProfiler()':
[build] /..../TracyProfiler.hpp:143: undefined reference to `GetProfiler_CFG_E1_OD0_DI0_ML0_F0_DHT0_TF0()'

Reason for going with acronym+0/1 instead of just acronym when enabled is for us to be able to tell users easily which define is wrong by just looking at the error if needed.

The only thing we don't really detect is user not having TRACY_ENABLE but tracy having been built with it. This is because macros become noops in that case, with no reference to `GetProfiler`.
There may be a way to do it by introducing a local variable into each TU, but I don't really like that idea.
We could also add pragma detect mismatch for a more user-friendly error on windows (https://learn.microsoft.com/en-us/cpp/preprocessor/detect-mismatch?view=msvc-170).
@Lectem Lectem force-pushed the feature/check-macros-mismatch branch from 84ac588 to f0f7d53 Compare April 14, 2026 13:23
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.

1 participant