From f857d59635cda31db2fdc0c58193f51eecf2cc73 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 12 Feb 2018 19:59:46 -0800 Subject: [PATCH] Switch x86 begin.c to asm; align ESP correctly Every other architecture already uses an assembly file here. The previous code aligned ESP incorrectly, but it doesn't really matter because everything is built with Clang's -mstackrealign, which realigns ESP in every function prologue. Bug: http://b/73140672#comment4 Test: lunch aosp_x86-eng; m; emulator; device boots Test: manual Change-Id: I921fd7848cdc611b4f8f13d1176d1983ffea952d --- linker/Android.bp | 4 +--- linker/arch/x86/{begin.c => begin.S} | 32 ++++++++++------------------ 2 files changed, 12 insertions(+), 24 deletions(-) rename linker/arch/x86/{begin.c => begin.S} (72%) diff --git a/linker/Android.bp b/linker/Android.bp index 50587f27e..b6fcf4947 100644 --- a/linker/Android.bp +++ b/linker/Android.bp @@ -104,9 +104,7 @@ cc_binary { version_script: "linker.generic.map", }, x86: { - srcs: ["arch/x86/begin.c"], - - cflags: ["-D__work_around_b_24465209__"], + srcs: ["arch/x86/begin.S"], version_script: "linker.generic.map", }, x86_64: { diff --git a/linker/arch/x86/begin.c b/linker/arch/x86/begin.S similarity index 72% rename from linker/arch/x86/begin.c rename to linker/arch/x86/begin.S index 331b79e17..3812646e6 100644 --- a/linker/arch/x86/begin.c +++ b/linker/arch/x86/begin.S @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2018 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,28 +26,18 @@ * SUCH DAMAGE. */ -#include -#include +#include -extern unsigned __linker_init(void* raw_args); - -__LIBC_HIDDEN__ void _start() { +ENTRY(_start) // Force unwinds to end in this function. - asm volatile(".cfi_undefined \%eip"); + .cfi_undefined %eip - void (*start)(void); - - void* raw_args = (void*) ((uintptr_t) __builtin_frame_address(0) + sizeof(void*)); - start = (void(*)(void))__linker_init(raw_args); + movl %esp, %eax // %esp is aligned to 16 here. + subl $12, %esp + pushl %eax + call __linker_init // %esp is aligned to 16 before the call. + addl $16, %esp /* linker init returns (%eax) the _entry address in the main image */ - /* entry point expects sp to point to raw_args */ - - __asm__ ( - "mov %0, %%esp\n\t" - "jmp *%1\n\t" - : : "r"(raw_args), "r"(start) : - ); - - /* Unreachable */ -} + jmp *%eax +END(_start)