From b0343a38a5910e980bb031e4014655d77cd0c162 Mon Sep 17 00:00:00 2001 From: Daniel Kiss Date: Wed, 13 Apr 2022 09:31:25 +0200 Subject: Support the min of module flags when linking, use for AArch64 BTI/PAC-RET LTO objects might compiled with different `mbranch-protection` flags which will cause an error in the linker. Such a setup is allowed in the normal build with this change that is possible. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D123493 --- clang/lib/CodeGen/CodeGenModule.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 4efcc8447d81..b251a4a7df3d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -729,7 +729,10 @@ void CodeGenModule::Release() { // attributes, but we use module metadata to emit build attributes. This is // needed for LTO, where the function attributes are inside bitcode // serialised into a global variable by the time build attributes are - // emitted, so we can't access them. + // emitted, so we can't access them. LTO objects could be compiled with + // different flags therefore module flags are set to "Min" behavior to achieve + // the same end result of the normal build where e.g BTI is off if any object + // doesn't support it. if (Context.getTargetInfo().hasFeature("ptrauth") && LangOpts.getSignReturnAddressScope() != LangOptions::SignReturnAddressScopeKind::None) @@ -743,16 +746,16 @@ void CodeGenModule::Release() { Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb || Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32 || Arch == llvm::Triple::aarch64_be) { - getModule().addModuleFlag(llvm::Module::Error, "branch-target-enforcement", + getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement", LangOpts.BranchTargetEnforcement); - getModule().addModuleFlag(llvm::Module::Error, "sign-return-address", + getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", LangOpts.hasSignReturnAddress()); - getModule().addModuleFlag(llvm::Module::Error, "sign-return-address-all", + getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all", LangOpts.isSignReturnAddressScopeAll()); - getModule().addModuleFlag(llvm::Module::Error, + getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-with-bkey", !LangOpts.isSignReturnAddressWithAKey()); } -- cgit v1.2.3