[x264-devel] arm: Eliminate text relocations in asm

Janne Grunau git at videolan.org
Sun Jan 17 22:17:53 CET 2016


x264 | branch: master | Janne Grunau <janne-x264 at jannau.net> | Tue Oct 13 23:50:11 2015 +0200| [df51d8efa8ce9afcedda64acc69c1dba2648716d] | committer: Henrik Gramner

arm: Eliminate text relocations in asm

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.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=df51d8efa8ce9afcedda64acc69c1dba2648716d
---

 common/arm/asm.S     |   61 +++++++++++++++++++++++++++++++++++++++++++++++++-
 common/arm/mc-a.S    |    5 +++--
 common/arm/quant-a.S |    4 ++--
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/common/arm/asm.S b/common/arm/asm.S
index c363c38..a96e0a7 100644
--- a/common/arm/asm.S
+++ b/common/arm/asm.S
@@ -56,6 +56,12 @@
 #   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
diff --git a/common/arm/mc-a.S b/common/arm/mc-a.S
index 7e5f78c..767ab10 100644
--- a/common/arm/mc-a.S
+++ b/common/arm/mc-a.S
@@ -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
diff --git a/common/arm/quant-a.S b/common/arm/quant-a.S
index 7a2667f..1a5aa03 100644
--- a/common/arm/quant-a.S
+++ b/common/arm/quant-a.S
@@ -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



More information about the x264-devel mailing list