[1/3] aarch64: Add an offset parameter to the movrel macro

Message ID 1478685650-22827-1-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Nov. 9, 2016, 10 a.m.
With apple tools, the linker fails with errors like these, if the
offset is negative:

ld: in section __TEXT,__text reloc 8: symbol index out of range for architecture arm64
---
 libavutil/aarch64/asm.S | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Janne Grunau Nov. 10, 2016, 8:38 a.m. | #1
On 2016-11-09 12:00:48 +0200, Martin Storsjö wrote:
> With apple tools, the linker fails with errors like these, if the
> offset is negative:
> 
> ld: in section __TEXT,__text reloc 8: symbol index out of range for architecture arm64
> ---
>  libavutil/aarch64/asm.S | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
> index 6a7f506..3bf9f25 100644
> --- a/libavutil/aarch64/asm.S
> +++ b/libavutil/aarch64/asm.S
> @@ -72,15 +72,21 @@ ELF     .size   \name, . - \name
>  \name:
>  .endm
>  
> -.macro  movrel rd, val
> +.macro  movrel rd, val, offset=0
>  #if CONFIG_PIC && defined(__APPLE__)
> +    .if \offset < 0
>          adrp            \rd, \val@PAGE
>          add             \rd, \rd, \val@PAGEOFF
> +        add             \rd, \rd, \offset

sub \rd, \rd, -(\offset)

as we discovered last night

> +    .else
> +        adrp            \rd, \val+(\offset)@PAGE
> +        add             \rd, \rd, \val+(\offset)@PAGEOFF

I'm a little surprised it works for positive offsets, I should look at 
disassembly. The only reason I can see why the negative offset would 
fail, is that the offset is not considered for @PAGE and @PAGEOFF. That 
would mean this should also fail if the offset is larger than 4095.

Not practical concern though.

> +    .endif
>  #elif CONFIG_PIC
> -        adrp            \rd, \val
> -        add             \rd, \rd, :lo12:\val
> +        adrp            \rd, \val+\offset
> +        add             \rd, \rd, :lo12:\val+\offset
>  #else
> -        ldr             \rd, =\val
> +        ldr             \rd, =\val+\offset
>  #endif
>  .endm


patch ok with fixes in your github repo folded into this

Janne

Patch

diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index 6a7f506..3bf9f25 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -72,15 +72,21 @@  ELF     .size   \name, . - \name
 \name:
 .endm
 
-.macro  movrel rd, val
+.macro  movrel rd, val, offset=0
 #if CONFIG_PIC && defined(__APPLE__)
+    .if \offset < 0
         adrp            \rd, \val@PAGE
         add             \rd, \rd, \val@PAGEOFF
+        add             \rd, \rd, \offset
+    .else
+        adrp            \rd, \val+(\offset)@PAGE
+        add             \rd, \rd, \val+(\offset)@PAGEOFF
+    .endif
 #elif CONFIG_PIC
-        adrp            \rd, \val
-        add             \rd, \rd, :lo12:\val
+        adrp            \rd, \val+\offset
+        add             \rd, \rd, :lo12:\val+\offset
 #else
-        ldr             \rd, =\val
+        ldr             \rd, =\val+\offset
 #endif
 .endm