Existing OpenMP code generation in clang adds the same OpenMP registration code and associated data to every object file. As a result this code is replicated multiple times in the linked binary (by the number of object files in a program) and each copy of this code is called at programs startup. This negatively affects both code size and startup time. It is sufficient to have only one copy of OpenMP registration code and call it only once at startup.
Attached patch changes clang OpenMP code generation to create a COMDAT group for the OpenMP registration code and associated data which forces linker to keep only one copy of this code in the binary. Registration routine serves as a key for this COMDAT group. Visibility of the OpenMP registration routine is set to “hidden” to avoid this symbol to be preempted if it is defined in more than one component in a process (for example both executable and a shared library which executable depends on may have its own copy of initialization routine, and in such case we do not want shared library’s symbol to be preempted by executable’s symbol).