From a7bd0b4e8e622e0a549fceae238689bfa5bdac60 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Mon, 27 Nov 2017 14:30:42 -0800 Subject: [PATCH] Use different symbols for SystraceSection depending on WITH_FBYSTRACE Reviewed By: tmikov Differential Revision: D6365162 fbshipit-source-id: d1e13b0012528305506c368d5e60f3754a576df3 --- ReactCommon/cxxreact/SystraceSection.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ReactCommon/cxxreact/SystraceSection.h b/ReactCommon/cxxreact/SystraceSection.h index 2db1e51b4b39a5..ea73046e8a469e 100644 --- a/ReactCommon/cxxreact/SystraceSection.h +++ b/ReactCommon/cxxreact/SystraceSection.h @@ -13,21 +13,33 @@ namespace react { * This is a convenience class to avoid lots of verbose profiling * #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will * remove this completely. If it is defined, it will behave as - * FbSystraceSection, with the right tag provided. + * FbSystraceSection, with the right tag provided. Use two separate classes to + * to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has + * different values in different files, there is no inconsistency in the sizes + * of defined symbols. */ -struct SystraceSection { +#ifdef WITH_FBSYSTRACE +struct ConcreteSystraceSection { public: template - explicit SystraceSection(const char* name, ConvertsToStringPiece&&... args) -#ifdef WITH_FBSYSTRACE + explicit + ConcreteSystraceSection(const char* name, ConvertsToStringPiece&&... args) : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) -#endif {} private: -#ifdef WITH_FBSYSTRACE fbsystrace::FbSystraceSection m_section; -#endif }; +using SystraceSection = ConcreteSystraceSection; +#else +struct DummySystraceSection { +public: + template + explicit + DummySystraceSection(const char* name, ConvertsToStringPiece&&... args) + {} +}; +using SystraceSection = DummySystraceSection; +#endif }}