Skip to content

Commit

Permalink
Merge "Use the global stack protector guard for old x86."
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Feb 15, 2017
2 parents 2656745 + 1f46cdf commit efa3688
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build/core/build-binary.mk
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_CFLAGS += -mstackrealign
endif

# https://github.com/android-ndk/ndk/issues/297
ifeq ($(TARGET_ARCH_ABI),x86)
ifneq (,$(call lt,$(APP_PLATFORM_LEVEL),17))
ifeq ($(NDK_TOOLCHAIN_VERSION),4.9)
LOCAL_CFLAGS += -mstack-protector-guard=global
endif
endif
endif

#
# The original Android build system allows you to use the .arm prefix
# to a source file name to indicate that it should be defined in either
Expand Down
6 changes: 6 additions & 0 deletions tests/build/mstack-protector-guard/project/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.cpp
include $(BUILD_SHARED_LIBRARY)
1 change: 1 addition & 0 deletions tests/build/mstack-protector-guard/project/jni/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo() {}
63 changes: 63 additions & 0 deletions tests/build/mstack-protector-guard/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Check for mstack-protector-guard=global when targeting old x86 targets.
https://gcc.gnu.org/ml/gcc/2015-11/msg00060.html changed the default for this
from using a global to using the TLS slot. As noted in
https://github.com/android-ndk/ndk/issues/297 (and in that commit), this is not
compatible with pre-4.2 devices, so we need to guard against that in the NDK.
"""
import os
import subprocess
import sys


def run_test(abi=None, platform=None, toolchain=None, build_flags=None):
"""Checks ndk-build V=1 output for mstackrealign flag."""
if build_flags is None:
build_flags = []

ndk_dir = os.environ['NDK']
ndk_build = os.path.join(ndk_dir, 'ndk-build')
if sys.platform == 'win32':
ndk_build += '.cmd'
project_path = 'project'
ndk_args = build_flags + [
'APP_ABI=' + abi,
'APP_PLATFORM=android-{}'.format(platform),
'NDK_TOOLCHAIN_VERSION=' + toolchain,
'V=1',
]
proc = subprocess.Popen([ndk_build, '-C', project_path] + ndk_args,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = proc.communicate()
if proc.returncode != 0:
return proc.returncode == 0, out

search_text = '-mstack-protector-guard=global'
out_words = out.split(' ')
if abi == 'x86' and platform < 17 and toolchain == '4.9':
if search_text in out_words:
return True, out
else:
out = 'Did not find {} in output:\n{}'.format(search_text, out)
return False, out
else:
if search_text in out_words:
print 'Found unexpceted {} in output:\n'.format(search_text, out)
return False, out
else:
return True, out

0 comments on commit efa3688

Please sign in to comment.