From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id C31483875DC4 for ; Thu, 27 Jun 2024 05:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C31483875DC4 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 C31483875DC4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719464784; cv=none; b=jPf8d3+LL+rqxDk9fuQftmVlND+DVAa/0BzRmdKHawfguPC374Y/B0lBpvamVjv33itKIkSo1sO3Yi/OfI6+UEE06vTFV0lopRRiYYr5jjMcIglrB6QsPFOQ6i0KTxR4B9TziOosyOpIeDbgFpZizhE21bf0v91Cqgqsd+8bZ0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719464784; c=relaxed/simple; bh=czfAh8V6M1UAWq6a42bYUq7E8kNgbBIqYs4IvgGWUAc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=MWtK5I9EC+bimZWvDjS2xAt+2n8EDcPLpEJDfK4DQCOCdxGYXnag+rrysHzhoRg5++TUN0BMoZVqTvz6QkBbK/m+GlftKd1op/CJy6rPJ7/oPzzMZ4hjb3sAf/7bYTsJoyUXqpfsx7SV9HSTIgTOAGClKwqAYdkN6anaXq7VvCc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-706642b4403so1006207b3a.1 for ; Wed, 26 Jun 2024 22:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719464781; x=1720069581; darn=sourceware.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=J7qrwhKpgyMnHRZMZEUbQfqq17Bgt4VFOxN1mUcMszc=; b=Ch6MoM670rsL3muIua8dWFfdHDh0uA28V5Dj7LepUtN23xo+GHOUPHA4i8ZLmiNypn WpH1wpZHQtRkGoSU9wDLFZROh+BST6KCHvIt3nvy4GgQJ+ALj7rXCKjTP6dy5SmdQxM7 k61uqrhniQP75lqLHEBB0fJ0iftSM5pJmOI7MNf69tdwqrGD1bO0iUkuMZJGfWxHWb+n vcNa5u7AJzlWacpQ2g0a5393+DjAkQ045XqifJ55IiH9KfpELioJpePfjT6/1X8Fk7Er rW0puELEv10mIVZMewPdlF28v+5q2vvIrhvIRzNmPNW/OYwn7g6Hx9AM9niHSF/U2xd1 EkUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719464781; x=1720069581; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=J7qrwhKpgyMnHRZMZEUbQfqq17Bgt4VFOxN1mUcMszc=; b=eVj+H6WKEUNuFxSPTacy/N2phmwGvMmFA+nrGejUZ2vEG+ogvAwtvwjLKql5solSE5 EQbhV2njbZ8FcV4TW1bebHtv7BBcd4oeZic+Xau6+n95ljLdgPzT52gDgAtJLYSiAKk2 f83T4EWussJvpAlBxSf5g5xYeiG+sfGwN5XMnfbB1lXvpbztQ34rmb3hDy69Ngq5/fpT sob+zT6/IKmuljW04ndk1ap9CsiYe1R7qdHXLAoxWZdjCeP2f/LS8KK8LdAvTcAg9Bl/ UjVS1CWszwr30O4Qnws5LjqYySXde4j6cfvZss9wFwTYfi38s0BJ3DmGLFMUaFS74+sm qimQ== X-Gm-Message-State: AOJu0YxTGL1bn5aEuY4+HFShDmOac8wYlIr58611TqtswnIF8yp+XJQY C2j0IVkRJlQPgMNghSt85JJndf5g26l3edJg6cTHRlvIGcbuqzDqbYayWQ== X-Google-Smtp-Source: AGHT+IFmQTNanTxUZcqwrpvb8CdUVzx/E4faowZAVZ41Xm0DIdyFDBhVfht9NGx/DZSSHYv20WQvHA== X-Received: by 2002:a05:6a21:339a:b0:1bd:199a:6347 with SMTP id adf61e73a8af0-1bd199a652bmr12348836637.5.1719464781015; Wed, 26 Jun 2024 22:06:21 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4d08:cebd:d73f:b794]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706b4a34ee5sm380762b3a.163.2024.06.26.22.06.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 22:06:20 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4A11A1140562; Thu, 27 Jun 2024 14:36:18 +0930 (ACST) Date: Thu, 27 Jun 2024 14:36:18 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Re: Rewrite SHT_GROUP handling Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3032.4 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 List-Id: There is no need to loop over the headers twice. Remove that leftover from the previous scheme. Also, the previous scheme silently ignored a section being mentioned in two or more SHT_GROUP sections. * elf.c (process_sht_group_entries): Prevent sections from belonging to two groups. (_bfd_elf_setup_sections): Process groups in a single loop over headers. diff --git a/bfd/elf.c b/bfd/elf.c index d7c42273aff..8bb296f9637 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -636,7 +636,9 @@ process_sht_group_entries (bfd *abfd, shdr = elf_elfsections (abfd)[idx]; if (idx >= elf_numsections (abfd) - || shdr->sh_type == SHT_GROUP) + || shdr->sh_type == SHT_GROUP + || (shdr->bfd_section != NULL + && elf_next_in_group (shdr->bfd_section) != NULL)) { _bfd_error_handler (_("%pB: invalid entry in SHT_GROUP section [%u]"), abfd, gidx); @@ -698,12 +700,10 @@ process_sht_group_entries (bfd *abfd, bool _bfd_elf_setup_sections (bfd *abfd) { - unsigned int i; bool result = true; - asection *s; /* Process SHF_LINK_ORDER. */ - for (s = abfd->sections; s != NULL; s = s->next) + for (asection *s = abfd->sections; s != NULL; s = s->next) { Elf_Internal_Shdr *this_hdr = &elf_section_data (s)->this_hdr; if ((this_hdr->sh_flags & SHF_LINK_ORDER) != 0) @@ -746,46 +746,27 @@ _bfd_elf_setup_sections (bfd *abfd) } /* Process section groups. */ - - /* First count the number of groups. If we have a SHT_GROUP - section with just a flag word (ie. sh_size is 4), ignore it. */ - unsigned int num_group = 0; - for (i = 1; i < elf_numsections (abfd); i++) + for (unsigned int i = 1; i < elf_numsections (abfd); i++) { Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i]; if (shdr && shdr->sh_type == SHT_GROUP) { - if (!is_valid_group_section_header (shdr, GRP_ENTRY_SIZE)) + if (is_valid_group_section_header (shdr, GRP_ENTRY_SIZE)) { - /* PR binutils/18758: Beware of corrupt binaries with invalid - group data. */ + if (shdr->sh_size >= 2 * GRP_ENTRY_SIZE + && !process_sht_group_entries (abfd, shdr, i)) + result = false; + } + else + { + /* PR binutils/18758: Beware of corrupt binaries with + invalid group data. */ _bfd_error_handler /* xgettext:c-format */ - (_("%pB: section group entry number %u is corrupt"), - abfd, i); + (_("%pB: section group entry number %u is corrupt"), abfd, i); result = false; - continue; } - if (shdr->sh_size >= 2 * GRP_ENTRY_SIZE) - ++num_group; - } - } - - if (num_group == 0) - return result; - - for (i = 1; i < elf_numsections (abfd); i++) - { - Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i]; - - if (shdr && shdr->sh_type == SHT_GROUP - && is_valid_group_section_header (shdr, 2 * GRP_ENTRY_SIZE)) - { - if (!process_sht_group_entries (abfd, shdr, i)) - result = false; - if (--num_group == 0) - break; } } -- Alan Modra