]> git.sesse.net Git - x264/commitdiff
arm: Eliminate text relocations in asm
authorJanne Grunau <janne-x264@jannau.net>
Tue, 13 Oct 2015 21:50:11 +0000 (23:50 +0200)
committerHenrik Gramner <henrik@gramner.com>
Sun, 20 Dec 2015 17:38:40 +0000 (18:38 +0100)
Android 6 does not link shared libraries with text relocations.

Make the movrel macro position independent and add movrelx for indirect
loads of external symbols.

Move the function pointer table for the aligned memcpy variants to the
data.rel.ro section on Linux/Android.

common/arm/asm.S
common/arm/mc-a.S
common/arm/quant-a.S

index c363c3816f3c2e542684c3672e9395b8a8fa0221..a96e0a708e1164e01763d93076fd1f61d3746515 100644 (file)
 #   define FUNC @
 #endif
 
+#if SYS_LINUX
+#define HAVE_SECTION_DATA_REL_RO 1
+#else
+#define HAVE_SECTION_DATA_REL_RO 0
+#endif
+
 .macro require8, val=1
 ELF     .eabi_attribute 24, \val
 .endm
@@ -85,8 +91,30 @@ FUNC    .func   \name
 .endif
 .endm
 
+.macro const name, align=2, relocate=0
+    .macro endconst
+ELF     .size   \name, . - \name
+        .purgem endconst
+    .endm
+.if HAVE_SECTION_DATA_REL_RO && \relocate
+        .section        .data.rel.ro
+.else
+        .section        .rodata
+.endif
+        .align          \align
+\name:
+.endm
+
 .macro movrel rd, val
-#if HAVE_ARMV6T2 && !defined(PIC)
+#if defined(PIC)
+        ldr             \rd,  1f
+        b               2f
+1:
+@ FIXME: thumb
+        .word           \val - (2f + 8)
+2:
+        add             \rd,  \rd,  pc
+#elif HAVE_ARMV6T2
         movw            \rd, #:lower16:\val
         movt            \rd, #:upper16:\val
 #else
@@ -94,6 +122,37 @@ FUNC    .func   \name
 #endif
 .endm
 
+.macro movrelx rd, val, got
+#if defined(PIC) && defined(__ELF__)
+        ldr             \got, 2f
+        ldr             \rd,  1f
+        b               3f
+1:
+@ FIXME: thumb
+        .word \val(GOT)
+2:
+        .word _GLOBAL_OFFSET_TABLE_ - (3f + 8)
+3:
+        add             \got, \got, pc
+        ldr             \rd, [\got, \rd]
+#elif defined(PIC) && defined(__APPLE__)
+        ldr             \rd,  1f
+        b               2f
+1:
+@ FIXME: thumb
+        .word           3f - (2f + 8)
+2:
+        ldr             \rd, [pc, \rd]
+        .non_lazy_symbol_pointer
+3:
+        .indirect_symbol \val
+        .word           0
+        .text
+#else
+        movrel          \rd, \val
+#endif
+.endm
+
 .macro movconst rd, val
 #if HAVE_ARMV6T2
     movw        \rd, #:lower16:\val
index 7e5f78c704180426aa95d6f8250e725fb58acfea..767ab1067aac6225979e9e6f8f25c9be935f20e2 100644 (file)
@@ -140,12 +140,13 @@ MEMCPY_ALIGNED 16, 8
 MEMCPY_ALIGNED  8, 16
 MEMCPY_ALIGNED  8, 8
 
-.section .rodata
-memcpy_table:
+const memcpy_table align=2, relocate=1
 .word memcpy_aligned_16_16_neon
 .word memcpy_aligned_16_8_neon
 .word memcpy_aligned_8_16_neon
 .word memcpy_aligned_8_8_neon
+endconst
+
 .text
 
 .ltorg
index 7a2667f16808a0487ede5dc75678e09252f06c53..1a5aa038d3bc9f5185523091fb9ed6e3fec9c9bb 100644 (file)
@@ -346,7 +346,7 @@ function x264_decimate_score\size\()_neon
     lsr         r1,  r1,  #2
 .endif
     rbit        r1,  r1
-    movrel      r3,  X(x264_decimate_table4)
+    movrelx     r3,  X(x264_decimate_table4), r2
 1:
     clz         r2,  r1
     lsl         r1,  r1,  r2
@@ -415,7 +415,7 @@ function x264_decimate_score64_neon
     mvn         r12, r12
     mov         r0,  #0
     mov         lr,  #32
-    movrel      r3,  X(x264_decimate_table8)
+    movrelx     r3,  X(x264_decimate_table8), r2
     beq         2f
 1:
     clz         r2,  r1