This is an archive of the discontinued LLVM Phabricator instance.

introduce flag -fsanitize-address-detect-stack-use-after-return-mode. No functional change.
AbandonedPublic

Authored by kda on Apr 22 2021, 5:47 PM.

Details

Reviewers
vitalybuka
Summary

introduce flag -fsanitize-address-detect-stack-use-after-return-mode. No functional change.
for issue: https://github.com/google/sanitizers/issues/1394

Diff Detail

Event Timeline

kda created this revision.Apr 22 2021, 5:47 PM
kda requested review of this revision.Apr 22 2021, 5:47 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 22 2021, 5:47 PM
kda edited the summary of this revision. (Show Details)Apr 22 2021, 5:48 PM
joerg added a subscriber: joerg.Apr 22 2021, 5:55 PM

This review doesn't make sense to me. Why add a flag that isn't affecting anything? Why add a flag that isn't even tested?

kda added a comment.Apr 22 2021, 10:24 PM

I'm new here.
I was told to take small steps.
This will eventually effect compiler-rt and llvm.
I took the smallest possible step.

What I had previously: https://reviews.llvm.org/D99630
And was told it was too large.

joerg added a comment.Apr 23 2021, 5:53 AM

There are two approaches that work for reviewing: starting from clang and going down or starting from compiler-rt and going up the layers. I'd prefer to do the latter as it means meaningful testing can be done easier. There are two natural steps here: clang flag+IR generation is one, llvm codegen and compiler-rt is the other. The clang step should include tests that ensure that proper IR is generated for the different flag combination (including documentation for the IR changes). The LLVM step should ensure that the different attributes (either function or module scope) are correctly lowered in the instrumentation pass and unit tests on the compiler-rt side to do functional testing. The unit testing might also be done as a third step if it goes the full way from C to binary code.

There are two approaches that work for reviewing: starting from clang and going down or starting from compiler-rt and going up the layers. I'd prefer to do the latter as it means meaningful testing can be done easier. There are two natural steps here: clang flag+IR generation is one, llvm codegen and compiler-rt is the other. The clang step should include tests that ensure that proper IR is generated for the different flag combination (including documentation for the IR changes). The LLVM step should ensure that the different attributes (either function or module scope) are correctly lowered in the instrumentation pass and unit tests on the compiler-rt side to do functional testing. The unit testing might also be done as a third step if it goes the full way from C to binary code.

Today on chat I advised to start with clang, but now I agree with Joerg. More precisely you can go with following 4 patches:

  1. LLVM Detailed IR tests of effect of this flag on transformation
  2. compiler-rt (tests will have to uses -mllvm -<internal asan copt>)
  3. clang
    • driver tests
    • basic IR tests to see that flag makes a difference of generated code. see llvm-project/clang/test/CodeGen/asan-*.cpp
  4. compiler-rt: replace -mllvm copt from patch2 with with clang flag from patch3.
clang/include/clang/Basic/CodeGenOptions.def
225

Mode->Kind to be consistent with the file

225–228

I believe for consistency we need:

  1. Var name (SanitizeAddressDetectStackUseAfterReturn) no Mode/Kind suffix
  2. Enum type AsanDetectStackUseAfterReturnKind uses "kind"
  3. Actual flag includes no "kind" -fsanitize-address-detect-stack-use-after-return=

BTW. @delcypher -fsanitize-address-destructor-kind was not consistent with the rest of file, but I am not sure it's worth of fixing now.

clang/include/clang/Driver/Options.td
1555

same order as enum

llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
29

Could you order them in acceding order by "strictness", this will make Never == 0, and the current default == 1.
Never = 0, (maybe None for consistency?)
Runtime=1,
Always=2,
Invalid=<whatever>

vitalybuka requested changes to this revision.Apr 26 2021, 5:45 PM
This revision now requires changes to proceed.Apr 26 2021, 5:45 PM
kda updated this revision to Diff 340746.Apr 27 2021, 1:08 AM

Revisions as requested.

kda marked 4 inline comments as done.Apr 27 2021, 1:15 AM

Thank you for delineating the steps.

Unfortunately, I don't know where to even start looking for the tests you mention in step 1. Are you looking for something like this: https://reviews.llvm.org/differential/changeset/?ref=2496958

For the 3 files I have here, which step are they in? (Step 1?)

kda updated this revision to Diff 340754.Apr 27 2021, 1:19 AM

fixed up some more naming issues.

delcypher added inline comments.Apr 28 2021, 9:57 AM
clang/include/clang/Basic/CodeGenOptions.def
225–228

@vitalybuka It's not too late to fix this because the -fsanitize-address-destructor-kind= flag hasn't been adopted yet AFAIK.

Am I right in understanding that what I landed doesn't match points 1 and 3 above? If you can confirm that's what you'd like to be changed I can put up some patches to fix this.

vitalybuka added inline comments.Apr 28 2021, 10:51 AM
clang/include/clang/Basic/CodeGenOptions.def
225–228

Correct
I'd expect

ENUM_CODEGENOPT(SanitizeAddressDtor, llvm::AsanDtorKind, 2,
                llvm::AsanDtorKind::Global)

and

def sanitize_address_destructor_EQ
    : Joined<["-"], "fsanitize-address-destructor=">,
      MetaVarName<"<kind>">,
      Flags<[CC1Option]>,
      HelpText<"Set destructor type used in ASan instrumentation">,
      Group<f_clang_Group>,
      Values<"none,global">,
      NormalizedValuesScope<"llvm::AsanDtorKind">,
      NormalizedValues<["None", "Global"]>,
      MarshallingInfoEnum<CodeGenOpts<"SanitizeAddressDtor">, "Global">;

And one more thing, probably not very important, and matter of personal preferences.
Maybe we don't need MetaVarName<"<kind>"> for both of these flags.
Without MetaVarName documentation is going to be -fsanitize-address-destructor=<arg>
MetaVarName just lets use to replace <arg> with more common and specific <file>, <dir>.. etc.
To me <kind> is almost generic as <arg>, so why not to stick to default.

delcypher added inline comments.Apr 28 2021, 2:37 PM
clang/include/clang/Basic/CodeGenOptions.def
225–228
kda abandoned this revision.Jun 11 2021, 2:09 PM