public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S
@ 2017-09-07  7:34 wangboshi
  2017-09-07 11:43 ` Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: wangboshi @ 2017-09-07  7:34 UTC (permalink / raw)
  To: libc-alpha

eXecute-Only Memory (XOM) is a protection mechanism against some ROP attacks. XOM sets the code as executable and unreadable, so the access to any data, like literal pools, in the code section causes the fault with XOM. The compiler can disable literal pools for C source files, but not for assembly files, so I use movz/movk instead of literal pools in start.S for XOM.

I add MOVL macro with movz/movk instructions like movl pseudo-instruction in armasm, and use the macro instead of literal pools.


2017-09-07  Wang Boshi  <wangboshi@huawei.com>

     * sysdeps/aarch64/start.S: Use MOVL instead of literal pools.
     * sysdeps/aarch64/sysdep.h (MOVL): Add MOVL macro.

diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S
index df1c642..51e8e82 100644
--- a/sysdeps/aarch64/start.S
+++ b/sysdeps/aarch64/start.S
@@ -71,9 +71,9 @@ _start:
      ldr     PTR_REG (4), [x4, #:got_lo12:__libc_csu_fini]
  #else
      /* Set up the other arguments in registers */
-    ldr    PTR_REG (0), =main
-    ldr    PTR_REG (3), =__libc_csu_init
-    ldr    PTR_REG (4), =__libc_csu_fini
+    MOVL(0, main)
+    MOVL(3, __libc_csu_init)
+    MOVL(4, __libc_csu_fini)
  #endif

      /* __libc_start_main (main, argc, argv, init, fini, rtld_fini,
diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index a749a70..0a11b57 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -137,6 +137,20 @@
      ldr    PTR_REG (T), [x##T, #:got_lo12:EXPR];    \
      OP    PTR_REG (R), [x##T];

+/* Load an immediate into R.
+   Note R is a register number and not a register name. */
+#ifdef __LP64__
+# define MOVL(n, name)                    \
+    movz    PTR_REG(n), #:abs_g3:name;        \
+    movk    PTR_REG(n), #:abs_g2_nc:name;        \
+    movk    PTR_REG(n), #:abs_g1_nc:name;        \
+    movk    PTR_REG(n), #:abs_g0_nc:name;
+#else
+# define MOVL(n, name)                    \
+    movz    PTR_REG(n), #:abs_g1:name;        \
+    movk    PTR_REG(n), #:abs_g0_nc:name;
+#endif
+
  /* Since C identifiers are not normally prefixed with an underscore
     on this system, the asm identifier `syscall_error' intrudes on the
     C name space.  Make sure we use an innocuous name.  */


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-09-18 17:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-07  7:34 [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S wangboshi
2017-09-07 11:43 ` Florian Weimer
2017-09-11  8:58   ` Szabolcs Nagy
2017-09-11  9:09 ` Andrew Pinski
2017-09-11  9:24   ` Szabolcs Nagy
2017-09-12  8:54   ` Boshi Wang
2017-09-11  9:11 ` Szabolcs Nagy
     [not found]   ` <336560e5-c9de-08bc-c850-28994cac2c33@huawei.com>
2017-09-14  8:35     ` Szabolcs Nagy
2017-09-15  1:16       ` Boshi Wang
2017-09-18 17:21         ` Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).