From 7e065cd57392772b2ec20388f9cacc1c828995e9 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 17 Feb 2016 18:21:03 -0800 Subject: [PATCH] Copy PIC handling code from x86_abi_support Change-Id: Ia05fe78d2bd29b6aebaf6605719fe8a32528f25c --- third_party/x86inc/README.libvpx | 1 + third_party/x86inc/x86inc.asm | 94 ++++++++++++++++++++++++++++---- 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/third_party/x86inc/README.libvpx b/third_party/x86inc/README.libvpx index 2a75c4ad1..6fe3429d6 100644 --- a/third_party/x86inc/README.libvpx +++ b/third_party/x86inc/README.libvpx @@ -14,3 +14,4 @@ Manage name mangling (prefixing with '_') manually because 'PREFIX' does not exist in libvpx. Expand PIC default to macho64 and respect CONFIG_PIC from libvpx Set 'private_extern' visibility for macho targets. +Copy PIC 'GLOBAL' macros from x86_abi_support.asm diff --git a/third_party/x86inc/x86inc.asm b/third_party/x86inc/x86inc.asm index 112e37288..e28348eef 100644 --- a/third_party/x86inc/x86inc.asm +++ b/third_party/x86inc/x86inc.asm @@ -101,21 +101,93 @@ SECTION .rodata align=%1 %endmacro -%if WIN64 - %define PIC -%elifidn __OUTPUT_FORMAT__,macho64 - %define PIC -%elif ARCH_X86_64 == 0 -; x86_32 doesn't require PIC. -; Some distros prefer shared objects to be PIC, but nothing breaks if -; the code contains a few textrels, so we'll skip that complexity. - %undef PIC -%elif CONFIG_PIC - %define PIC +; PIC macros are copied from vpx_ports/x86_abi_support.asm. The "define PIC" +; from original code is added in for 64bit. +%ifidn __OUTPUT_FORMAT__,elf32 +%define ABI_IS_32BIT 1 +%elifidn __OUTPUT_FORMAT__,macho32 +%define ABI_IS_32BIT 1 +%elifidn __OUTPUT_FORMAT__,win32 +%define ABI_IS_32BIT 1 +%elifidn __OUTPUT_FORMAT__,aout +%define ABI_IS_32BIT 1 +%else +%define ABI_IS_32BIT 0 %endif + +%if ABI_IS_32BIT + %if CONFIG_PIC=1 + %ifidn __OUTPUT_FORMAT__,elf32 + %define GET_GOT_DEFINED 1 + %define WRT_PLT wrt ..plt + %macro GET_GOT 1 + extern _GLOBAL_OFFSET_TABLE_ + push %1 + call %%get_got + %%sub_offset: + jmp %%exitGG + %%get_got: + mov %1, [esp] + add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc + ret + %%exitGG: + %undef GLOBAL + %define GLOBAL(x) x + %1 wrt ..gotoff + %undef RESTORE_GOT + %define RESTORE_GOT pop %1 + %endmacro + %elifidn __OUTPUT_FORMAT__,macho32 + %define GET_GOT_DEFINED 1 + %macro GET_GOT 1 + push %1 + call %%get_got + %%get_got: + pop %1 + %undef GLOBAL + %define GLOBAL(x) x + %1 - %%get_got + %undef RESTORE_GOT + %define RESTORE_GOT pop %1 + %endmacro + %else + %define GET_GOT_DEFINED 0 + %endif + %endif + + %if ARCH_X86_64 == 0 + %undef PIC + %endif + +%else + %macro GET_GOT 1 + %endmacro + %define GLOBAL(x) rel x + %define WRT_PLT wrt ..plt + + %if WIN64 + %define PIC + %elifidn __OUTPUT_FORMAT__,macho64 + %define PIC + %elif CONFIG_PIC + %define PIC + %endif +%endif + +%ifnmacro GET_GOT + %macro GET_GOT 1 + %endmacro + %define GLOBAL(x) x +%endif +%ifndef RESTORE_GOT + %define RESTORE_GOT +%endif +%ifndef WRT_PLT + %define WRT_PLT +%endif + %ifdef PIC default rel %endif +; Done with PIC macros %ifdef __NASM_VER__ %use smartalign