Skip to content

Commit

Permalink
gen/modules.cpp: use setModuleFlag API to replace ...
Browse files Browse the repository at this point in the history
... the module attribute to avoid LLVM assertions if specified module
attribute already exists
  • Loading branch information
liushuyu committed Jan 23, 2025
1 parent 9de21fd commit f7f0fc4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gen/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,18 @@ void registerModuleInfo(Module *m) {

void addModuleFlags(llvm::Module &m) {
const auto ModuleMinFlag = llvm::Module::Min;
const auto ConstantOne =
llvm::ConstantInt::get(LLType::getInt32Ty(m.getContext()), 1);
const auto ConstantOneMetadata = llvm::ConstantAsMetadata::get(ConstantOne);

if (opts::fCFProtection == opts::CFProtectionType::Return ||
opts::fCFProtection == opts::CFProtectionType::Full) {
m.addModuleFlag(ModuleMinFlag, "cf-protection-return", 1);
m.setModuleFlag(ModuleMinFlag, "cf-protection-return", ConstantOneMetadata);
}

if (opts::fCFProtection == opts::CFProtectionType::Branch ||
opts::fCFProtection == opts::CFProtectionType::Full) {
m.addModuleFlag(ModuleMinFlag, "cf-protection-branch", 1);
m.setModuleFlag(ModuleMinFlag, "cf-protection-branch", ConstantOneMetadata);
}
}

Expand Down

0 comments on commit f7f0fc4

Please sign in to comment.