@@ -2848,7 +2848,16 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
28482848 // Skip available_externally functions. They won't be codegen'ed in the
28492849 // current module anyway.
28502850 if (getContext ().GetGVALinkageForFunction (FD) != GVA_AvailableExternally)
2851- createFunctionTypeMetadataForIcall (FD, F);
2851+ createFunctionTypeMetadataForIcallForCFI (FD, F);
2852+ }
2853+ }
2854+
2855+ if (CodeGenOpts.CallGraphSection ) {
2856+ if (auto *FD = dyn_cast<FunctionDecl>(D)) {
2857+ // Skip available_externally functions. They won't be codegen'ed in the
2858+ // current module anyway.
2859+ if (getContext ().GetGVALinkageForFunction (FD) != GVA_AvailableExternally)
2860+ createFunctionTypeMDForIcallForCallGraph (FD, F);
28522861 }
28532862 }
28542863
@@ -3060,16 +3069,24 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) {
30603069 return MD && MD->hasGeneralizedMDString ();
30613070}
30623071
3063- void CodeGenModule::createFunctionTypeMetadataForIcall (const FunctionDecl *FD,
3064- llvm::Function *F) {
3065- if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD (F) &&
3072+ void CodeGenModule::createFunctionTypeMDForIcallForCallGraph (
3073+ const FunctionDecl *FD, llvm::Function *F) {
3074+ // Add additional metadata if we are emitting call graph section
3075+ if (!CodeGenOpts.CallGraphSection )
3076+ return ;
3077+
3078+ if (!hasExistingGeneralizedTypeMD (F) &&
30663079 (!F->hasLocalLinkage () ||
30673080 F->getFunction ().hasAddressTaken (nullptr , /* IgnoreCallbackUses=*/ true ,
30683081 /* IgnoreAssumeLikeCalls=*/ true ,
30693082 /* IgnoreLLVMUsed=*/ false )))
30703083 F->addTypeMetadata (0 , CreateMetadataIdentifierGeneralized (FD->getType ()));
3084+ }
3085+
3086+ void CodeGenModule::createFunctionTypeMetadataForIcallForCFI (
3087+ const FunctionDecl *FD, llvm::Function *F) {
30713088
3072- // Add additional metadata only if we are checking indirect calls with CFI .
3089+ // Only if we are checking indirect calls.
30733090 if (!LangOpts.Sanitize .has (SanitizerKind::CFIICall))
30743091 return ;
30753092
@@ -3243,7 +3260,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
32433260 // jump table.
32443261 if (!CodeGenOpts.SanitizeCfiCrossDso ||
32453262 !CodeGenOpts.SanitizeCfiCanonicalJumpTables )
3246- createFunctionTypeMetadataForIcall (FD, F);
3263+ createFunctionTypeMetadataForIcallForCFI (FD, F);
32473264
32483265 if (LangOpts.Sanitize .has (SanitizerKind::KCFI))
32493266 setKCFIType (FD, F);
0 commit comments