Add a __x86.get_pc_thunk.bx helper function
Copied from bionic/libc/arch-x86/bionic/__x86.get_pc_thunk.S
Ordinarily, GCC would emit this function into any object file that
calls it, but ART isn't necessarily linked against any GCC-compiled
code anymore on Android. Clang's way of doing this is to use a pattern
like:
call 1f; 1: popl %ebx; 2: addl $_GLOBAL_OFFSET_TABLE_+(2b-1b), %ebx
...but it seems fragile to use local labels buried under several macro
expansions. .altmacro's LOCAL directive seems like it would help with
the scoping, but LLVM doesn't have it yet.
Currently ART is probably calling one of the copies of this function in
libatomic.a, a prebuilt packaged with GCC. After removing libatomic.a,
this thunk needs to be defined somewhere else.
Bug: none
Test: treehugger
Change-Id: I0254932abcfa0bae3af5ebfb237b97d594c45d34
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 3de88d7..5c6e481 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -327,6 +327,7 @@
"interpreter/mterp/mterp.cc",
"interpreter/mterp/nterp_stub.cc",
":libart_mterp.x86",
+ "arch/x86/__x86.get_pc_thunk.S",
"arch/x86/context_x86.cc",
"arch/x86/entrypoints_init_x86.cc",
"arch/x86/jni_entrypoints_x86.S",
diff --git a/runtime/arch/x86/__x86.get_pc_thunk.S b/runtime/arch/x86/__x86.get_pc_thunk.S
new file mode 100644
index 0000000..9dda2bf
--- /dev/null
+++ b/runtime/arch/x86/__x86.get_pc_thunk.S
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+// Typically GCC outputs functions like these into any object file that needs a PIC base register,
+// and one of the copies for each register is used. Clang doesn't use these functions, but
+// SETUP_GOT_NOSAVE in asm_support_x86.S calls this one.
+
+ .section .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
+ .globl __x86.get_pc_thunk.bx
+ .hidden __x86.get_pc_thunk.bx
+ .p2align 4
+ .type __x86.get_pc_thunk.bx,@function
+__x86.get_pc_thunk.bx:
+ .cfi_startproc
+ movl (%esp), %ebx
+ ret
+ .cfi_endproc