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 0A9B53858C66 for ; Fri, 1 Mar 2024 17:23:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A9B53858C66 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 0A9B53858C66 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=1709313804; cv=none; b=uvjnjqDFi1OmmfiW8tmMGZhL1tSYnv2p6XAh1lwhJ6L2IrdPnGtcyQPdgiUJBSPMOSaXZ7MzFMJF7eaM6qvZrFzlUou0MTRvzNd+YfChExhCV6THSGBxW9p4npdt45AoyE86S5UviO7QG8aZ0CuDLe0nuAF+W/4LZkR852F6lkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709313804; c=relaxed/simple; bh=TXd1oIZI4pNG70wrZb6morbWuAqCDJ1B/pJ7Rfi7JN8=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=LbCDw4HoCFqvuqKO8Os52JaD4U/BKJvwLBDy2MMh6CvkwQI/gew38J7H57c4KV2eOiJaYloEkK1HCWcGC1CyC+YCCgcrDw48just4lVzxfPLUygORdfZ8Cw17TV7cdT655xCrArzMIo6XQ1sU7Tm25zEPN+RPUOngXgOykw+ke8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 35A3092009C; Fri, 1 Mar 2024 18:23:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 2FB1A92009B; Fri, 1 Mar 2024 17:23:22 +0000 (GMT) Date: Fri, 1 Mar 2024 17:23:22 +0000 (GMT) From: "Maciej W. Rozycki" To: YunQiang Su cc: Hans-Peter Nilsson , Nick Clifton , binutils@sourceware.org, xry111@xry111.site Subject: Re: [PATCH v6] MIPS: Reject branch absolute relocs for PIC for linking In-Reply-To: Message-ID: References: <20240221145256.3118097-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 Sun, 25 Feb 2024, YunQiang Su wrote: > > > Good idea. I think that we should use "...against an absolute value". > > > "absolute symbol" is not included in this code, as it's r_symndx is > > > not STN_UNDEF. > > > > Well code says otherwise: > > > > + if (branch_reloc_p (r_type) && r_symndx == STN_UNDEF) > > > > did you mean "the relocation's r_symndx is STN_UNDEF"? > > > > But it can be a relocation against an absolute symbol, for example if the > > symbol referred to by a relocation is supplied by another module in the > > link or a linker script and said symbol is absolute. This case has to be > > I have no idea whether we should emit this error for this case: > If the symbol is set by a linker script, and is near enough with > our instruction, > the object should be ok for PIC? > If not near enough, a "relocation truncated to fit" error will emit. If the symbol referred is absolute, then the case is no different from an absolute relocation. You just can't calculate a PC-relative reference to an absolute value at static link time, because the distance from PC to that value will depend on the base address at load time. It is different from a reference to a regular (non-absolute) symbol that just turns out too distant for a PC-relative relocation to reach (where the "relocation truncated to fit" case applies). Maciej