Draft
Conversation
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).
84ac588 to
f0f7d53
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asOr
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_ENABLEbut tracy having been built with it. (opposite is detected though, if tracy was built withoutTRACY_ENABLEand consumer with) This is because macros become noops in that case, with no reference toGetProfiler. 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 wholeMANGLED_NAME_BASED_ON_DEFINESinto 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.