Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1026525rdb; Sun, 20 Aug 2023 13:39:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/N8UIODcft06tPsYjURIyIn++MVWypVSfWFnmKA2KtQyu6cr3Oa03RkSAWoFCy7B3SWAV X-Received: by 2002:a05:6512:3d1d:b0:4fb:7b2a:78de with SMTP id d29-20020a0565123d1d00b004fb7b2a78demr4137592lfv.45.1692563957254; Sun, 20 Aug 2023 13:39:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692563957; cv=none; d=google.com; s=arc-20160816; b=EF+TOWPigetC0O/oKzlGG/kQpFa1Si5ocYV/vcSshl/78XhmElJG7Ff72BJFWhtnft 4F1vJijIW/BarHJz7g6MCv452Zn3BNz/eggYy47tJxkfzGQ4FhmmWxzl0xy7anDlxwo2 q8lDR5ZGL23stpIueyHBHe9CMtmI0xXzL7RsWAJRlUJn57oNRGl9Fs/wOS7D4reRWdOW hqZH94SSHhbI/+rbpPUWlq1ntFAEjEZYap86cjVYxyw6ZU86OlnuweRcP0hd/910DFrM 4sFQlwSJWTLflBceWeOR3Xh3AZfOAb18CdVMwFoQhZPGsuWDoRUfUgEx2tkM6WwssBak TO9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=V9ln3TdJwG5T7SeM0UIZez9JkkMcWRwP2C3SNRFTu0Q=; fh=jn/e2h6Uy1oYBT6q5tq3ohbHsWCa78Vri7PUfWCnePI=; b=HNMIvmz0aS+EYZ1aJUzMxymogZs+ZbSn+OnW2zYaZEnyn0Ij5zYMqYa7RX7DT/5HOt 7/sEB3MMk6XbRgIMTPnXJmbHi0K9jiGFByAl0h+eTw7tiW1cc6E2b4dH1dcHoqZaZXIB 9WzbP9jHlHKuJfSm3TGt3Q+kMU/VjsYLzghDSkQM0nQD3zp/hreAF7T81lqf3G8m/tx0 6aGJ2MyiDtKibD/8m+5203XGI1Wvu/V8Kr2OqEkBOeSg3sGKWfGLCvtkvsbC3q0IPsLX VE0emFHdRXk/yKXHUZhIVSUa6S5wSkeNEi/JRUenprSq9xcmYfjQtENlkbC95B53uUTN 8bhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1-20020aa7d741000000b00523402c3957si4343345eds.102.2023.08.20.13.38.53; Sun, 20 Aug 2023 13:39:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbjHTTcd (ORCPT + 99 others); Sun, 20 Aug 2023 15:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbjHTTc0 (ORCPT ); Sun, 20 Aug 2023 15:32:26 -0400 Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9EE931A2; Sun, 20 Aug 2023 12:28:09 -0700 (PDT) Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id D870472C981; Sun, 20 Aug 2023 22:28:08 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id D0C0E36D0165; Sun, 20 Aug 2023 22:28:08 +0300 (MSK) Date: Sun, 20 Aug 2023 22:28:08 +0300 From: Vitaly Chikunov To: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [RFC] tools/nolibc: x86_64: Make it compile with -pie Message-ID: <20230820192808.dm65aenmbrton6vy@altlinux.org> References: <20230820181900.3786107-1-vt@altlinux.org> <76af26a2-bf31-4397-8e9c-f15a8c9dac18@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <76af26a2-bf31-4397-8e9c-f15a8c9dac18@t-8ch.de> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thomas, On Sun, Aug 20, 2023 at 09:13:51PM +0200, Thomas Weißschuh wrote: > On 2023-08-20 21:19:00+0300, Vitaly Chikunov wrote: > > Use RIP-relative addressing when setting `environ` and `_auxv` in > > startup code. > > > > Some toolchains have `-pie` enabled by default. On them or when -pie is > > specified manually gcc produces error like this: > > > > ld: /tmp/cci0uPcR.o: relocation R_X86_64_32S against symbol `environ' can not be used when making a PIE object; recompile with -fPIE > > ld: failed to set dynamic section sizes: bad value > > > > This is because asm() startup code accesses there pointers with absolute > > addressing. > > > > This may inspire others to fix the problem for other architectures too. > > > > Signed-off-by: Vitaly Chikunov > > --- > > tools/include/nolibc/arch-x86_64.h | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h > > index 6fc4d8392742..a6be44b333ce 100644 > > --- a/tools/include/nolibc/arch-x86_64.h > > +++ b/tools/include/nolibc/arch-x86_64.h > > @@ -199,14 +199,14 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_pr > > "pop %rdi\n" /* argc (first arg, %rdi) */ > > "mov %rsp, %rsi\n" /* argv[] (second arg, %rsi) */ > > "lea 8(%rsi,%rdi,8),%rdx\n" /* then a NULL then envp (third arg, %rdx) */ > > - "mov %rdx, environ\n" /* save environ */ > > + "mov %rdx, environ(%rip)\n" /* save environ */ > > "xor %ebp, %ebp\n" /* zero the stack frame */ > > "mov %rdx, %rax\n" /* search for auxv (follows NULL after last env) */ > > "0:\n" > > "add $8, %rax\n" /* search for auxv using rax, it follows the */ > > "cmp -8(%rax), %rbp\n" /* ... NULL after last env (rbp is zero here) */ > > "jnz 0b\n" > > - "mov %rax, _auxv\n" /* save it into _auxv */ > > + "mov %rax, _auxv(%rip)\n" /* save it into _auxv */ > > "and $-16, %rsp\n" /* x86 ABI : esp must be 16-byte aligned before call */ > > "call main\n" /* main() returns the status code, we'll exit with it. */ > > "mov %eax, %edi\n" /* retrieve exit code (32 bit) */ > > -- > > 2.33.8 > > > > nolibc recently switched to startup code that is mostly implemented in C > instead of assembly. > See the current linux-next tree. > > That should make this change unnecessary I guess. Yes seems so! Zhangjin Wu done a fine job. Thanks, > > > Thomas