Skip to content

Commit b45cfd9

Browse files
pcanaldevajithvs
authored andcommitted
Fix ROOT-7775 by making all static init function name unique.
In EmitCXXGlobalVarDeclInitFunc make the init function name more unique when module are used. Most static init are called from a wrapping function (whose name start with _GLOBAL__sub_I_ and is followed by the source filename). The static init functions are named __cxx_global_var_init followed by a serial number which is local to each module. Neither the _GLOBAL__sub_I_ nor the __cxx_global_var_init are effectively removed for the SymbolTable in the dynamic library corresponding to the module. I assume normal functions they get properly removed because when the module is unloaded/removed the whole corresponding SymbolTable must be removed. There does not seem to be any interface to remove a single symbol from the symbol table. To avoid the problem for the common case of static init, we alredy use a 'Hack to temporarily set the file entry's name to a unique name.' in IncrementalParser.cpp around line 539, which make the name of the wrapping init function whose name start with _GLOBAL__sub_I_ unique accross the whole execution. Those routines in turn call routines that have *non* unique name (starting by __cxx_global_var_init), I suppose because the wrapping routines are compiled they see the init function with that name in the module before looking into other modules. The static initialization for explicit template specialization are intentionally *not* put in this uniquely named wrapping function. Instead they are called directly. When they are called by runStaticInitializersOnce, the search-by-name we use find the 'first' instance of a function by that name (rather than the last). The solution I found was to make the name of the static init functions that are named __cxx_global_var_init to be followed by the module name ....
1 parent a866fd2 commit b45cfd9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,19 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
540540
getCXXABI().getMangleContext().mangleDynamicInitializer(D, Out);
541541
}
542542

543+
// Use the module name to make the initializer unique accross modules.
544+
SmallString<128> moduleName(TheModule.getName());
545+
for (size_t i = 0; i < moduleName.size(); ++i) {
546+
// Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
547+
// to be the set of C preprocessing numbers.
548+
if (!isPreprocessingNumberBody(moduleName[i]))
549+
moduleName[i] = '_';
550+
}
551+
543552
// Create a variable initialization function.
544553
llvm::Function *Fn = CreateGlobalInitOrCleanUpFunction(
545-
FTy, FnName.str(), getTypes().arrangeNullaryFunction(), D->getLocation());
554+
FTy, llvm::Twine(FnName)+moduleName.str() + "_",
555+
getTypes().arrangeNullaryFunction(), D->getLocation());
546556

547557
auto *ISA = D->getAttr<InitSegAttr>();
548558
CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr,

0 commit comments

Comments
 (0)