{"id":810876,"url":"http://patchwork.ozlabs.org/api/1.2/patches/810876/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/e65025af-5168-c999-bfc1-7ac614314836@huawei.com/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.2/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<e65025af-5168-c999-bfc1-7ac614314836@huawei.com>","list_archive_url":null,"date":"2017-09-07T07:33:34","name":"[RFC] AArch64: use movz/movk instead of literal pools in start.S","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5c530652a366c40f03065ee8443228d0225b870d","submitter":{"id":72313,"url":"http://patchwork.ozlabs.org/api/1.2/people/72313/?format=json","name":"Boshi Wang","email":"wangboshi@huawei.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/e65025af-5168-c999-bfc1-7ac614314836@huawei.com/mbox/","series":[{"id":1928,"url":"http://patchwork.ozlabs.org/api/1.2/series/1928/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=1928","date":"2017-09-07T07:33:34","name":"[RFC] AArch64: use movz/movk instead of literal pools in start.S","version":1,"mbox":"http://patchwork.ozlabs.org/series/1928/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810876/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810876/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-return-84284-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84284-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"WBgNXc16\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnsfK1w1gz9sRY\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 17:34:33 +1000 (AEST)","(qmail 17081 invoked by alias); 7 Sep 2017 07:34:25 -0000","(qmail 16885 invoked by uid 89); 7 Sep 2017 07:34:24 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:to:from:subject:message-id:date:mime-version\n\t:content-type:content-transfer-encoding; q=dns; s=default; b=ymI\n\tpz/c0K+i6ImyDMe4kZ7K5brIEWP9Ei2HpvBol0iRMwFjZizB+HN2qTfyHFMEV6dH\n\tfJYmCafe7KUffHS9lbdk2ij2LDqWlUgbLmAF94vswjuaULyeoOBfp70DfkhvTOUy\n\tgfWgKgRzVpFCDPv3C0soDNJ7yr8yry0oMElOJfCM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:to:from:subject:message-id:date:mime-version\n\t:content-type:content-transfer-encoding; s=default; bh=1td752bK6\n\tdILo/Wp//IYRzeJnP8=; b=WBgNXc160GEj5RbNlQFAUioEW3E3BGr1++1hmY2SC\n\taOPufJ505FKOKtV86b4ql/9K3MPGJsGsjCeTpnA/RVoLPRep6rbqkhVX+uhU8n4x\n\tDJziIdNiLldQUabOWAXcXZFqFENTjL3qQPg2dskWj1rj+0e2n+SZatAVmfYVaQP3\n\tGk=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-23.9 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tRP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=attacks","X-HELO":"szxga05-in.huawei.com","To":"<libc-alpha@sourceware.org>","From":"wangboshi <wangboshi@huawei.com>","Subject":"[RFC][PATCH] AArch64: use movz/movk instead of literal pools in\n\tstart.S","Message-ID":"<e65025af-5168-c999-bfc1-7ac614314836@huawei.com>","Date":"Thu, 7 Sep 2017 15:33:34 +0800","User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"; format=flowed","Content-Transfer-Encoding":"7bit","X-CFilter-Loop":"Reflected","X-Mirapoint-Virus-RAPID-Raw":"score=unknown(0),\n\trefid=str=0001.0A0B0202.59B0F678.0151, ss=1, re=0.000, recu=0.000,\n\treip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0,\n\tso=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32","X-Mirapoint-Loop-Id":"462c1a3e35d5506de521ba84cbbdfb28"},"content":"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.\n\nI add MOVL macro with movz/movk instructions like movl pseudo-instruction in armasm, and use the macro instead of literal pools.\n\n\n2017-09-07  Wang Boshi  <wangboshi@huawei.com>\n\n     * sysdeps/aarch64/start.S: Use MOVL instead of literal pools.\n     * sysdeps/aarch64/sysdep.h (MOVL): Add MOVL macro.","diff":"diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S\nindex df1c642..51e8e82 100644\n--- a/sysdeps/aarch64/start.S\n+++ b/sysdeps/aarch64/start.S\n@@ -71,9 +71,9 @@ _start:\n      ldr     PTR_REG (4), [x4, #:got_lo12:__libc_csu_fini]\n  #else\n      /* Set up the other arguments in registers */\n-    ldr    PTR_REG (0), =main\n-    ldr    PTR_REG (3), =__libc_csu_init\n-    ldr    PTR_REG (4), =__libc_csu_fini\n+    MOVL(0, main)\n+    MOVL(3, __libc_csu_init)\n+    MOVL(4, __libc_csu_fini)\n  #endif\n\n      /* __libc_start_main (main, argc, argv, init, fini, rtld_fini,\ndiff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h\nindex a749a70..0a11b57 100644\n--- a/sysdeps/aarch64/sysdep.h\n+++ b/sysdeps/aarch64/sysdep.h\n@@ -137,6 +137,20 @@\n      ldr    PTR_REG (T), [x##T, #:got_lo12:EXPR];    \\\n      OP    PTR_REG (R), [x##T];\n\n+/* Load an immediate into R.\n+   Note R is a register number and not a register name. */\n+#ifdef __LP64__\n+# define MOVL(n, name)                    \\\n+    movz    PTR_REG(n), #:abs_g3:name;        \\\n+    movk    PTR_REG(n), #:abs_g2_nc:name;        \\\n+    movk    PTR_REG(n), #:abs_g1_nc:name;        \\\n+    movk    PTR_REG(n), #:abs_g0_nc:name;\n+#else\n+# define MOVL(n, name)                    \\\n+    movz    PTR_REG(n), #:abs_g1:name;        \\\n+    movk    PTR_REG(n), #:abs_g0_nc:name;\n+#endif\n+\n  /* Since C identifiers are not normally prefixed with an underscore\n     on this system, the asm identifier `syscall_error' intrudes on the\n     C name space.  Make sure we use an innocuous name.  */\n","prefixes":["RFC"]}