Message ID | ZS4VVi3jhP/DEW9K@squeak.grove.modra.org |
---|---|
State | Accepted |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3903510vqb; Mon, 16 Oct 2023 22:02:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHk3FEyr2lPueI5yb283wWMU0/i4pefLAFGMqbuDEp3Ulq+u75+zHvONAEbLON4FhYKZUUE X-Received: by 2002:a67:a60b:0:b0:452:7232:5c22 with SMTP id p11-20020a67a60b000000b0045272325c22mr1459585vse.18.1697518944045; Mon, 16 Oct 2023 22:02:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697518944; cv=pass; d=google.com; s=arc-20160816; b=bLwG7eX62qy55W28o1NnA+HhMAPaDRFS0U8SJ3tAyAuf8NWrYKUFpn9TLUKhFzeaHR yVKD0nPtXiWRz3Hc6OwTkPYJYRz0V++/D6NMXsfUU1qOvbzwvhfKPxbhBv5P/eOLgIZN /qsE3Y/bcYX6S6TMoBey/vacWiVCVuefbpma0X5/Pqe+gj7lV90y5ReK9BYpCVBOY4dY 89wm3U8jEJpmNnsPobPgvyHQoJIDSzDv8Ol3AjBfrSYw0zYt+/BG/dqkfQYshGdCyUpJ hO51POD7bgzn26rCLL5S7MC1Qh6oVBs2MIJbHoroQC9u40wZxFzojlWgQQbltGLMC5dQ 1dDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=J5sVeGmmaXqaSzZWXFHwl55dhlISxsyOAvzymgBP+q0=; fh=bVUFmfLiPc4JWPtmsbLQ2UpofX97wl2A29vcgx7kqFw=; b=UCFhxYpAZeJKijE2KDbPYmkuA6ep+nn4LYaSRH2XEzoka7l3y3GAaKIJNfWEU59gIO m5CzSVaScf4A9GyvJRGM48Aqq6LLcciifxXx3BQbFxWG26KYYjSZMY3igtKShurG+RkF qWbk+cRvgHZSteL5IkDkpm1NM9ovPALvmO5qSwZ9bS1HKmDqGrXSj6Q/BjCpqCSyZ0b3 UyXahiNuJ7rgmP0bfwlj0f/NKtMARJjdpTn8tMV09bq1Sc4KvhC381/gLxSio5IaTwUB s3w95dH1Ze5BQRbl6Xd603CuhoPy90EUEfX9OlTQGJCg+N5aGaF4fQqXgTFN50MF3Pd5 e15Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZinxKgeN; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e5-20020a056214162500b0065d8846dd43si474285qvw.192.2023.10.16.22.02.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 22:02:24 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZinxKgeN; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAF3C385770B for <ouuuleilei@gmail.com>; Tue, 17 Oct 2023 05:02:23 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 31D543858423 for <binutils@sourceware.org>; Tue, 17 Oct 2023 05:02:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31D543858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 31D543858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697518939; cv=none; b=rkXGIVWvDlfIitLQINAp1hxqCR8gXWdfYFIdA/EBnSu44rsUNLx1Uap16D5YAG+u/w+g0dzaLb6D3ydHvWa5apNqZdXAJUj5RonogyZg5aflV05Q33+03faCyA8LEyEcS5e9iCDNHjZ97WPZ5etlUjEzEeNUewXVgqGK1BejY64= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697518939; c=relaxed/simple; bh=vt++md/mSfNQ/xFjjKORUiX43R0e5DdqIemZnfSTqBY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=aSY2NU+qasuZJYt2jOs6uKmGoxYd/40kqzQzOr9KtIlNrRyX+e55ADA03yzZqH23EMgNg/xaZBP67ktgJmpfu2xGLi/L0IRCsqr76H6QDGTnFfKt3rd30ETKinK7M4wlKjnIDvS9zNpoAcg41r9dcb8SU1fFdzi8GgXBkuimPig= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c9fa869a63so20350435ad.0 for <binutils@sourceware.org>; Mon, 16 Oct 2023 22:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697518937; x=1698123737; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=J5sVeGmmaXqaSzZWXFHwl55dhlISxsyOAvzymgBP+q0=; b=ZinxKgeN2ERWMcKcLrqAZZ+XDg+UcHDwnwYdL+w8YGMrOvV5B4AFmCGx1ppqwW7qoc rOfXyrz0BE6IrQ9MphlQ6K1m2y+CW8TTJCApx7zWCPeZz+HP8eYC/ACciMbIVUlt/DG0 WGveesJ/O9uBuomn3yV44ISp7CadHZLvajMR0r271pFQ0yzU49Gp8Aq21ouYpYQXxHFU R8pKkBsE+WePT0iTVWgHmezoi/R8Vif+HkZO+H2urAdnhBEVsTLpOBn6M+0C6R5Ste9T HnQsz2oJ7P61hyvUDMoNyLrsQToG336Q3PqIPT4wrraUMt29dKa2YgIbIsF8jCO9Lb2n +DAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697518937; x=1698123737; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J5sVeGmmaXqaSzZWXFHwl55dhlISxsyOAvzymgBP+q0=; b=aSHRtIz1YkyJd13dogIHA9hgCN5l2XjBVlLudUwYgUoCEV8rJPe+DIJVl9Q3CxFH/s Wc4Q79HH4xwJpTZwfdXmsErpVONaRC83v+XPSVdNgvE04HzU6dMs0dJkKMRSjRCVfkvI rV2lhxs+AbuX+1GFTK0eqlrHwBQG20PJ+2teGl1xopbfY/IpAo06I70U0hsFOBPCZ2Ms JsE9PdIG4L6fpAHtoAsG6RPw7yO4PvxAGokw/iNxb2a1XXqQ80Zuf5ZT2CpnJ7KUM8T5 q0KKnRLlQVUDGYfKPs6ZDSaKVst3nobIfg4MYBasmIh4iBXXw6rLCd8LRAtee7c1RvOb ggdg== X-Gm-Message-State: AOJu0YyNdQNw+7fz9fKpwXq/76/F8H39gmgUZK3Y5E1WoV9PGmsWjwBG ZHgXl+CrNFhz9hjnTr97pP8= X-Received: by 2002:a17:903:10b:b0:1c9:bef4:e11 with SMTP id y11-20020a170903010b00b001c9bef40e11mr1199943plc.46.1697518937144; Mon, 16 Oct 2023 22:02:17 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id f15-20020a170902ce8f00b001c9dac0fbbasm480631plg.63.2023.10.16.22.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 22:02:16 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4806A11422A7; Tue, 17 Oct 2023 15:32:14 +1030 (ACDT) Date: Tue, 17 Oct 2023 15:32:14 +1030 From: Alan Modra <amodra@gmail.com> To: binutils@sourceware.org Cc: Chenghua Xu <paul.hua.gm@gmail.com>, "Maciej W. Rozycki" <macro@orcam.me.uk> Subject: R_MICROMIPS_GPREL7_S2 Message-ID: <ZS4VVi3jhP/DEW9K@squeak.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3033.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779977624227650467 X-GMAIL-MSGID: 1779977624227650467 |
Series |
R_MICROMIPS_GPREL7_S2
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | success | Github commit url |
Commit Message
Alan Modra
Oct. 17, 2023, 5:02 a.m. UTC
This reloc is specified to operate on a half-word by the howtos in elf32-mips.c, elfn32-mips.c and elf64-mips.c. It is also subject to shuffle/unshuffle in code like _bfd_mips_elf32_gprel16_reloc. I believe there is a contradiction here. Either the reloc should operate on a 32-bit word, or it should not be shuffled. As is, address range checking fails to catch a buffer overflow when the reloc is at the last half-word of a section. This patch takes a guess that it should not be shuffled. I didn't find any ABI docs for the reloc, so I'm not at all sure what to do. Current behaviour when applying the reloc to .byte 0x11,0x22,0x33,0x44 is to apply the reloc to byte 0x22 when big-endian, and to byte 0x33 when little-endian. Big-endian behaviour is unchanged after this patch and little-endian applies the reloc to byte 0x11. * elfxx-mips.c (micromips_reloc_shuffle_p): Return false for R_MICROMIPS_GPREL7_S2.
Comments
On Tue, 17 Oct 2023, Alan Modra wrote: > This reloc is specified to operate on a half-word by the howtos in > elf32-mips.c, elfn32-mips.c and elf64-mips.c. It is also subject to > shuffle/unshuffle in code like _bfd_mips_elf32_gprel16_reloc. I > believe there is a contradiction here. Either the reloc should > operate on a 32-bit word, or it should not be shuffled. As is, > address range checking fails to catch a buffer overflow when the reloc > is at the last half-word of a section. > > This patch takes a guess that it should not be shuffled. I didn't > find any ABI docs for the reloc, so I'm not at all sure what to do. Correct, the relocation is meant for the 16-bit LWGP instruction, 0x6400/0xfc00 match/mask encoding in `micromips_opcodes'. It's not clear to me why it has no support beyond the `.reloc' pseudo-op, maybe it was meant for linker relaxation from microMIPS regular 32-bit LW instruction with $gp as the base register, which has never been implemented. > Current behaviour when applying the reloc to .byte 0x11,0x22,0x33,0x44 > is to apply the reloc to byte 0x22 when big-endian, and to byte 0x33 > when little-endian. Big-endian behaviour is unchanged after this > patch and little-endian applies the reloc to byte 0x11. > > * elfxx-mips.c (micromips_reloc_shuffle_p): Return false for > R_MICROMIPS_GPREL7_S2. > > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c > index 92dd4c20a7d..3a6a91359df 100644 > --- a/bfd/elfxx-mips.c > +++ b/bfd/elfxx-mips.c > @@ -2231,7 +2231,8 @@ micromips_reloc_shuffle_p (unsigned int r_type) > { > return (micromips_reloc_p (r_type) > && r_type != R_MICROMIPS_PC7_S1 > - && r_type != R_MICROMIPS_PC10_S1); > + && r_type != R_MICROMIPS_PC10_S1 > + && r_type != R_MICROMIPS_GPREL7_S2); Can you please update the comment above `micromips_reloc_shuffle_p' accordingly? From this issue it seems to me like we need some testsuite coverage for microMIPS (and maybe general MIPS) relocation processing. Not needed for this fix specifically, but I'll see what I can do about it sometime. Well-spotted, and thank you for fixing this! Maciej
On Tue, Oct 17, 2023 at 08:40:43AM +0100, Maciej W. Rozycki wrote: > Can you please update the comment above `micromips_reloc_shuffle_p' > accordingly? Yes of course, here is a more complete patch. ---- This reloc is meant for the 16-bit LWGP instruction, 0x6400/0xfc00 match/mask encoding in `micromips_opcodes'. It is correctly specified to operate on a half-word by the howtos in elf32-mips.c, elfn32-mips.c and elf64-mips.c, but is incorrectly subject to shuffle/unshuffle in code like _bfd_mips_elf32_gprel16_reloc. Current behaviour when applying the reloc to .byte 0x11,0x22,0x33,0x44 is to apply the reloc to byte 0x22 when big-endian, and to byte 0x33 when little-endian. Big-endian behaviour is unchanged after this patch and little-endian correctly applies the reloc to byte 0x11. The patch also corrects REL addend extraction from section contents, and overflow checking. gold had all of the bfd problems with this reloc and additionally did not apply the rightshift by two. bfd/ * elfxx-mips.c (micromips_reloc_shuffle_p): Return false for R_MICROMIPS_GPREL7_S2. (mips_elf_calculate_relocation): Correct sign extension and overflow calculation for R_MICROMIPS_GPREL7_S2. (_bfd_mips_elf_relocate_section): Update small-data overflow message. gold/ * mips.cc (Mips_relocate_functions::should_shuffle_micromips_reloc): Return false for R_MICROMIPS_GPREL7_S2. (Mips_relocate_functions::mips_reloc_unshuffle): Update comment. (Mips_relocate_functions::relgprel): Remove R_MICROMIPS_GPREL7_S2 handling. (Mips_relocate_functions::relgprel7): New function. (Target_mips::Relocate::relocate): Adjust to suit. ld/ * testsuite/ld-mips-elf/reloc-4.d: Adjust expected error. * testsuite/ld-mips-elf/reloc-5.d: Likewise. diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 92dd4c20a7d..afe864aa7ac 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -2223,15 +2223,17 @@ micromips_reloc_p (unsigned int r_type) } /* Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped - on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1 - and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions. */ + on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1, + R_MICROMIPS_PC10_S1 and R_MICROMIPS_GPREL7_S2 relocs that apply to + 16-bit instructions. */ static inline bool micromips_reloc_shuffle_p (unsigned int r_type) { return (micromips_reloc_p (r_type) && r_type != R_MICROMIPS_PC7_S1 - && r_type != R_MICROMIPS_PC10_S1); + && r_type != R_MICROMIPS_PC10_S1 + && r_type != R_MICROMIPS_GPREL7_S2); } static inline bool @@ -6255,21 +6257,24 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd, case R_MIPS_GPREL16: case R_MICROMIPS_GPREL7_S2: case R_MICROMIPS_GPREL16: - /* Only sign-extend the addend if it was extracted from the - instruction. If the addend was separate, leave it alone, - otherwise we may lose significant bits. */ - if (howto->partial_inplace) - addend = _bfd_mips_elf_sign_extend (addend, 16); - value = symbol + addend - gp; - /* If the symbol was local, any earlier relocatable links will - have adjusted its addend with the gp offset, so compensate - for that now. Don't do it for symbols forced local in this - link, though, since they won't have had the gp offset applied - to them before. */ - if (was_local_p) - value += gp0; - if (was_local_p || h->root.root.type != bfd_link_hash_undefweak) - overflowed_p = mips_elf_overflow_p (value, 16); + { + int bits = howto->bitsize + howto->rightshift; + /* Only sign-extend the addend if it was extracted from the + instruction. If the addend was separate, leave it alone, + otherwise we may lose significant bits. */ + if (howto->partial_inplace) + addend = _bfd_mips_elf_sign_extend (addend, bits); + value = symbol + addend - gp; + /* If the symbol was local, any earlier relocatable links will + have adjusted its addend with the gp offset, so compensate + for that now. Don't do it for symbols forced local in this + link, though, since they won't have had the gp offset applied + to them before. */ + if (was_local_p) + value += gp0; + if (was_local_p || h->root.root.type != bfd_link_hash_undefweak) + overflowed_p = mips_elf_overflow_p (value, bits); + } break; case R_MIPS16_GOT16: @@ -10671,7 +10676,7 @@ _bfd_mips_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, && (gprel16_reloc_p (howto->type) || literal_reloc_p (howto->type))) { - msg = _("small-data section exceeds 64KB;" + msg = _("small-data section too large;" " lower small-data size limit (see option -G)"); htab->small_data_overflow_reported = true; diff --git a/gold/mips.cc b/gold/mips.cc index a6a41d7a5e4..76dd90a5847 100644 --- a/gold/mips.cc +++ b/gold/mips.cc @@ -4348,7 +4348,8 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> { return (micromips_reloc(r_type) && r_type != elfcpp::R_MICROMIPS_PC7_S1 - && r_type != elfcpp::R_MICROMIPS_PC10_S1); + && r_type != elfcpp::R_MICROMIPS_PC10_S1 + && r_type != elfcpp::R_MICROMIPS_GPREL7_S2); } public: @@ -4438,8 +4439,9 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> // little-endian system. // Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped - // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1 - // and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions. + // on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1, + // R_MICROMIPS_PC10_S1 and R_MICROMIPS_GPREL7_S2 relocs that apply + // to 16-bit instructions. static void mips_reloc_unshuffle(unsigned char* view, unsigned int r_type, @@ -5432,13 +5434,12 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> } // R_MIPS_GPREL16, R_MIPS16_GPREL, R_MIPS_LITERAL, R_MICROMIPS_LITERAL - // R_MICROMIPS_GPREL7_S2, R_MICROMIPS_GPREL16 + // R_MICROMIPS_GPREL16 static inline typename This::Status relgprel(unsigned char* view, const Mips_relobj<size, big_endian>* object, const Symbol_value<size>* psymval, Mips_address gp, Mips_address addend_a, bool extract_addend, bool local, - unsigned int r_type, bool calculate_only, - Valtype* calculated_value) + bool calculate_only, Valtype* calculated_value) { Valtype32* wv = reinterpret_cast<Valtype32*>(view); Valtype32 val = elfcpp::Swap<32, big_endian>::readval(wv); @@ -5446,10 +5447,7 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> Valtype addend; if (extract_addend) { - if (r_type == elfcpp::R_MICROMIPS_GPREL7_S2) - addend = (val & 0x7f) << 2; - else - addend = val & 0xffff; + addend = val & 0xffff; // Only sign-extend the addend if it was extracted from the // instruction. If the addend was separate, leave it alone, // otherwise we may lose significant bits. @@ -5468,10 +5466,7 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> if (local) x += object->gp_value(); - if (r_type == elfcpp::R_MICROMIPS_GPREL7_S2) - val = Bits<32>::bit_select32(val, x, 0x7f); - else - val = Bits<32>::bit_select32(val, x, 0xffff); + val = Bits<32>::bit_select32(val, x, 0xffff); if (calculate_only) { @@ -5483,13 +5478,56 @@ class Mips_relocate_functions : public Relocate_functions<size, big_endian> if (check_overflow<16>(x) == This::STATUS_OVERFLOW) { - gold_error(_("small-data section exceeds 64KB; lower small-data size " - "limit (see option -G)")); + gold_error(_("small-data section too large;" + " lower small-data size limit (see option -G)")); return This::STATUS_OVERFLOW; } return This::STATUS_OKAY; } + // R_MICROMIPS_GPREL7_S2 + static inline typename This::Status + relgprel7(unsigned char* view, const Mips_relobj<size, big_endian>* object, + const Symbol_value<size>* psymval, Mips_address gp, + Mips_address addend_a, bool extract_addend, bool local, + bool calculate_only, Valtype* calculated_value) + { + Valtype16* wv = reinterpret_cast<Valtype16*>(view); + Valtype16 val = elfcpp::Swap<16, big_endian>::readval(wv); + + Valtype addend; + if (extract_addend) + { + addend = (val & 0x7f) << 2; + addend = Bits<9>::sign_extend32(addend); + } + else + addend = addend_a; + + Valtype x = psymval->value(object, addend) - gp; + + if (local) + x += object->gp_value(); + + val = Bits<16>::bit_select32(val, x >> 2, 0x7f); + + if (calculate_only) + { + *calculated_value = x; + return This::STATUS_OKAY; + } + else + elfcpp::Swap<16, big_endian>::writeval(wv, val); + + if (check_overflow<9>(x) == This::STATUS_OVERFLOW) + { + gold_error(_("small-data section too large;" + " lower small-data size limit (see option -G)")); + return This::STATUS_OVERFLOW; + } + return This::STATUS_OKAY; + } + // R_MIPS_GPREL32 static inline typename This::Status relgprel32(unsigned char* view, const Mips_relobj<size, big_endian>* object, @@ -11938,12 +11976,20 @@ Target_mips<size, big_endian>::Relocate::relocate( case elfcpp::R_MIPS_GPREL16: case elfcpp::R_MIPS16_GPREL: - case elfcpp::R_MICROMIPS_GPREL7_S2: case elfcpp::R_MICROMIPS_GPREL16: reloc_status = Reloc_funcs::relgprel(view, object, psymval, target->adjusted_gp_value(object), r_addend, extract_addend, - gsym == NULL, r_types[i], + gsym == NULL, + this->calculate_only_, + &this->calculated_value_); + break; + + case elfcpp::R_MICROMIPS_GPREL7_S2: + reloc_status = Reloc_funcs::relgprel7(view, object, psymval, + target->adjusted_gp_value(object), + r_addend, extract_addend, + gsym == NULL, this->calculate_only_, &this->calculated_value_); break; diff --git a/ld/testsuite/ld-mips-elf/reloc-4.d b/ld/testsuite/ld-mips-elf/reloc-4.d index 936a861c65c..3d0a37a2ead 100644 --- a/ld/testsuite/ld-mips-elf/reloc-4.d +++ b/ld/testsuite/ld-mips-elf/reloc-4.d @@ -1,3 +1,3 @@ #source: reloc-4.s #ld: -#error: small-data section exceeds 64KB.*truncated to fit: R_MIPS_LITERAL +#error: small-data section too large.*truncated to fit: R_MIPS_LITERAL diff --git a/ld/testsuite/ld-mips-elf/reloc-5.d b/ld/testsuite/ld-mips-elf/reloc-5.d index 2fc74ea27d5..7910b35fcaf 100644 --- a/ld/testsuite/ld-mips-elf/reloc-5.d +++ b/ld/testsuite/ld-mips-elf/reloc-5.d @@ -1,3 +1,3 @@ #source: reloc-5.s #ld: -#error: small-data section exceeds 64KB.*truncated to fit: R_MIPS_GPREL16 +#error: small-data section too large.*truncated to fit: R_MIPS_GPREL16
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 92dd4c20a7d..3a6a91359df 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -2231,7 +2231,8 @@ micromips_reloc_shuffle_p (unsigned int r_type) { return (micromips_reloc_p (r_type) && r_type != R_MICROMIPS_PC7_S1 - && r_type != R_MICROMIPS_PC10_S1); + && r_type != R_MICROMIPS_PC10_S1 + && r_type != R_MICROMIPS_GPREL7_S2); } static inline bool