GCC: also fix StackCanary.ChangingStackCanaryCrashesOnReturn

Create NOOPT compiler specific macro, and use it both in
ResetCanaryAndReturn and in ChangingStackCanaryCrashesOnReturn. For
the latter, it fixes the unit tests in GCC.

Bug: 819294
Change-Id: I1e5e9e4434728c6b1916d43fa4c8225dd71bbcb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5014023
Reviewed-by: danakj <[email protected]>
Commit-Queue: José Dapena Paz <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1221765}
diff --git a/base/stack_canary_linux_unittest.cc b/base/stack_canary_linux_unittest.cc
index f3dc1f1..3bdaeab9 100644
--- a/base/stack_canary_linux_unittest.cc
+++ b/base/stack_canary_linux_unittest.cc
@@ -4,6 +4,7 @@
 
 #include "base/stack_canary_linux.h"
 
+#include "base/compiler_specific.h"
 #include "build/build_config.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -13,12 +14,7 @@
     (defined(ARCH_CPU_ARM_FAMILY) || defined(ARCH_CPU_X86_FAMILY))
 
 namespace {
-#if defined(COMPILER_GCC) && !defined(__clang__)
-__attribute__((noinline, optimize(0)))
-#else
-__attribute__((noinline, optnone))
-#endif
-void ResetCanaryAndReturn() {
+NOINLINE NOOPT void ResetCanaryAndReturn() {
   // Create a buffer >=8 bytes to force the stack protector on this function,
   // which should work as long as -fno-stack-protector isn't passed in the
   // default options. We compile this file with -fstack-protector-all, but it