From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 9168C382D829 for ; Fri, 28 Apr 2023 06:16:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9168C382D829 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-63b46186c03so10828020b3a.3 for ; Thu, 27 Apr 2023 23:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682662560; x=1685254560; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=qL22ChQLCQfTzhnc++gD4iIYX7ML1zePdYXAcgzKssM=; b=ouB+22NZLnP+mMsPegrs4GEo/SuoG8ymPFMm7YoZ8Y/AVi0jSTYInsi8g5InFhZ93o DhXyxq/c5F0cSW+SkgbMESJ+pG1xdpMdCGclmysfQTq9uT/NBGQcySJtqKSxkGzXE08w bF7qP24vxnvf5xZ572TbA0gSnRCnDygA+Ox+V2wwN2jCLNLv6eWOhH6T4wC1hQbiTylm a7c9OREa3LZQMIxbOmfVlla2se6at1IWFhyWxkIxUFDu39I0X9CEqlmdgQ+PGKIS8zhs KVgJqlKJTmK8qC52Co0UPKs0hm3iWbtjiwinQLlqzHnWgLP3pZSdfC3MjXxx24/SvmsN I9+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682662560; x=1685254560; 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=qL22ChQLCQfTzhnc++gD4iIYX7ML1zePdYXAcgzKssM=; b=eKro/SZH5ksnPcm/K/OO9/YnxGn0wlJg9UkQ4jTQt0EwO2a5sfR8k1v1m5HPT+95dI 7U5rUwdQpubYSlOyEjEGLi8U6QKxw2CM53dGBWMU5Qm6+gvelUzuKPUVn8DP7lqTPzHB veyeHArGSu1emMc3++td3hpgFMsY449WDeVgRzv93VbQwc6LJxrl4dRXmelCcsibNc4F AqD7qz3Qjq81vt0A8Kut5npgtEUfY5MpFcFlgbxmCaN+5WYDq2i4XIUDZAKWRiFK3HGa /J3mun9A5nSOmlKiHEc4P3qvpfBPc1eAuKmI9cVe+Hlyb5EtycgojLvINbwE6y7Z2Lie q+WQ== X-Gm-Message-State: AC+VfDzmSPHhbRFC1JtVui9RcKiUYJFuZKPystf/JOZw9GKca4ld3Awp /NiNXdQdPYGJdIAZwQGk122UdoC2gVI= X-Google-Smtp-Source: ACHHUZ67EDGgTaSSaFlU/YaRiWml1RTNgUGFL29cLQ/nNN/a7Y0sM3d7nly46kqTIC8yjwbiJnbn4w== X-Received: by 2002:a05:6a00:15cf:b0:63d:4752:4db6 with SMTP id o15-20020a056a0015cf00b0063d47524db6mr6071342pfu.8.1682662559991; Thu, 27 Apr 2023 23:15:59 -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 a22-20020a056a000c9600b0062dd9a8c1b8sm14328649pfv.100.2023.04.27.23.15.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 23:15:59 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id F2A321142D60; Fri, 28 Apr 2023 15:45:56 +0930 (ACST) Date: Fri, 28 Apr 2023 15:45:56 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Re: Keeping track of rs6000-coff archive element pointers Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.9 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,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: Commit de7b90610e9e left a hole in the element checking, explained by the comment added to _bfd_xcoff_openr_next_archived_file. While fixing this, tidy some types used to hold unsigned values so that casts are not needed to avoid signed/unsigned comparison warnings. Also tidy a few things in xcoff.h. bfd/ * coff-rs6000.c (_bfd_xcoff_openr_next_archived_file): Check that we aren't pointing back at the last element. Make filestart a ufile_ptr. Update for xcoff_artdata change. (_bfd_strntol, _bfd_strntoll): Return unsigned values. (_bfd_xcoff_slurp_armap): Make off a ufile_ptr. (add_ranges): Update for xcoff_artdata change. * libbfd-in.h (struct artdata): Make first_file_filepos a ufile_ptr. * libbfd.h: Regenerate. include/ * coff/xcoff.h (struct xcoff_artdata): Replace min_elt with ar_hdr_size. (xcoff_big_format_p): In the !SMALL_ARCHIVE case return true for anything but a small archive. --- bfd/coff-rs6000.c | 35 ++++++++++++++++++++++++++--------- bfd/libbfd-in.h | 2 +- bfd/libbfd.h | 2 +- include/coff/xcoff.h | 10 +++++----- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 3b451912df7..421dc8f7ee5 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -1294,7 +1294,7 @@ _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, take a maximum length as an additional parameter. Also - just to save space, we omit the endptr return parameter, since we know that it is never used. */ -static long +static unsigned long _bfd_strntol (const char * nptr, int base, unsigned int maxlen) { char buf[24]; /* Should be enough. */ @@ -1306,7 +1306,7 @@ _bfd_strntol (const char * nptr, int base, unsigned int maxlen) return strtol (buf, NULL, base); } -static long long +static unsigned long long _bfd_strntoll (const char * nptr, int base, unsigned int maxlen) { char buf[32]; /* Should be enough. */ @@ -1338,7 +1338,7 @@ _bfd_strntoll (const char * nptr, int base, unsigned int maxlen) bool _bfd_xcoff_slurp_armap (bfd *abfd) { - file_ptr off; + ufile_ptr off; size_t namlen; bfd_size_type sz; bfd_byte *contents, *cend; @@ -1636,7 +1636,8 @@ add_range (bfd *abfd, ufile_ptr start, ufile_ptr end) /* Overlap with another element. */ goto err; - unsigned min_elt = x_artdata (abfd)->min_elt; + /* A zero size element with a one char name is this big. */ + unsigned min_elt = x_artdata (abfd)->ar_hdr_size + 2 + SXCOFFARFMAG; if (start - lo->end < min_elt) { /* Merge into an existing range. */ @@ -1757,7 +1758,7 @@ _bfd_xcoff_read_ar_hdr (bfd *abfd) bfd * _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file) { - file_ptr filestart; + ufile_ptr filestart; if (x_artdata (archive) == NULL) { @@ -1770,10 +1771,10 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file) if (last_file == NULL) { filestart = bfd_ardata (archive)->first_file_filepos; - if (x_artdata (archive)->min_elt == 0) + if (x_artdata (archive)->ar_hdr_size == 0) { x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR; - x_artdata (archive)->min_elt = SIZEOF_AR_HDR + SXCOFFARFMAG + 2; + x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR; } } else @@ -1794,10 +1795,10 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file) if (last_file == NULL) { filestart = bfd_ardata (archive)->first_file_filepos; - if (x_artdata (archive)->min_elt == 0) + if (x_artdata (archive)->ar_hdr_size == 0) { x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR_BIG; - x_artdata (archive)->min_elt = SIZEOF_AR_HDR_BIG + SXCOFFARFMAG + 2; + x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR_BIG; } } else @@ -1814,6 +1815,22 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file) } } + /* Check that we aren't pointing back at the last element. This is + necessary depite the add_range checking in _bfd_xcoff_read_ar_hdr + because archive.c leaves the last element open and thus in the + archive element cache until the next element is opened. */ + if (last_file != NULL) + { + ufile_ptr laststart = last_file->proxy_origin; + laststart -= x_artdata (archive)->ar_hdr_size; + laststart -= arch_eltdata (last_file)->extra_size; + if (filestart == laststart) + { + bfd_set_error (bfd_error_malformed_archive); + return NULL; + } + } + return _bfd_get_elt_at_filepos (archive, filestart, NULL); } diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 68b5343fd2e..4305b8416ea 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -72,7 +72,7 @@ extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN; struct artdata { - file_ptr first_file_filepos; + ufile_ptr first_file_filepos; /* Speed up searching the armap */ htab_t cache; carsym *symdefs; /* The symdef entries. */ diff --git a/bfd/libbfd.h b/bfd/libbfd.h index bb7f2f1efcf..aceec4ab9c0 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -78,7 +78,7 @@ extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN; struct artdata { - file_ptr first_file_filepos; + ufile_ptr first_file_filepos; /* Speed up searching the armap */ htab_t cache; carsym *symdefs; /* The symdef entries. */ diff --git a/include/coff/xcoff.h b/include/coff/xcoff.h index 08afc000bf0..7e86cc37d5c 100644 --- a/include/coff/xcoff.h +++ b/include/coff/xcoff.h @@ -653,7 +653,7 @@ struct xcoff_artdata } u; struct ar_ranges ranges; /* Anything less than this size can't hold an archive element. */ - unsigned int min_elt; + unsigned int ar_hdr_size; }; #define x_artdata(abfd) ((struct xcoff_artdata *) bfd_ardata (abfd)->tdata) @@ -663,13 +663,13 @@ struct xcoff_artdata #ifndef SMALL_ARCHIVE /* Creates big archives by default */ #define xcoff_big_format_p(abfd) \ - (bfd_ardata (abfd) != NULL \ - && (x_artdata (abfd) == NULL \ - || x_artdata (abfd)->u.hdr.magic[1] == 'b')) + (bfd_ardata (abfd) == NULL \ + || x_artdata (abfd) == NULL \ + || x_artdata (abfd)->u.hdr.magic[1] != 'a') #else /* Creates small archives by default. */ #define xcoff_big_format_p(abfd) \ - (bfd_ardata (abfd) != NULL \ + (bfd_ardata (abfd) != NULL \ && x_artdata (abfd) != NULL \ && x_artdata (abfd)->u.hdr.magic[1] == 'b') #endif -- Alan Modra Australia Development Lab, IBM