From patchwork Thu Sep 7 07:33:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boshi Wang X-Patchwork-Id: 810876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-84284-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="WBgNXc16"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xnsfK1w1gz9sRY for ; Thu, 7 Sep 2017 17:34:33 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=ymI pz/c0K+i6ImyDMe4kZ7K5brIEWP9Ei2HpvBol0iRMwFjZizB+HN2qTfyHFMEV6dH fJYmCafe7KUffHS9lbdk2ij2LDqWlUgbLmAF94vswjuaULyeoOBfp70DfkhvTOUy gfWgKgRzVpFCDPv3C0soDNJ7yr8yry0oMElOJfCM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type:content-transfer-encoding; s=default; bh=1td752bK6 dILo/Wp//IYRzeJnP8=; b=WBgNXc160GEj5RbNlQFAUioEW3E3BGr1++1hmY2SC aOPufJ505FKOKtV86b4ql/9K3MPGJsGsjCeTpnA/RVoLPRep6rbqkhVX+uhU8n4x DJziIdNiLldQUabOWAXcXZFqFENTjL3qQPg2dskWj1rj+0e2n+SZatAVmfYVaQP3 Gk= Received: (qmail 17081 invoked by alias); 7 Sep 2017 07:34:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 16885 invoked by uid 89); 7 Sep 2017 07:34:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=attacks X-HELO: szxga05-in.huawei.com To: From: wangboshi Subject: [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S Message-ID: Date: Thu, 7 Sep 2017 15:33:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0202.59B0F678.0151, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 462c1a3e35d5506de521ba84cbbdfb28 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 * 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. */