https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68771
Bug ID: 68771 Summary: Darwin: Profile guided optimisation with cold sections and invalid symbol redefinition Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: zerolo at gmail dot com Target Milestone: --- Created attachment 36944 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36944&action=edit Patch to make cold section label unique(r?) I'm not sure which component to attach this report to, the problem seems to be specific to Darwin (and stem from its format for debug symbols but is present whether generating debug info or not), but relates to both PGO (which causes the cold and hot splits) and is exacerbate by LTO. On the Darwin platform, a label is inserted for debugging / EH purposes when a function is split into hot / hold (with info generated from PGO). Rough repo steps for Mac OS 10.11.1 El Yosemite with Homebrew gcc 5.3.0 1) Compile/link C++ project with -Ofast -DNDEBUG -flto -fprofile-generate 2) Run to generate profiling files 3) Compile/link C++ project with -Ofast -DNDEBUG -flto -fprofile-use Step 3's link aborts on multiple temporary assembler files with errors such as /var/folders/02/yl3m8d4d0397mk6dxn6dpcqw0000gp/T//ccgBAKOU.s:3430:1: error: invalid symbol redefinition ___cold_sect_of_ComputeBoundingBox: ^ /var/folders/02/yl3m8d4d0397mk6dxn6dpcqw0000gp/T//ccHiavMh.s:1652:1: error: invalid symbol redefinition ___cold_sect_of_GetInterpolationMatrix: ^ /var/folders/02/yl3m8d4d0397mk6dxn6dpcqw0000gp/T//ccjQlEWp.s:11019:1: error: invalid symbol redefinition ___cold_sect_of_GetReferencePoints: ^ The methods mentioned exist multiple times, but either as different overloads (different C++ arguments, so distinct mangled name), or in completely difference classes (or static in distinct files). The machinery that actually generates those __cold_sect_of_ seems to be set up in gcc/config/darwin.c:3682. Originally this seems to come from a patch for debugging information here https://gcc.gnu.org/ml/gcc-patches/2010-12/msg01609.html These label are derived *only* from the name of the function, so it fails when multiple overloads are present, also seems to cause problems with LTO. When I change darwin.c to use DECL_ASSEMBLER_NAME instead (and increase the buffer size for really long mangled names), the link works, although I'm not sure about the accuracy of debug information.