diff --git a/libc/Android.mk b/libc/Android.mk index 884d759b8..4470efa86 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -736,7 +736,7 @@ WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A)) include $(CLEAR_VARS) -LOCAL_SRC_FILES := bionic/__stack_chk_fail.cpp bionic/__stack_chk_guard.cpp +LOCAL_SRC_FILES := bionic/__stack_chk_fail.cpp LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector -Werror LOCAL_C_INCLUDES := $(libc_common_c_includes) LOCAL_MODULE := libbionic_ssp diff --git a/libc/bionic/__stack_chk_guard.cpp b/libc/bionic/__stack_chk_guard.cpp deleted file mode 100644 index a695cafbb..000000000 --- a/libc/bionic/__stack_chk_guard.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "bionic_ssp.h" - -#include - -uintptr_t __stack_chk_guard = 0; - -static void __attribute__((constructor)) __init_stack_check_guard() { - // AT_RANDOM is a pointer to 16 bytes of randomness on the stack. - __stack_chk_guard = *reinterpret_cast(getauxval(AT_RANDOM)); -} diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index 6038056b3..33ec1db35 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -26,21 +26,24 @@ * SUCH DAMAGE. */ -#include -#include -#include -#include -#include -#include -#include -#include "pthread_internal.h" -#include "atexit.h" -#include "KernelArgumentBlock.h" #include "libc_init_common.h" +#include #include +#include #include -#include +#include +#include +#include +#include +#include +#include + +#include "atexit.h" +#include "private/bionic_auxv.h" +#include "private/bionic_ssp.h" +#include "private/KernelArgumentBlock.h" +#include "pthread_internal.h" extern "C" unsigned __get_sp(void); extern "C" int __system_properties_init(void); @@ -51,6 +54,9 @@ const char* __progname; // Declared in . char** environ; +// Declared in . +uintptr_t __stack_chk_guard = 0; + // Declared in . unsigned int __page_size = PAGE_SIZE; unsigned int __page_shift = PAGE_SHIFT; @@ -91,6 +97,9 @@ void __libc_init_common(KernelArgumentBlock& args) { __libc_auxv = args.auxv; __progname = args.argv[0] ? args.argv[0] : ""; + // AT_RANDOM is a pointer to 16 bytes of randomness on the stack. + __stack_chk_guard = *reinterpret_cast(getauxval(AT_RANDOM)); + // Get the main thread from TLS and add it to the thread list. pthread_internal_t* main_thread = __get_thread(); main_thread->allocated_on_heap = false;