aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.

Message ID 20190821194013.50497-1-martin@martin.st
State Committed
Commit e5afa1b556542fd7a52a0a9b409c80f2e6e1e9bb
Headers show
Series
  • aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
Related show

Commit Message

Martin Storsjö Aug. 21, 2019, 7:40 p.m.
From: Peter Collingbourne <pcc@google.com>

As of LLVM r368102, Clang will set a pointer tag in bits 56-63 of the
address of a global when compiling with -fsanitize=hwaddress. This requires
an adjustment to assembly code that takes the address of such globals: the
code cannot use the regular R_AARCH64_ADR_PREL_PG_HI21 relocation to refer
to the global, since the tag would take the address out of range. Instead,
the code must use the non-checking (_NC) variant of the relocation (the
link-time check is substituted by a runtime check).

This change makes the necessary adjustment in the movrel macro, where it is
needed when compiling with -fsanitize=hwaddress.

Signed-off-by: Peter Collingbourne <pcc@google.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
---
 libavutil/aarch64/asm.S | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Janne Grunau Aug. 22, 2019, 7:12 a.m. | #1
On 2019-08-21 22:40:13 +0300, Martin Storsjö wrote:
> From: Peter Collingbourne <pcc@google.com>
> 
> As of LLVM r368102, Clang will set a pointer tag in bits 56-63 of the
> address of a global when compiling with -fsanitize=hwaddress. This requires
> an adjustment to assembly code that takes the address of such globals: the
> code cannot use the regular R_AARCH64_ADR_PREL_PG_HI21 relocation to refer
> to the global, since the tag would take the address out of range. Instead,
> the code must use the non-checking (_NC) variant of the relocation (the
> link-time check is substituted by a runtime check).
> 
> This change makes the necessary adjustment in the movrel macro, where it is
> needed when compiling with -fsanitize=hwaddress.
> 
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
>  libavutil/aarch64/asm.S | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
> index bf5c1b7ee1..81d723b9b3 100644
> --- a/libavutil/aarch64/asm.S
> +++ b/libavutil/aarch64/asm.S
> @@ -32,6 +32,10 @@
>  #   define FUNC #
>  #endif
>  
> +#ifndef __has_feature
> +#   define __has_feature(x) 0
> +#endif
> +
>  .macro  function name, export=0, align=2
>      .macro endfunc
>  ELF     .size   \name, . - \name
> @@ -94,7 +98,11 @@ ELF     .size   \name, . - \name
>          add             \rd, \rd, :lo12:\val+(\offset)
>      .endif
>  #elif CONFIG_PIC
> +#   if __has_feature(hwaddress_sanitizer)
> +        adrp            \rd, :pg_hi21_nc:\val+(\offset)
> +#   else
>          adrp            \rd, \val+(\offset)
> +#   endif
>          add             \rd, \rd, :lo12:\val+(\offset)
>  #else
>          ldr             \rd, =\val+\offset

ok

Janne

Patch

diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index bf5c1b7ee1..81d723b9b3 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -32,6 +32,10 @@ 
 #   define FUNC #
 #endif
 
+#ifndef __has_feature
+#   define __has_feature(x) 0
+#endif
+
 .macro  function name, export=0, align=2
     .macro endfunc
 ELF     .size   \name, . - \name
@@ -94,7 +98,11 @@  ELF     .size   \name, . - \name
         add             \rd, \rd, :lo12:\val+(\offset)
     .endif
 #elif CONFIG_PIC
+#   if __has_feature(hwaddress_sanitizer)
+        adrp            \rd, :pg_hi21_nc:\val+(\offset)
+#   else
         adrp            \rd, \val+(\offset)
+#   endif
         add             \rd, \rd, :lo12:\val+(\offset)
 #else
         ldr             \rd, =\val+\offset