Knowledge Library
Help Us Improve Your Knowledge Library Experience
Help Us Improve Your
Knowledge Library Experience
Express your opinion by taking a five minute survey
Knowledge Library Home Knowledge Library Products Development Tools LLVM Compiler TCLLVM-49 : Template static data member objects don't get constructed

TCLLVM-49 : Template static data member objects don't get constructed

Defect #: TCLLVM-49
Previous IDTCLLVM-56
Found In VersionLLVM
Created Date:02/15/2017
Component/s :CLANG


C++ template static data members used by DKMs does not get constructed when the DKM is loaded.

C++ template static data members with constructors must be initialized before they are used. However there is no unique file in which this initialization must occur. Instead every file that might need such an entity must generate a .ctor entry to do the initialization. The actual initialization is guarded so that it only runs once.

clang generates "COMDAT" .ctor sections to do these initializations. 

The munch mechanism used for ARM64 uses the linker script to arrange all the .ctors sections in the correct order between delimiters provided by ctdt.c. [Note that ARM64 cannot use the traditional munch scheme because the initializer functions themselves have internal linkage (they are file local) and so cannot be discovered and referenced by munch. As a result ARM64 uses the more modern .ctors approach already used by all architectures in user mode.]

However during a relocatable link COMDAT sections are output separately, and are not be treated as normal input sections by the linker script. As a result, the corresponding initializations will not run when a DKM is downloaded.

This problem only affects DKMs, it does not affect code linked into VIPs or RTPs.

Steps to Reproduce

1. Create and build a DKM for ARM64;

2. Create and build a VIP based on the VSB;

3. Create a DKM and attach the following test.h and test.cpp files:
/* test.h */
struct Init {
    bool Initialized;
template <typename T> struct Template {
    static Init Static;
template <typename T> Init Template<T>::Static;

/* test.cpp */
#include "StaticTemplate.h"
extern "C" int printf(const char*, ...);
Init::Init() {
    Initialized = true;
extern "C" void TestStaticTemplate(void) {
    printf("TestStaticTemplate: %s\n", Template<char>::Static.Initialized ? "PASSED" : "FAILED\n");

4. Build the DKM;

5. Load the DKM and run the function TestStaticTemplate.

KLID_DEFECT (use as Content ID for linking):  KLID_DEFECT_45828
You must to post a comment.
Last modified