Skip to content

LLVM-Passes: add pointer authentication to Swift's function merge pass. #34033

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

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

eeckstein
Copy link
Contributor

If during merging a function pointer is passed as a parameter to the merged function, it needs to be signed on arm64e.

rdar://problem/66797689

@eeckstein eeckstein requested a review from rjmccall September 22, 2020 19:12
@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 554a4c333088d9477a811a2932fb8f3eced466af

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 554a4c333088d9477a811a2932fb8f3eced466af

@@ -316,6 +325,15 @@ class SwiftMergeFunctions : public ModulePass {
CurrentInst = &*std::next(CurrentInst->getIterator());
}

/// Returns true if the operand \p OpIdx of the current instruction is the
/// callee of a call, which needs to be signed if passed as a parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you might have a similar problem with the ptrauth intrinsics — you shouldn't turn a constant operand of llvm.ptrauth.sign (which we have to do when e.g. storing into an address-diversified location) into a non-constant one. You'll need to turn the sign into a resign.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intrinsics are excluded from being parameterized, anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, if the parameterization only happens with function calls and not other uses of functions, then yeah, this isn't a problem.

Copy link
Contributor

@rjmccall rjmccall Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, parameterization also doesn't consider uses by intrinsics.

@@ -337,12 +355,25 @@ class SwiftMergeFunctions : public ModulePass {
/// All uses of the parameter in the merged function.
SmallVector<OpLocation, 16> Uses;

/// The discriminator for pointer signing.
/// Only not null, if needsPointerSigning is true.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma

// Replace all differing operands, which need pointer signing, with a
// parameter.
// We need to do that after all other parameters, because here we replace
// call instructions, which must be life in case it has another constant to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"live"

If during merging a function pointer is passed as a parameter to the merged function, it needs to be signed on arm64e.

rdar://problem/66797689
@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eeckstein eeckstein changed the base branch from master to main September 24, 2020 07:02
@eeckstein eeckstein merged commit 638cf56 into swiftlang:main Sep 24, 2020
@eeckstein eeckstein deleted the merge-func-ptrauth branch September 24, 2020 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants