aarch64: Fix negative movrel offsets for windows

Message ID 1502015924-17049-1-git-send-email-martin@martin.st
State Committed
Commit 7b7760ad6efb7b96122aa7133ad21e22653ae222
Headers show

Commit Message

Martin Storsjö Aug. 6, 2017, 10:38 a.m.
On windows, the offset for the relocation doesn't get stored in
the relocation itself, but as an unsigned immediate in the opcode.
Therefore, negative offsets has to be handled via a separate sub
instruction, just as on MachO.
---
 libavutil/aarch64/asm.S | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Luca Barbato Aug. 6, 2017, 1:58 p.m. | #1
On 06/08/2017 12:38, Martin Storsjö wrote:
> On windows, the offset for the relocation doesn't get stored in
> the relocation itself, but as an unsigned immediate in the opcode.
> Therefore, negative offsets has to be handled via a separate sub
> instruction, just as on MachO.
> ---
>  libavutil/aarch64/asm.S | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
> index 86d36cd..7e2af4d 100644
> --- a/libavutil/aarch64/asm.S
> +++ b/libavutil/aarch64/asm.S
> @@ -82,6 +82,15 @@ ELF     .size   \name, . - \name
>          adrp            \rd, \val+(\offset)@PAGE
>          add             \rd, \rd, \val+(\offset)@PAGEOFF
>      .endif
> +#elif CONFIG_PIC && defined(_WIN32)
> +    .if \offset < 0
> +        adrp            \rd, \val
> +        add             \rd, \rd, :lo12:\val
> +        sub             \rd, \rd, -(\offset)
> +    .else
> +        adrp            \rd, \val+(\offset)
> +        add             \rd, \rd, :lo12:\val+(\offset)
> +    .endif
>  #elif CONFIG_PIC
>          adrp            \rd, \val+(\offset)
>          add             \rd, \rd, :lo12:\val+(\offset)
> 

Seems fine

Patch

diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index 86d36cd..7e2af4d 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -82,6 +82,15 @@  ELF     .size   \name, . - \name
         adrp            \rd, \val+(\offset)@PAGE
         add             \rd, \rd, \val+(\offset)@PAGEOFF
     .endif
+#elif CONFIG_PIC && defined(_WIN32)
+    .if \offset < 0
+        adrp            \rd, \val
+        add             \rd, \rd, :lo12:\val
+        sub             \rd, \rd, -(\offset)
+    .else
+        adrp            \rd, \val+(\offset)
+        add             \rd, \rd, :lo12:\val+(\offset)
+    .endif
 #elif CONFIG_PIC
         adrp            \rd, \val+(\offset)
         add             \rd, \rd, :lo12:\val+(\offset)