Skip to content

[Sanitizers] Add new sanitize-stable-abi flag for libsanitizers. #69943

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

Closed
wants to merge 1 commit into from

Conversation

usama54321
Copy link
Contributor

This patch adds a new flag sanitize-stable-abi to support linking against the stable ABI introduced in libsanitizers. The patch also passes the appropriate options for the ASan pass when using this flag.

This change depends on the llvm-project change here: llvm/llvm-project#72439
rdar://112915278

Copy link
Contributor

@yln yln left a comment

Choose a reason for hiding this comment

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

LGTM, with nits, thanks!

@@ -1394,6 +1394,10 @@ def sanitize_coverage_EQ : CommaJoined<["-"], "sanitize-coverage=">,
HelpText<"Specify the type of coverage instrumentation for Sanitizers and"
" additional options separated by commas">;

def sanitize_stable_abi_EQ : Flag<["-"], "sanitize-stable-abi">,
Flags<[FrontendOption, NoInteractiveOption]>,
HelpText<"ABI instrumentation for sanitizer runtime.">;
Copy link
Contributor

@yln yln Nov 17, 2023

Choose a reason for hiding this comment

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

Please improve the help text here, I don't think anyone (who doesn't already know) can understand what the option does based on this description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially copied the HelpText from the same option in clang. I have updated it to make it a bit more helpful

Comment on lines +321 to +325
if (context.OI.SanitizerUseStableABI)
addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "asan_abi",
*this, false);
else
addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "asan", *this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use something like this to reduce diff/duplication.
auto good_name = context.OI.SanitizerUseStableABI ? "asan_abi" : "asan";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is an extra boolean argument in one of the cases, so this would require two ternary operators, so using an if feels cleaner here.

@@ -0,0 +1,5 @@
// REQUIRES: asan_runtime
// RUN: %swiftc_driver -driver-print-jobs -sanitize=address -sanitize-stable-abi %s 2>&1 | %FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

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

When I read "-sanitize-stable-abi` as "sanitize stable ABI" it's not the right meaning. Compare "Sanitize address" which describes pretty well what it does.

The variable names for this are SanitizerUseStableABI, so we just forgot the r here?

I think the "sanitizer" prefix here is a noun vs. "sanitize" (verb). If we want to include a verb, we could spell the option with "use".

I would pick one of these:

-sanitizer-stable-abi
-sanitizer-use-stable-abi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I matched the convention used in clang where we use -fsanitize-stable-abi flag. In the last team meeting, @devincoughlin suggested that the naming should be consistent in clang and swift. We currently are not planning to change this in clang

@usama54321
Copy link
Contributor Author

@swift-ci test

This patch adds a new flag sanitize-stable-abi to support linking
against the Sanitizers stable ABI added recently in compiler-rt. The
patch also passes extra options for the ASan pass when using this flag
to outline instrumentation code and remove version check.

rdar://112915278
@usama54321
Copy link
Contributor Author

@swift-ci test

@@ -317,8 +317,13 @@ toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments,
// Linking sanitizers will add rpaths, which might negatively interact when
// other rpaths are involved, so we should make sure we add the rpaths after
// all user-specified rpaths.
if (context.OI.SelectedSanitizers & SanitizerKind::Address)
addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "asan", *this);
if (context.OI.SelectedSanitizers & SanitizerKind::Address) {

Choose a reason for hiding this comment

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

Will the rpath still be added? If it's not necessary is it just a NOP or could it cause a problem?

Copy link

@rsundahl rsundahl left a comment

Choose a reason for hiding this comment

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

It looks like maybe the commit isn't signed or isn't verifiable.
Is the build failure expected?

@usama54321
Copy link
Contributor Author

@swift-ci test

3 similar comments
@usama54321
Copy link
Contributor Author

@swift-ci test

@usama54321
Copy link
Contributor Author

@swift-ci test

@usama54321
Copy link
Contributor Author

@swift-ci test

@xedin xedin removed their request for review December 5, 2023 01:15
@usama54321
Copy link
Contributor Author

@swift ci test Linux

@usama54321
Copy link
Contributor Author

@swift-ci test Linux

1 similar comment
@usama54321
Copy link
Contributor Author

@swift-ci test Linux

@wrotki
Copy link
Contributor

wrotki commented Dec 16, 2023

@swift-ci test Linux

@wrotki
Copy link
Contributor

wrotki commented Dec 16, 2023

@swift-ci Please smoke test Linux platform

@wrotki
Copy link
Contributor

wrotki commented Dec 18, 2023

Cloned this commit to #70508 , and will be merging from there (on behalf of Usama who's not available at the moment). So closing this one

@wrotki wrotki closed this Dec 18, 2023
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.

4 participants