From patchwork Tue Apr 2 08:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 87917 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68331385842A for ; Tue, 2 Apr 2024 08:55:57 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 6119F3858431 for ; Tue, 2 Apr 2024 08:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6119F3858431 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 6119F3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712048124; cv=none; b=i8rXdRWd62ccew/7mIYmV6SRwR4QIaUcJESU/+B0DqyG59kr+no24Oqwgs81cvO2Qi2/e7qduOA6402qLTY02sDXoDJEbcjFMqMUEaFdNpjgY5kjVpHtFn3E5JHEugzOh97RI5CJ3wKGDPjk4OCpJfNFQF5U6e/L3g7kRWG4qCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712048124; c=relaxed/simple; bh=GhXwbMkUFQmTde2BSxxxdG7kDchA7XXzwuyAnn3reKQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KUmHT8FS3wtsIApsAp1Q8kUFoGnSo/e4esg+b6n1lC3M5sOxgAM+yJ7zDFMqXI1luKlrLoPx80ud/bWdv5ITHbBMfvSlzPoC6FwD2Q20EhqeNk4ep5VGIf4jJfY+8juJlfnYDPFjNC6/JMorrDHev3KC1l0kBaJCcgwSX1L90GI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-29ddfd859eeso4042796a91.1 for ; Tue, 02 Apr 2024 01:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712048121; x=1712652921; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=9kiEjsVJQKfgWldRHXTsO3Ds85b5zrLNUxO/2wFzQi4=; b=e2hz+dWzvOcdiymDv6I4Su5Werl4DQXOtsNXPkYw56xLsHSc5YRYTZyho3FD60tY3W RzMy3HmbrgHxZFum+6IaF5ECkP68Ya9JFO0334nESuPSEYpEdCSB6P5Oh9EqEzbzlteq 3uJWdCsahCWXj6+3NnGtHy+pceCmxu8ECUUFNP+ywv+44VcwZaXlTXoX9qczdUnSJyhK VNTJ1JSp0SQts7G2hzMERPAVThvMI9txvaAXeJ9Sah0y4YA+0AwUxgImZp5/5so7dpcU bpdlKBv17vtnJURT+sclvG2YDg6uKSW3xPO7Hr3xxzmS/rAVZ9Gzuoz9kb2RzTK3xR7Q +wQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712048121; x=1712652921; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9kiEjsVJQKfgWldRHXTsO3Ds85b5zrLNUxO/2wFzQi4=; b=ErDbsRwwYURar3LsVTIo/XCNJr36dEOrxkQCbuICoiQr/lKOd2LKuxj+7ikBlEu/e9 p8N/pHUqpXGSHFYdWvkEpfUaDsODFIw6MYwK+77yXajb5wfkY3yd3r9vkFTE1grVaSCo Wg5dQjjL8sjf/giI6DJJOpB01m3bDN51pkXN9I+97AFpx2gOT8KVoB1EdG+ZAfnm0Rzk 6PBqs2HmH0zs2xVPPDXtM4Xqi4s/tJnvC0OW8V7nibGuso+QNDmX/tnjwOtRkTk3a+l1 suol4zz66XTBdynPfqKhs2frlr6iVlwBrqQykG48UATJ7Sz3fgDMlpm8dTLwfLsTLCdX aWJw== X-Gm-Message-State: AOJu0YwZQKxAn82dySy16lZ/90lADnL/6i/97GFsSH0ocI+YrKcXilS3 QzSnRMmNsYyN3tDjNZqcTHpuqzzgdU0Z+ZbzU2EQh7R4TUsIBqx67LFnRc4q X-Google-Smtp-Source: AGHT+IGaRPMcQHoxLsv94+tNa0wfTm89XS86LX8L6VV2LYAyUJCf8psDuLZzdMVrXmr6Nd+jlNH42w== X-Received: by 2002:a17:90a:c593:b0:29f:dbdc:57df with SMTP id l19-20020a17090ac59300b0029fdbdc57dfmr9776323pjt.28.1712048121106; Tue, 02 Apr 2024 01:55:21 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:24d1:6044:8942:7204]) by smtp.gmail.com with ESMTPSA id a4-20020a655c84000000b005e838b99c96sm8068612pgt.80.2024.04.02.01.55.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 01:55:20 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 6E3B01140318; Tue, 2 Apr 2024 19:25:18 +1030 (ACDT) Date: Tue, 2 Apr 2024 19:25:18 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org This is HJ's patch fixing a mips bug, tidied a little. PR 31458 bfd/ * elf-bfd.h (_bfd_elf_link_read_relocs), (_bfd_elf_link_info_read_relocs): Constify section. * elflink.c: Likewise. * elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read relocs again in case --no-keep-memory. ld/ * testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory version of eh-frame3 test. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 7ad171d5000..29283f24895 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2592,9 +2592,9 @@ extern char *_bfd_elfcore_strndup (bfd *, char *, size_t); extern Elf_Internal_Rela *_bfd_elf_link_read_relocs - (bfd *, asection *, void *, Elf_Internal_Rela *, bool); + (bfd *, const asection *, void *, Elf_Internal_Rela *, bool); extern Elf_Internal_Rela *_bfd_elf_link_info_read_relocs - (bfd *, struct bfd_link_info *, asection *, void *, Elf_Internal_Rela *, + (bfd *, struct bfd_link_info *, const asection *, void *, Elf_Internal_Rela *, bool); extern bool _bfd_elf_link_output_relocs diff --git a/bfd/elflink.c b/bfd/elflink.c index 37a61b7cd31..e9cef470333 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2649,7 +2649,7 @@ _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data) static bool elf_link_read_relocs_from_section (bfd *abfd, - asection *sec, + const asection *sec, Elf_Internal_Shdr *shdr, void *external_relocs, Elf_Internal_Rela *internal_relocs) @@ -2746,7 +2746,7 @@ elf_link_read_relocs_from_section (bfd *abfd, Elf_Internal_Rela * _bfd_elf_link_info_read_relocs (bfd *abfd, struct bfd_link_info *info, - asection *o, + const asection *o, void *external_relocs, Elf_Internal_Rela *internal_relocs, bool keep_memory) @@ -2843,7 +2843,7 @@ _bfd_elf_link_info_read_relocs (bfd *abfd, Elf_Internal_Rela * _bfd_elf_link_read_relocs (bfd *abfd, - asection *o, + const asection *o, void *external_relocs, Elf_Internal_Rela *internal_relocs, bool keep_memory) diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index f2a1441fdf7..59444b063a4 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -7298,11 +7298,23 @@ _bfd_mips_elf_eh_frame_address_size (bfd *abfd, const asection *sec) if (long64_p) return 8; - if (sec->reloc_count > 0 - && elf_section_data (sec)->relocs != NULL - && (ELF32_R_TYPE (elf_section_data (sec)->relocs[0].r_info) - == R_MIPS_64)) - return 8; + if (sec->reloc_count > 0) + { + /* Load the relocations for this section. */ + Elf_Internal_Rela *internal_relocs = + _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, true); + if (internal_relocs == NULL) + return 0; + + unsigned int size = 0; + if (ELF32_R_TYPE (internal_relocs[0].r_info) == R_MIPS_64) + size = 8; + + if (elf_section_data (sec)->relocs != internal_relocs) + free (internal_relocs); + + return size; + } return 0; } diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index 50af78d1430..818238d0d58 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -771,6 +771,7 @@ if {$linux_gnu} { run_dump_test_n64 "eh-frame2-n64" } run_dump_test_eabi "eh-frame3" +run_dump_test_eabi "eh-frame3" {{ld --no-keep-memory} {name --no-keep-memory}} run_dump_test_eabi "eh-frame4" if {$linux_gnu} { set eh_frame5_test {