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 674353858033 for ; Fri, 2 Feb 2024 13:30:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 674353858033 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 674353858033 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=1706880607; cv=none; b=onX3KBtoQ0vOg99H5Y2KhYJV2x3b/gJEpczmRwh/3dohmqvudtSjOqH4PMz9G2fJIhzU6Qn3iGtQydg2nDQw5EOviXAAh0MQJSomVWiCYw6pYtd38ZZ3bK2JaE1hYP5nUyD0uArDSk5THPiff5SVrM1d06vE/bebRfGC01vMVy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706880607; c=relaxed/simple; bh=r62pLCETVMFrbQtRwFDYDWRsGgVl9ambQkuJOUy/43I=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=BuDU32Qw8RHcW/WMknHIH9Ok89vefm5Cp3S4tijrRtvEC4EG5NGpjUGELSRu/OujiPUiJ9IhP0T3//3NcekSZdsPWsl8dOZ8czfIlGnRAodTQaU6C+ri+wCrGutFYEQPOPUrECyGJwLbFR7KuTadUmLb66V2CECPpMIlsdKdO/Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 8041292009C; Fri, 2 Feb 2024 14:30:04 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 7820D92009B; Fri, 2 Feb 2024 13:30:04 +0000 (GMT) Date: Fri, 2 Feb 2024 13:30:04 +0000 (GMT) From: "Maciej W. Rozycki" To: YunQiang Su cc: Nick Clifton , binutils@sourceware.org, xry111@xry111.site Subject: Re: [PATCH v4] MIPS: Support PCREL GOT access In-Reply-To: <20240202125105.1504614-1-syq@gcc.gnu.org> Message-ID: References: <20240202125105.1504614-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=-3494.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Fri, 2 Feb 2024, YunQiang Su wrote: > Current if we need to access a GOT entry, we use the > got_base + offset. Thus we have GOT and XGOT. > >From MIPSr6, we have PCREL instructions like ALUIPC, I'm assuming ">" above is a typo; overall the change description may need a little bit polishing, but let's leave it until all the issues with code itself have been sorted. > so we have no need to use got_base now. > For pre-R6, we can use BAL to get the the value of PC. I've skimmed over your change and spotted a couple of issues right away, as noted below. I'll go through your change more thoroughly again. Have the new relocations been formally documented anywhere? > diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c > index 489a461bb0b..dc4e56d1f55 100644 > --- a/bfd/elf64-mips.c > +++ b/bfd/elf64-mips.c > @@ -1670,6 +1782,118 @@ static reloc_howto_type mips_elf64_howto_table_rela[] = > 0x0000ffff, /* dst_mask */ > true), /* pcrel_offset */ > > + HOWTO (R_MIPS_GOTPC_HI16, /* type */ > + 16, /* rightshift */ > + 4, /* size */ > + 16, /* bitsize */ > + true, /* pc_relative */ > + 0, /* bitpos */ > + complain_overflow_signed, /* complain_on_overflow */ > + _bfd_mips_elf_generic_reloc, /* special_function */ > + "R_MIPS_GOTPC_HI16", /* name */ > + true, /* partial_inplace */ > + 0x0000ffff, /* src_mask */ > + 0x0000ffff, /* dst_mask */ > + true), /* pcrel_offset */ For RELA relocations you need to set `partial_inplace' to `false' and `src_mask' to 0, because they do not store the addend in the field relocated. Likewise throughout and with n32. > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c > index 69dd71419ff..c8a9ceb7524 100644 > --- a/bfd/elfxx-mips.c > +++ b/bfd/elfxx-mips.c > @@ -2267,19 +2267,28 @@ got_page_reloc_p (unsigned int r_type) > static inline bool > got_lo16_reloc_p (unsigned int r_type) > { > - return r_type == R_MIPS_GOT_LO16 || r_type == R_MICROMIPS_GOT_LO16; > + return r_type == R_MIPS_GOT_LO16 > + || r_type == R_MIPS_GOTPC_LO16 > + || r_type == R_MIPS_GOTPC_ALO16 > + || r_type == R_MICROMIPS_GOT_LO16; > } Please follow the GNU coding style, i.e.: return (r_type == R_MIPS_GOT_LO16 || r_type == R_MIPS_GOTPC_LO16 || r_type == R_MIPS_GOTPC_ALO16 || r_type == R_MICROMIPS_GOT_LO16); Likewise throughout. Maciej