-
Notifications
You must be signed in to change notification settings - Fork 14.5k
LowerTypeTests: Start using !elf_section_properties metadata to mark CFI jump table sections. #149261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pcc
wants to merge
2
commits into
users/pcc/spr/main.wip-lowertypetests-start-using-elf_section_properties-metadata-to-mark-cfi-jump-table-sections
Choose a base branch
from
users/pcc/spr/wip-lowertypetests-start-using-elf_section_properties-metadata-to-mark-cfi-jump-table-sections
base: users/pcc/spr/main.wip-lowertypetests-start-using-elf_section_properties-metadata-to-mark-cfi-jump-table-sections
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−20
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.6-beta.1
@llvm/pr-subscribers-llvm-transforms Author: Peter Collingbourne (pcc) ChangesTODO:
Full diff: https://github.com/llvm/llvm-project/pull/149261.diff 2 Files Affected:
diff --git a/compiler-rt/test/cfi/mfcall.cpp b/compiler-rt/test/cfi/mfcall.cpp
index d4666df8d5333..f95251f5adb44 100644
--- a/compiler-rt/test/cfi/mfcall.cpp
+++ b/compiler-rt/test/cfi/mfcall.cpp
@@ -63,12 +63,12 @@ int main(int argc, char **argv) {
switch (argv[1][0]) {
case 'a':
// A: runtime error: control flow integrity check for type 'int (S::*)()' failed during non-virtual pointer to member function call
- // A: note: S::f1() defined here
+ // A: note: S::f1() {{.*}}defined here
(s.*bitcast<S_int>(&S::f1))();
break;
case 'b':
// B: runtime error: control flow integrity check for type 'int (T::*)()' failed during non-virtual pointer to member function call
- // B: note: S::f2() defined here
+ // B: note: S::f2() {{.*}}defined here
(t.*bitcast<T_int>(&S::f2))();
break;
case 'c':
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 86e1ebf937dbe..8b21d81bc9678 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -30,6 +30,8 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/TypeMetadataUtils.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
@@ -73,6 +75,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/IPO/CrossDSOCFI.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <algorithm>
@@ -498,6 +501,10 @@ class LowerTypeTestsModule {
GlobalVariable *GlobalAnnotation;
DenseSet<Value *> FunctionAnnotations;
+ // Cross-DSO CFI emits jumptable entries for exported functions as well as
+ // address taken functions in case they are address taken in other modules.
+ bool CrossDsoCfi = M.getModuleFlag("Cross-DSO CFI") != nullptr;
+
bool shouldExportConstantsAsAbsoluteSymbols();
uint8_t *exportTypeId(StringRef TypeId, const TypeIdLowering &TIL);
TypeIdLowering importTypeId(StringRef TypeId);
@@ -1527,10 +1534,19 @@ Triple::ArchType LowerTypeTestsModule::selectJumpTableArmEncoding(
void LowerTypeTestsModule::createJumpTable(
Function *F, ArrayRef<GlobalTypeMember *> Functions,
Triple::ArchType JumpTableArch) {
- std::string AsmStr, ConstraintStr;
- raw_string_ostream AsmOS(AsmStr), ConstraintOS(ConstraintStr);
- SmallVector<Value *, 16> AsmArgs;
- AsmArgs.reserve(Functions.size() * 2);
+ unsigned JumpTableEntrySize = getJumpTableEntrySize(JumpTableArch);
+ // Give the jumptable section this type in order to enable jumptable
+ // relaxation. Only do this if cross-DSO CFI is disabled because jumptable
+ // relaxation violates cross-DSO CFI's restrictions on the ordering of the
+ // jumptable relative to other sections.
+ if (!CrossDsoCfi)
+ F->setMetadata(LLVMContext::MD_elf_section_properties,
+ MDNode::get(F->getContext(),
+ ArrayRef<Metadata *>{
+ ConstantAsMetadata::get(ConstantInt::get(
+ Int64Ty, ELF::SHT_LLVM_CFI_JUMP_TABLE)),
+ ConstantAsMetadata::get(ConstantInt::get(
+ Int64Ty, JumpTableEntrySize))}));
BasicBlock *BB = BasicBlock::Create(M.getContext(), "entry", F);
IRBuilder<> IRB(BB);
@@ -1552,7 +1568,7 @@ void LowerTypeTestsModule::createJumpTable(
IRB.CreateUnreachable();
// Align the whole table by entry size.
- F->setAlignment(Align(getJumpTableEntrySize(JumpTableArch)));
+ F->setAlignment(Align(JumpTableEntrySize));
// Skip prologue.
// Disabled on win32 due to https://llvm.org/bugs/show_bug.cgi?id=28641#c3.
// Luckily, this function does not get any prologue even without the
@@ -2119,10 +2135,6 @@ bool LowerTypeTestsModule::lower() {
unsigned CurUniqueId = 0;
SmallVector<MDNode *, 2> Types;
- // Cross-DSO CFI emits jumptable entries for exported functions as well as
- // address taken functions in case they are address taken in other modules.
- const bool CrossDsoCfi = M.getModuleFlag("Cross-DSO CFI") != nullptr;
-
struct ExportedFunctionInfo {
CfiFunctionLinkage Linkage;
MDNode *FuncMD; // {name, linkage, type[, type...]}
|
Created using spr 1.3.6-beta.1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.