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
diff --git a/linker/Android.bp b/linker/Android.bp
index 50587f2..b6fcf49 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -104,9 +104,7 @@
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 331b79e..3812646 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 <stdint.h>
-#include <sys/cdefs.h>
+#include <private/bionic_asm.h>
-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)