Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1289744rdb; Mon, 21 Aug 2023 03:25:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuex081oWD2Ma4qqr3qb7eA2JWUWUsr1mDBX3gIDXDSBA1bv5mUvDgL+XZBWTzzotN5MJZ X-Received: by 2002:a05:6358:9925:b0:135:57d0:d173 with SMTP id w37-20020a056358992500b0013557d0d173mr5842174rwa.20.1692613531892; Mon, 21 Aug 2023 03:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692613531; cv=none; d=google.com; s=arc-20160816; b=D8KMVGWchXMG3Ak7YowqE442avfDC2Y7MmDYtJN5vsgo4hotizBZt/V0xuNfUOs7a0 OVepkuAvvot1xUNobQ/XnrP7Wfk97J2eLzxCeAvMghONgyhya5a62hSiAkx1K7GKROTf k1NMh7aadTSTdS6Te06op6ScBZbqtc9az97xyIYUKDB8LRyvMv7CTiSb1nEeieOhpYrS qFiqXgboZDDnnwAW4rYwxFSkaYh5ADtWEDL51VLaH7bRt8TVaUxnOVHoAbEmx2aWT5OT V0TYLQ9Of7UzhWeZNgEV4o6rh71Jzfo74A0u0smALIpOeS/s50E7TY6uDYosF7gKRNBQ IvXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from; bh=LNhsOK0qyI8PvMRH+92AKZlyquE+g1IqEgDYlC9KWBo=; fh=5aV1V3I65jisUX3scVb2su7x5UddyqVNSIqyaLNxcXU=; b=uPd/6Vtg/Tli2PjZ/6klb3fWzBxPbYS0jt6fchvdy2OCnB78dkCkxXjAzOtRPjmHit SzzHLGV+c84DJeoQ0CilhcCnEnSBQb+4IlM0ZLV8w9v20Q9kCftu47KbHTy4Ml1c/P+V 3J7hPZVXuJ6k7/ZeI+2hfHt86gy2OJjZZYNdPCk3nFM/W4+xfY1GX86tGvxxFXresbOx b3hSMyqGELiM/Rc7PX9OitKsJcRdaWgsQOTRFKzV3PYSbB2/UayCrY2PW3pzRqL29oZm gTc0fnu2YKE058kFbcSR0ej1IEHfRGi8FaRMZooIbnQU52fO18NRZa2oiBw9S5xNXkrG CRJw== 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 a7-20020a656407000000b00553c4551a08si7183862pgv.887.2023.08.21.03.25.19; Mon, 21 Aug 2023 03:25:31 -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 S230449AbjHTSbw (ORCPT + 99 others); Sun, 20 Aug 2023 14:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbjHTSbt (ORCPT ); Sun, 20 Aug 2023 14:31:49 -0400 X-Greylist: delayed 454 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 20 Aug 2023 11:27:04 PDT Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 602DDAF; Sun, 20 Aug 2023 11:27:03 -0700 (PDT) Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id EF0FC72C981; Sun, 20 Aug 2023 21:19:27 +0300 (MSK) Received: from beacon.altlinux.org (unknown [193.43.10.9]) by imap.altlinux.org (Postfix) with ESMTPSA id E459836D0165; Sun, 20 Aug 2023 21:19:27 +0300 (MSK) From: Vitaly Chikunov To: Willy Tarreau , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC] tools/nolibc: x86_64: Make it compile with -pie Date: Sun, 20 Aug 2023 21:19:00 +0300 Message-Id: <20230820181900.3786107-1-vt@altlinux.org> X-Mailer: git-send-email 2.33.8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 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