From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125697 invoked by alias); 11 Sep 2017 09:09:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 125686 invoked by uid 89); 11 Sep 2017 09:09:45 -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,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:Mon, H*RU:209.85.223.195, Hx-spam-relays-external:209.85.223.195 X-HELO: mail-io0-f195.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bK4d7B0AIBp4NLJu3bBc2D76IvD9TpVkP//ZzBPLOlc=; b=QfggblZkIMx39WxkJUBrgCf2WtFdRZVQdZ71sUyZ+MMMKV97d+BCeJkyMziQ4tridU HFr2juFkdoxzp2SbsjVuyyq3tVq6QwvFRJQvU8zIa7JX3j7U3ZTMMCSxaRxOLkngOqxq 1Cn1K1SMjSmHGjHgFkZfbXiybLpVGY0l5l+9STd0DBG3phqRvpxaiLhso2kzqpJLk1iY icHMQYAaOJTBlBK0SgfpVN3ckCGh2T+UkkXd6mdrnb6lS8txWn7tHxMB7H3tx3ZZRT+M OIpqlMNufWXLs/SOoZW86/S5nPeFjO+L6DY9pKf47AxNCXniNK7a25oWVA8XfrSpI7Wu p41Q== X-Gm-Message-State: AHPjjUgGB/Y4Km4Jxgdpac8NFu5WH9h2yQGEdG5fBwNe1hRxvGGKiiwx Z6L4r3N9vyDMulHki+WmJwmSXmujaA== X-Google-Smtp-Source: AOwi7QCEiVdOb/EPDKarQFk1AS73ul+cx2N/5pGFJva8uAHRi6p7QBfwzwr07Cayy4b02bASATopPxof6qAv0Cje3HM= X-Received: by 10.202.235.80 with SMTP id j77mr11044481oih.220.1505120982066; Mon, 11 Sep 2017 02:09:42 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Andrew Pinski Date: Mon, 11 Sep 2017 09:09:00 -0000 Message-ID: Subject: Re: [RFC][PATCH] AArch64: use movz/movk instead of literal pools in start.S To: wangboshi Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2017-09/txt/msg00438.txt.bz2 On Thu, Sep 7, 2017 at 12:33 AM, wangboshi wrote: > 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. I have a few comments about the overall design: I don't know if this is a good idea, can the kernel override XOM anyways? That is if you do write(N, &main, 1024); That will write the main function out to the file? I have one comment about the implementation too. > > > 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 PTR_REG is defined only based on __LP64__ already why don't you just do: #ifdef __LP64__ # define MOVL(n, name) \ movz x##n, #:abs_g3:name; \ movk x##n, #:abs_g2_nc:name; \ movk x##n, #:abs_g1_nc:name; \ movk x##n, #:abs_g0_nc:name; #else # define MOVL(n, name) \ movz w##n, #:abs_g1:name; \ movk w##n, #:abs_g0_nc:name; #endif Thanks, Andrew > + > /* 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. */ > >