From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 496593858C5F for ; Thu, 18 May 2023 02:54:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 496593858C5F 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-x42b.google.com with SMTP id d2e1a72fcca58-64d1d68b4dbso113611b3a.3 for ; Wed, 17 May 2023 19:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684378471; x=1686970471; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=fCD1M93xnHQDiPyPnpe/Ofar/mtZQn8dYQzw8XKn2YE=; b=ll44zPnNH2iF9XHV6KxU1xIpxw7zRaap8OUXePugPYVqK4RDRAEJ1jE+vXh6MXAfOc 9TW2+0sgKRGY8MGLO3BuqiT6Cyg6OB4COWo7/JMOM5i8hK/3NTaUxk0JAxhWaWW8g32/ bf73ckFhHFk3AbxjWaz3KdzfAENmvC2WKF4WnoSegRCR6R/n6oAu5WDZ8ajRue1V0VzT Dh4GLgSZ07dEI4fzzBxD9hSDK6QkULrvxVcYsqwfYOYh60VrRMLYCL/HHVC0eizkecVd PxC9oUEWLD9mlmy+SdSzPOoovJqU89mhHoJGBCNafcJOfzOSMNkjHIOn7uJkd4DEkhY2 EppA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684378471; x=1686970471; 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=fCD1M93xnHQDiPyPnpe/Ofar/mtZQn8dYQzw8XKn2YE=; b=IXo9q6vR02GsOewauL5808lSHrrsjzqVPVbnq1heB4A/dYcpW1kdBv8BBEBCr4/kMs bVUxo5eZOcgwuEZCqALGz1gzNgOYcNxK5d6DeqaZSzEDjhjW541KLch2XokW9W1IVvAH sS22cjWK0zc51sSWYSaORs7XeLNC8qwP1igfT7lZ/zB6Rq3bkqVZaJcQKjCPWry0Qqo5 0Qsc/x4E7qjgsG4V4XsdIS7XBZ0jKvoPUN5v3orSbSMZwPmK0C/qGm1odNno8KXaaBMY 5YvxPWnwTNVwSg9KukkXkkaWqNbXNMfUaqdURXe9NDmp4uYqgprXR/TfNExA2fW06xI1 KaJg== X-Gm-Message-State: AC+VfDwKYNAh7f2FOyuOwtj/V0GlJxwrBK1KjWlK46/hxjG97p0+naDm 5xex582ImhWhJiSEfB2+T5PKsY2eBmo= X-Google-Smtp-Source: ACHHUZ5Z8QYr5GGSxyAw2IZg6oeovD5JA5q8+ZWa45Wbd/hiRzbE2qcuXDE4GUikgd+dSAMBS8HMGQ== X-Received: by 2002:a05:6a20:a58f:b0:100:b137:3563 with SMTP id bc15-20020a056a20a58f00b00100b1373563mr495013pzb.32.1684378470712; Wed, 17 May 2023 19:54:30 -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 j17-20020aa79291000000b005a8b28c644esm238186pfa.4.2023.05.17.19.54.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 19:54:30 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id CF8AC114158A; Thu, 18 May 2023 12:24:27 +0930 (ACST) Date: Thu, 18 May 2023 12:24:27 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Re: Add section caches to coff_data_type Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.8 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_FILL_THIS_FORM_FRAUD_PHISH,T_FILL_THIS_FORM_SHORT,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 0e759f232b6d regressed these tests: rs6000-aix7.2 +FAIL: Garbage collection test 1 (32-bit) rs6000-aix7.2 +FAIL: Garbage collection test 1 (64-bit) rs6000-aix7.2 +FAIL: Glink test 1 (32-bit) rs6000-aix7.2 +FAIL: Glink test 1 (64-bit) Investigation showed segfaults in coff_section_from_bfd_index called by xcoff_write_global_symbol due to the hash table pointer being NULL. Well, yes, the hash table isn't initialised for the output bfd. mkobject_hook is the wrong place to do that. * coffcode.h: Revert 0e759f232b6d changes. * peicode.h: Likewise. * coff-x86_64.c (htab_hash_section_index, htab_eq_section_index): Moved here from coffcode.h. (coff_amd64_rtype_to_howto): Create section_by_index htab. * coffgen.c (htab_hash_section_target_index), (htab_eq_section_target_index): Moved here from coffcode.h. (coff_section_from_bfd_index): Create section_by_target_index htab. Stash newly created sections in htab. diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c index 1f8c8d515c4..f5bd5a27c40 100644 --- a/bfd/coff-x86_64.c +++ b/bfd/coff-x86_64.c @@ -656,6 +656,20 @@ coff_pe_amd64_relocate_section (bfd *output_bfd, #define coff_relocate_section coff_pe_amd64_relocate_section +static hashval_t +htab_hash_section_index (const void * entry) +{ + const struct bfd_section * sec = entry; + return sec->index; +} + +static int +htab_eq_section_index (const void * e1, const void * e2) +{ + const struct bfd_section * sec1 = e1; + const struct bfd_section * sec2 = e2; + return sec1->index == sec2->index; +} #endif /* COFF_WITH_PE */ /* Convert an rtype to howto for the COFF backend linker. */ @@ -756,11 +770,17 @@ coff_amd64_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, htab_t table = coff_data (abfd)->section_by_index; asection *s; + if (!table) + { + table = htab_create (10, htab_hash_section_index, + htab_eq_section_index, NULL); + if (table == NULL) + return NULL; + coff_data (abfd)->section_by_index = table; + } + if (htab_elements (table) == 0) { - /* Sigh - if we do not have a section index then the only way - to get the section to offset against is to find it the hard - way. */ for (s = abfd->sections; s != NULL; s = s->next) { void ** slot = htab_find_slot (table, s, INSERT); diff --git a/bfd/coffcode.h b/bfd/coffcode.h index ab6f797b324..777515e82e1 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -731,36 +731,6 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags) #ifndef COFF_WITH_PE -static hashval_t -htab_hash_section_index (const void * entry) -{ - const struct bfd_section * sec = entry; - return sec->index; -} - -static int -htab_eq_section_index (const void * e1, const void * e2) -{ - const struct bfd_section * sec1 = e1; - const struct bfd_section * sec2 = e2; - return sec1->index == sec2->index; -} - -static hashval_t -htab_hash_section_target_index (const void * entry) -{ - const struct bfd_section * sec = entry; - return sec->target_index; -} - -static int -htab_eq_section_target_index (const void * e1, const void * e2) -{ - const struct bfd_section * sec1 = e1; - const struct bfd_section * sec2 = e2; - return sec1->target_index == sec2->target_index; -} - static bool styp_to_sec_flags (bfd *abfd, void * hdr, @@ -2185,11 +2155,6 @@ coff_mkobject_hook (bfd * abfd, abfd->flags |= HAS_DEBUG; #endif - coff->section_by_index - = htab_create (10, htab_hash_section_index, htab_eq_section_index, NULL); - coff->section_by_target_index = htab_create - (10, htab_hash_section_target_index, htab_eq_section_target_index, NULL); - return coff; } #endif diff --git a/bfd/coffgen.c b/bfd/coffgen.c index 03b64ac6762..d4c14fba1d9 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -356,6 +356,21 @@ coff_object_p (bfd *abfd) : (struct internal_aouthdr *) NULL)); } +static hashval_t +htab_hash_section_target_index (const void * entry) +{ + const struct bfd_section * sec = entry; + return sec->target_index; +} + +static int +htab_eq_section_target_index (const void * e1, const void * e2) +{ + const struct bfd_section * sec1 = e1; + const struct bfd_section * sec2 = e2; + return sec1->target_index == sec2->target_index; +} + /* Get the BFD section from a COFF symbol section number. */ asection * @@ -371,17 +386,23 @@ coff_section_from_bfd_index (bfd *abfd, int section_index) struct bfd_section *answer; htab_t table = coff_data (abfd)->section_by_target_index; - if (htab_elements (table) == 0) + if (!table) { - answer = abfd->sections; + table = htab_create (10, htab_hash_section_target_index, + htab_eq_section_target_index, NULL); + if (table == NULL) + return bfd_und_section_ptr; + coff_data (abfd)->section_by_target_index = table; + } - while (answer) + if (htab_elements (table) == 0) + { + for (answer = abfd->sections; answer; answer = answer->next) { void **slot = htab_find_slot (table, answer, INSERT); if (slot == NULL) return bfd_und_section_ptr; *slot = answer; - answer = answer->next; } } @@ -392,14 +413,16 @@ coff_section_from_bfd_index (bfd *abfd, int section_index) if (answer != NULL) return answer; - answer = abfd->sections; - - while (answer) - { - if (answer->target_index == section_index) + /* Cover the unlikely case of sections added after the first call to + this function. */ + for (answer = abfd->sections; answer; answer = answer->next) + if (answer->target_index == section_index) + { + void **slot = htab_find_slot (table, answer, INSERT); + if (slot != NULL) + *slot = answer; return answer; - answer = answer->next; - } + } /* We should not reach this point, but the SCO 3.2v4 /lib/libc_s.a has a bad symbol table in biglitpow.o. */ diff --git a/bfd/peicode.h b/bfd/peicode.h index 436ff54fbea..e2e2be65b5d 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -255,36 +255,6 @@ coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in) #endif } -static hashval_t -htab_hash_section_index (const void * entry) -{ - const struct bfd_section * sec = entry; - return sec->index; -} - -static int -htab_eq_section_index (const void * e1, const void * e2) -{ - const struct bfd_section * sec1 = e1; - const struct bfd_section * sec2 = e2; - return sec1->index == sec2->index; -} - -static hashval_t -htab_hash_section_target_index (const void * entry) -{ - const struct bfd_section * sec = entry; - return sec->target_index; -} - -static int -htab_eq_section_target_index (const void * e1, const void * e2) -{ - const struct bfd_section * sec1 = e1; - const struct bfd_section * sec2 = e2; - return sec1->target_index == sec2->target_index; -} - static bool pe_mkobject (bfd * abfd) { @@ -382,11 +352,6 @@ pe_mkobject_hook (bfd * abfd, memcpy (pe->dos_message, internal_f->pe.dos_message, sizeof (pe->dos_message)); - pe->coff.section_by_index - = htab_create (10, htab_hash_section_index, htab_eq_section_index, NULL); - pe->coff.section_by_target_index = htab_create - (10, htab_hash_section_target_index, htab_eq_section_target_index, NULL); - return (void *) pe; } -- Alan Modra Australia Development Lab, IBM