From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 11FE13858D3C for ; Tue, 18 Jan 2022 00:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11FE13858D3C Received: by mail-pl1-x62f.google.com with SMTP id n11so20930035plf.4 for ; Mon, 17 Jan 2022 16:52:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=wQKvkGktWq7JLmAEgNa8ElW8aCJMIEskWlJRS/6Lg7w=; b=F/Jyb+ugX1ACj07wmNr7lQcCZHDR4JIEI0XNWHf3xBqVx0rkvdpY8NwDnJ2GuBxnEg hO5yyUnpWHm9foskOq1vs4DJE1D/hODEi07JShMeDwGD28R0MNc+uW45LsdT3FzKXnJ5 aA2JLpKMLbpgEKyRQuCJQdp/3F8BExeQG+fFMs9WwUmP5HNqnGXCZwPNNwjbBEajkBoA RFxjyNuTvyAiizxZLXoCtFXlcdxJGRxmoiHNgs3UbFyeU4aQpRZ26Pgv0OHqrFX79wI4 oU0Ygulv/VSmjTePSDnhYgVvPgRJubKozJI99XuFWZ1jJQl7DZnrYpTmsnkxpmry1gtt q4Dw== X-Gm-Message-State: AOAM531L2ssFhzheVmZ06Zd4Gi9WvhdgFTzkHKUxjLsWcUjTayzLAyOR 8WUJeGwG8XccK2dHxysVaHY5X7xAPiM= X-Google-Smtp-Source: ABdhPJwzyMhikpwwzHu1YOJrQf27LQx5kygDnd3nC0DgkgkrKnRNCx6vsGqmdWhpVwZaCzneK5IOkQ== X-Received: by 2002:a17:90b:1d81:: with SMTP id pf1mr37593696pjb.211.1642467153719; Mon, 17 Jan 2022 16:52:33 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:a575:5f9a:9623:ea11]) by smtp.gmail.com with ESMTPSA id i15sm804647pjz.0.2022.01.17.16.52.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jan 2022 16:52:32 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id F0FF5114031C; Tue, 18 Jan 2022 11:22:29 +1030 (ACDT) Date: Tue, 18 Jan 2022 11:22:29 +1030 From: Alan Modra To: binutils@sourceware.org Subject: tweak __ehdr_start visibility and flags for check_relocs Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3037.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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 00:52:38 -0000 bfd/ * elf-bfd.h (UNDEFWEAK_NO_DYNAMIC_RELOC): Test linker_def. ld/ * ldelf.c (ldelf_before_allocation): Don't force __ehdr_start local and hidden here.. * ldlang.c (lang_symbol_tweaks): ..do so here instead and set def_regular and linker_def for check_relocs. New function extracted from lang_process. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 4a85255a500..138ef46791b 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -291,9 +291,12 @@ weakdef (struct elf_link_hash_entry *h) _bfd_elf_symbol_refs_local_p (H, INFO, 1) /* Whether an undefined weak symbol should resolve to its link-time - value, even in PIC or PIE objects. */ + value, even in PIC or PIE objects. The linker_def test is to + handle symbols like __ehdr_start that may be undefweak in early + stages of linking but are guaranteed to be defined later. */ #define UNDEFWEAK_NO_DYNAMIC_RELOC(INFO, H) \ ((H)->root.type == bfd_link_hash_undefweak \ + && !(H)->root.linker_def \ && (ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT \ || (INFO)->dynamic_undefined_weak == 0)) diff --git a/ld/ldelf.c b/ld/ldelf.c index 799f7796017..121c25d948f 100644 --- a/ld/ldelf.c +++ b/ld/ldelf.c @@ -1607,11 +1607,6 @@ ldelf_before_allocation (char *audit, char *depaudit, || h->root.type == bfd_link_hash_undefweak || h->root.type == bfd_link_hash_common)) { - const struct elf_backend_data *bed; - bed = get_elf_backend_data (link_info.output_bfd); - (*bed->elf_backend_hide_symbol) (&link_info, h, true); - if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL) - h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; /* Don't leave the symbol undefined. Undefined hidden symbols typically won't have dynamic relocations, but we most likely will need dynamic relocations for diff --git a/ld/ldlang.c b/ld/ldlang.c index 48e40828634..499a9c7182c 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -6994,6 +6994,43 @@ lang_finalize_start_stop (void) foreach_start_stop (set_start_stop); } +static void +lang_symbol_tweaks (void) +{ + /* Give initial values for __start and __stop symbols, so that ELF + gc_sections will keep sections referenced by these symbols. Must + be done before lang_do_assignments. */ + if (config.build_constructors) + lang_init_start_stop (); + + /* Make __ehdr_start hidden, and set def_regular even though it is + likely undefined at this stage. For lang_check_relocs. */ + if (is_elf_hash_table (link_info.hash) + && !bfd_link_relocatable (&link_info)) + { + struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) + bfd_link_hash_lookup (link_info.hash, "__ehdr_start", + false, false, true); + + /* Only adjust the export class if the symbol was referenced + and not defined, otherwise leave it alone. */ + if (h != NULL + && (h->root.type == bfd_link_hash_new + || h->root.type == bfd_link_hash_undefined + || h->root.type == bfd_link_hash_undefweak + || h->root.type == bfd_link_hash_common)) + { + const struct elf_backend_data *bed; + bed = get_elf_backend_data (link_info.output_bfd); + (*bed->elf_backend_hide_symbol) (&link_info, h, true); + if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL) + h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; + h->def_regular = 1; + h->root.linker_def = 1; + } + } +} + static void lang_end (void) { @@ -8210,11 +8247,7 @@ lang_process (void) files. */ ldctor_build_sets (); - /* Give initial values for __start and __stop symbols, so that ELF - gc_sections will keep sections referenced by these symbols. Must - be done before lang_do_assignments below. */ - if (config.build_constructors) - lang_init_start_stop (); + lang_symbol_tweaks (); /* PR 13683: We must rerun the assignments prior to running garbage collection in order to make sure that all symbol aliases are resolved. */ -- Alan Modra Australia Development Lab, IBM