Skip to content

Commit b7d0781

Browse files
dpaoliellosivadeilra
authored andcommitted
Apply 0010-inliner-section-safety.patch
1 parent 56fef38 commit b7d0781

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

llvm/include/llvm/IR/Attributes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ def : CompatRule<"isEqual<UseSampleProfileAttr>">;
455455
def : CompatRule<"isEqual<NoProfileAttr>">;
456456
def : CompatRule<"checkDenormMode">;
457457
def : CompatRule<"checkStrictFP">;
458+
def : CompatRule<"checkSections">;
458459
def : CompatRuleStrAttr<"isEqual", "sign-return-address">;
459460
def : CompatRuleStrAttr<"isEqual", "sign-return-address-key">;
460461
def : CompatRuleStrAttr<"isEqual", "branch-protection-pauth-lr">;

llvm/lib/IR/Attributes.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,44 @@ static bool checkStrictFP(const Function &Caller, const Function &Callee) {
25082508
Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
25092509
}
25102510

2511+
static bool checkSections(const Function &Caller, const Function &Callee) {
2512+
// Implement MSVC compatible cross-section inlining rules
2513+
StringRef CallerSection = Caller.getSection();
2514+
StringRef CalleeSection = Callee.getSection();
2515+
2516+
// sections match, inline ok
2517+
if (!CallerSection.compare(CalleeSection))
2518+
return true;
2519+
2520+
bool isCallerPaged = CallerSection.starts_with("PAGE");
2521+
bool isCalleePaged = CalleeSection.starts_with("PAGE");
2522+
2523+
// Prevent inlining of non-paged code into a paged caller
2524+
// Prevent inlining of paged code into non-paged caller
2525+
// Section names are compared only before the '$' separator if present
2526+
2527+
if (isCallerPaged) {
2528+
size_t CallerComparable = CallerSection.size();
2529+
size_t CalleeComparable = CalleeSection.size();
2530+
size_t CallerSep = CallerSection.find('$');
2531+
size_t CalleeSep = CalleeSection.find('$');
2532+
2533+
if (CallerSep != StringRef::npos)
2534+
CallerComparable = CallerSep;
2535+
if (CalleeSep != StringRef::npos)
2536+
CalleeComparable = CalleeSep;
2537+
if (CallerComparable != CalleeComparable)
2538+
return false;
2539+
2540+
StringRef CallerComparableSection = CallerSection.substr(0, CallerComparable);
2541+
StringRef CalleeComparableSection = CalleeSection.substr(0, CallerComparable);
2542+
return !CallerComparableSection.compare(CalleeComparableSection);
2543+
} else if (isCalleePaged)
2544+
return false;
2545+
2546+
return true;
2547+
}
2548+
25112549
template<typename AttrClass>
25122550
static bool isEqual(const Function &Caller, const Function &Callee) {
25132551
return Caller.getFnAttribute(AttrClass::getKind()) ==

0 commit comments

Comments
 (0)