From patchwork Thu Jan 18 09:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1887840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=duJTyKm3; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KSJP44HB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=duJTyKm3; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KSJP44HB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TFyRM0BnMz1yPv for ; Thu, 18 Jan 2024 20:40:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAEB23858420 for ; Thu, 18 Jan 2024 09:40:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id D8743385841B for ; Thu, 18 Jan 2024 09:40:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8743385841B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8743385841B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705570808; cv=none; b=qRY22VUEl5TB6OcMpidlY1c685lOZmHPIFXvGHgI0l29ZXnMsjoPHGeecD5j1gBUxIpRi4tNwUZknPuL6SpnY1DsYHAAaYeXOMSPHtY1O7qI1Sp7I0xgBkqU1F04dZS7xQiQdtpz5fEDWoRINuBF0c9GdByEZ96VkP2+aiyhvjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705570808; c=relaxed/simple; bh=sSEJ+4cGQnRqrl4vluQrzER20xXDlQFEXyLJp8Eg82A=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=XYMkuswRIgDSuDL4YBYMwYz5pRzsxBeMPNBPgCYfmdsn5we2RyzxQMkxAHEQGPdvb4tYQyo4WPz5AVHM+zL7oJ7MmlrZ8iycbtljeV0pSHSekx5qWM/h6UB14FKUI0FP0poBLMWhotq/kG4wP1onFIipwlEpXNYW/lTYsHIOpds= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [10.168.4.11]) by smtp-out1.suse.de (Postfix) with ESMTP id C675921ECE for ; Thu, 18 Jan 2024 09:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705570804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=4gg036AMav924LM/sPwnG9na9AVWAy6JlcoU9Kj1VeA=; b=duJTyKm3c7Lkt/ZsVpgLTyru0glBOc7p6mkGeL4yY76gUsf9ux6vurWWh2PqyCx5Wg3IpZ ogSQr29GDBbQx2cERgzrjkArAVJJUB0OE6ZobQvq7004UheNDuqyCba9Nwc0tg3Ysv5rTB 2kfxv53ZfuUFA5+FKy41vrQ9n8HMOMQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705570804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=4gg036AMav924LM/sPwnG9na9AVWAy6JlcoU9Kj1VeA=; b=KSJP44HBsCMa3TOwqb+ryvwrLMloKW8dvowi9Kq9hDgsO6QKK83ZcbqP1qHd/4YSo/fjDp A1xlqqAUDarf3VBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705570804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=4gg036AMav924LM/sPwnG9na9AVWAy6JlcoU9Kj1VeA=; b=duJTyKm3c7Lkt/ZsVpgLTyru0glBOc7p6mkGeL4yY76gUsf9ux6vurWWh2PqyCx5Wg3IpZ ogSQr29GDBbQx2cERgzrjkArAVJJUB0OE6ZobQvq7004UheNDuqyCba9Nwc0tg3Ysv5rTB 2kfxv53ZfuUFA5+FKy41vrQ9n8HMOMQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705570804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=4gg036AMav924LM/sPwnG9na9AVWAy6JlcoU9Kj1VeA=; b=KSJP44HBsCMa3TOwqb+ryvwrLMloKW8dvowi9Kq9hDgsO6QKK83ZcbqP1qHd/4YSo/fjDp A1xlqqAUDarf3VBQ== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id B715C4A03B0; Thu, 18 Jan 2024 10:40:04 +0100 (CET) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] riscv: add support for static PIE X-Yow: Will this never-ending series of PLEASURABLE EVENTS never cease? Date: Thu, 18 Jan 2024 10:40:04 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-0.10 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Level: X-Spam-Score: -0.10 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org In order to support static PIE the startup code must avoid relocations before __libc_start_main is called. Reviewed-by: Adhemerval Zanella --- sysdeps/riscv/start.S | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sysdeps/riscv/start.S b/sysdeps/riscv/start.S index 0a1f713742..ede186ef23 100644 --- a/sysdeps/riscv/start.S +++ b/sysdeps/riscv/start.S @@ -50,7 +50,13 @@ ENTRY (ENTRY_POINT) call load_gp mv a5, a0 /* rtld_fini. */ /* main may be in a shared library. */ +#if defined PIC && !defined SHARED + /* Avoid relocation in static PIE since _start is called before it + is relocated. */ + lla a0, __wrap_main +#else la a0, main +#endif REG_L a1, 0(sp) /* argc. */ addi a2, sp, SZREG /* argv. */ andi sp, sp, ALMASK /* Align stack. */ @@ -62,6 +68,11 @@ ENTRY (ENTRY_POINT) ebreak END (ENTRY_POINT) +#if defined PIC && !defined SHARED +__wrap_main: + tail main@plt +#endif + /* Dynamic links need the global pointer to be initialized prior to calling any shared library's initializers, so we use preinit_array to load it. This doesn't cut it for static links, though, since the global pointer