From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 5CBDE3858D28 for ; Sat, 5 Feb 2022 06:55:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5CBDE3858D28 Received: by mail-pf1-x42a.google.com with SMTP id v74so7021325pfc.1 for ; Fri, 04 Feb 2022 22:55:11 -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=Enq6vJ9D0pkfaQbDQj+17BnYS/MTtJOubA+NzbStBdg=; b=O7+b4Hju+AewK4QyonrLoBTotHrntZrvAdAPdvqfvQrLGOPChyrTTEP5s6MgUX2MgS JtDVuNsL3p3tYGSxda6+O46AoyKQXsT5X5DR+lt9dB2mGRlOTC9nzEqOiBdOlj3Bp11m 7wo4AWyhMK2Ln7vAx9MBuf3Adx7pnZoAu/Tu3So4q5EymLvaOiTr2dTOLiwsPUYxafiE 4nBhuEo62DjRp1yZioqJOmNFNSNouhbkWFjEw2EeMe+ghXg9Axm3UxzDzO8UUTG1gKj6 sM3WtF5/u4V3xaFpZcarwIqdyAp4wCS79Iz0IRYcVvyJ1+jfNqi6EiWDQ3QZ9bKHcfH5 9uOA== X-Gm-Message-State: AOAM530qZh6kB4ZGHYk/G3YMGgrKMT6C95lLd6oKO9QOQhVUpAl/osAa IwnTl4GZgd3MDSCa2tBvbxdO+0534SU= X-Google-Smtp-Source: ABdhPJwJmW9s6luXmQErvQriyVJI8G0VoImHdJIfUyw9JGWnaThu7JNoMEhCBjJCOZ7Xas/my9D1qQ== X-Received: by 2002:a05:6a00:852:: with SMTP id q18mr6717199pfk.74.1644044110097; Fri, 04 Feb 2022 22:55:10 -0800 (PST) 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 a37sm3091848pga.3.2022.02.04.22.55.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 22:55:09 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 833071140872; Sat, 5 Feb 2022 17:25:06 +1030 (ACDT) Date: Sat, 5 Feb 2022 17:25:06 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Detect .eh_frame_hdr earlier for SIZEOF_HEADERS Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3038.0 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.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: Sat, 05 Feb 2022 06:55:13 -0000 Current code detects the need for PT_GNU_EH_FRAME using a field set by _bfd_elf_discard_section_eh_frame_hdr, which is called fairly late in the linking process. Use the elf hash table eh_info instead, which is set up earlier by size_dynamic_sections. Found when delving into PR28827. * elf-bfd.h (struct output_elf_obj_tdata): Delete eh_frame_hdr. (elf_eh_frame_hdr): Don't define. (_bfd_elf_discard_section_eh_frame_hdr): Update prototype. * elf-eh-frame.c (_bfd_elf_discard_section_eh_frame_hdr): Delete abfd parameter. Don't set elf_eh_frame_hdr. * elf.c (elf_eh_frame_hdr): New function. (get_program_header_size): Adjust elf_eh_frame_hdr call. (_bfd_elf_map_sections_to_segments): Likewise. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 138ef46791b..1d3ae76339a 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1909,10 +1909,6 @@ struct output_elf_obj_tdata /* STT_SECTION symbols for each section */ asymbol **section_syms; - /* Used to determine if PT_GNU_EH_FRAME segment header should be - created. */ - asection *eh_frame_hdr; - /* NT_GNU_BUILD_ID note type info. */ struct { @@ -2116,7 +2112,6 @@ struct elf_obj_tdata #define elf_seg_map(bfd) (elf_tdata(bfd) -> o->seg_map) #define elf_link_info(bfd) (elf_tdata(bfd) -> o->link_info) #define elf_next_file_pos(bfd) (elf_tdata(bfd) -> o->next_file_pos) -#define elf_eh_frame_hdr(bfd) (elf_tdata(bfd) -> o->eh_frame_hdr) #define elf_stack_flags(bfd) (elf_tdata(bfd) -> o->stack_flags) #define elf_shstrtab(bfd) (elf_tdata(bfd) -> o->strtab_ptr) #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) @@ -2412,7 +2407,7 @@ extern bool _bfd_elf_discard_section_eh_frame extern bool _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *, void *); extern bool _bfd_elf_discard_section_eh_frame_hdr - (bfd *, struct bfd_link_info *); + (struct bfd_link_info *); extern bfd_vma _bfd_elf_eh_frame_section_offset (bfd *, struct bfd_link_info *, asection *, bfd_vma); extern bool _bfd_elf_write_section_eh_frame diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c index a621fedbee8..2e22d0c9215 100644 --- a/bfd/elf-eh-frame.c +++ b/bfd/elf-eh-frame.c @@ -1612,7 +1612,7 @@ _bfd_elf_discard_section_eh_frame input sections. It finalizes the size of .eh_frame_hdr section. */ bool -_bfd_elf_discard_section_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info) +_bfd_elf_discard_section_eh_frame_hdr (struct bfd_link_info *info) { struct elf_link_hash_table *htab; struct eh_frame_hdr_info *hdr_info; @@ -1644,7 +1644,6 @@ _bfd_elf_discard_section_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info) sec->size += 4 + hdr_info->u.dwarf.fde_count * 8; } - elf_eh_frame_hdr (abfd) = sec; return true; } diff --git a/bfd/elf.c b/bfd/elf.c index 14c2c7ba734..79f71aa81e2 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -4343,6 +4343,20 @@ _bfd_elf_compute_section_file_positions (bfd *abfd, return true; } +/* Retrieve .eh_frame_hdr. Prior to size_dynamic_sections the + function effectively returns whether --eh-frame-hdr is given on the + command line. After size_dynamic_sections the result reflects + whether .eh_frame_hdr will actually be output (sizing isn't done + until ldemul_after_allocation). */ + +static asection * +elf_eh_frame_hdr (const struct bfd_link_info *info) +{ + if (info != NULL && is_elf_hash_table (info->hash)) + return elf_hash_table (info)->eh_info.hdr_sec; + return NULL; +} + /* Make an initial estimate of the size of the program header. If we get the number wrong here, we'll redo section placement. */ @@ -4379,7 +4393,7 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info) ++segs; } - if (elf_eh_frame_hdr (abfd)) + if (elf_eh_frame_hdr (info)) { /* We need a PT_GNU_EH_FRAME segment. */ ++segs; @@ -5134,7 +5148,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME segment. */ - eh_frame_hdr = elf_eh_frame_hdr (abfd); + eh_frame_hdr = elf_eh_frame_hdr (info); if (eh_frame_hdr != NULL && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0) { diff --git a/bfd/elflink.c b/bfd/elflink.c index 2677561478d..6fa18d92007 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -14888,7 +14888,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info) if (info->eh_frame_hdr_type && !bfd_link_relocatable (info) - && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info)) + && _bfd_elf_discard_section_eh_frame_hdr (info)) changed = 1; return changed; -- Alan Modra Australia Development Lab, IBM