From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 7AA073858C35 for ; Wed, 7 Feb 2024 11:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AA073858C35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7AA073858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707303810; cv=none; b=PYJH/YplUrPXUj1DHIQ7vPmwuXwA+tWXsXuc1ov7mPE18/HGDfXvpTjr/e1Mn1iiRF4wkwDr+CiJ0EDFYY4Ep5uqrC0E4TsCnfr/S5zEQ89HANS/QSMDYVHwjKX8tptC7E7zm21t1R+CBexug+MoyGaoXsR61zeq3dXMTO+w6eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707303810; c=relaxed/simple; bh=Y2cifU9/cPI1RUDLDK1OtpOXkt7Vn+x7HmOLFjh+p8g=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=ZWeCdtrD+DtThE86WTfkKUmjuFtr70/2Dp0EPfdug0iE61355O/w7F6+pKD+u1Vzgf0IXG1fi70aOEH6UuRNplatNJoMlO72n5reOUPOSnEJX0jggik0/nuQHOWDIBnTU9W/DUBqvtBwhL7oznR8xKIHS8vbl/EkbPEgNcmoW6k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id D8DC192009C; Wed, 7 Feb 2024 12:03:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id CA6F692009B; Wed, 7 Feb 2024 11:03:27 +0000 (GMT) Date: Wed, 7 Feb 2024 11:03:27 +0000 (GMT) From: "Maciej W. Rozycki" To: YunQiang Su cc: Nick Clifton , binutils@sourceware.org, xry111@xry111.site Subject: Re: [PATCH v4] MIPS/Gas: Disallow branch to absolute address for PIC In-Reply-To: Message-ID: References: <20240206170538.2937169-1-syq@gcc.gnu.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3488.5 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 7 Feb 2024, YunQiang Su wrote: > > NAK, `mips_pic' may be set to SVR4_PIC and still produce de facto non-PIC > > code, as per the original SVR4 MIPS ABI (with lazy binding stubs rather > > than PLT). We continue supporting this mode. > > > > Originally NO_PIC was intended for bare metal code only, statically > > linked only, which was later extended to Linux, etc. with the addition of > > PLT and copy reloc support. > > > > PR31343 has to be sorted in the linker. > > > > So, what's the expected behavior? The static linker is supposed to report, as a warning or an error (depending on what BFD's policy is), that it cannot resolve a relocation, either due to an overflow or due to the inability to emit a suitable dynamic relocation so as to defer the calculation to the dynamic loader. > Let's use the example: > .set noreorder > .set nomicromips > .set nomips16 > b (4) > INSN0 > INSN1 > INSN2 > INSN3 > > At least we have 2 choice: > 1. jump to INSN0, if we treat (4) same with (. + 4). > 2. jump to INSN1, if we treat (4) as the offset in ISA document: > "An 18-bit signed offset (the 16-bit offset field shifted left 2 > bits) is added > to the address of the instruction following the branch (not the > branch itself), > in the branch delay slot, to form a PC-relative effective target address." > > Currently, this syntax is not supported by ld even for static at all: > > xx: > b (8) > ssnop > ssnop > ssnop > ssnop > > mipsel-linux-gnu-gcc -mno-shared -mno-abicalls -static -nostdlib 1.s > warning: cannot find entry symbol __start; defaulting to 00400110 > /tmp/ccdHuq6V.o: in function `xx': > (.text+0x0): relocation truncated to fit: R_MIPS_PC16 against `*UND*' I gave valid use examples in PR31343 that link correctly. I can image a tiny bare-metal app using branches to hardcoded locations for one reason or another. Tools ought not to stand in the way (a general engineering principle and one of the GNU project in particular too). Maciej