From patchwork Fri Jan 7 19:06:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 49724 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC1933858017 for ; Fri, 7 Jan 2022 19:09:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC1933858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641582578; bh=Shha5XO9Qq5yWLD6GKRmXLdQ7jhGbuheO+D1g8Sl3dM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ObiYEnEjZ7aM7NKVtifzN2X9hxnUH8CeB702FYJVlULwGP3eLH5WD6kngayuMIibq DnAHouq9mM0ywmIZ8ixQeYdXvVzkn57h4tQC2Xy/cfd2eS140hF+8JKwXu/DOT23kp asFVRVC4HQAbkqVWRAtBd1tOuJtYszU0jLlx/G9c= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 840943858408; Fri, 7 Jan 2022 19:06:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 840943858408 Received: by mail-pl1-x633.google.com with SMTP id h1so5536283pls.11; Fri, 07 Jan 2022 11:06:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Shha5XO9Qq5yWLD6GKRmXLdQ7jhGbuheO+D1g8Sl3dM=; b=7wZ4H4lTLU+LId0azYZNbJqa2eBMhKhzHKOvEFmfp32p11El12pXVE9XesKm3BZEOA u129eNOKTZwqReMEr9xLjIllCAHborn74APykwCQ008dgja0RKThqiNT8t7fSccNmgxf LXsyWr1y2GXg5xh0ZXonfASr5BySHcaK/TdIjFBi45o3+3HIxj0ofTJ3FnIeoxe9frvL yM8qFmLx9QEWs+t1MPNar6jwlkPX71Kq3xnBKlpiLXFinv7hx9xS/2vqfTxZMbyDVX19 JDBGTzpGkDWl+u+f0xM1VB052xr5v3v0kK2ICy5wKF/S98A0dFl6Pgm7rvQUqG+sFwUd c6lw== X-Gm-Message-State: AOAM5301KmDhb+1tZ5q7c595hTPBppU7swqd+xxJcPOdWCOwZjRegO/f WCQgzOfyAuP6gioDp5WjmfIgY7+ggYA= X-Google-Smtp-Source: ABdhPJx9Sclct/ETFW2ghD2fDgNS3bAVNEA3Scv2SVj8byfKqMtzTBoH7PfXtuB8w8iY2+qHwlaDLg== X-Received: by 2002:a17:90b:3607:: with SMTP id ml7mr17224102pjb.56.1641582393598; Fri, 07 Jan 2022 11:06:33 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id e5sm1031121pjr.25.2022.01.07.11.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 11:06:33 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 0BE54C0DB6; Fri, 7 Jan 2022 11:06:32 -0800 (PST) To: binutils@sourceware.org Subject: [PATCH 04/10] elf: Pass need_layout to _bfd_elf_map_sections_to_segments Date: Fri, 7 Jan 2022 11:06:25 -0800 Message-Id: <20220107190631.309790-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220107190631.309790-1-hjl.tools@gmail.com> References: <20220107190631.309790-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3028.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: libc-alpha@sourceware.org, Nick Clifton , Alan Modra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On some targets, the DT_RELR section size can be computed only after all symbols addresses can be determined. Update ldelf_map_segments to pass need_layout to _bfd_elf_map_sections_to_segments which will size DT_RELR section and set need_layout to true if the DT_RELR section size is changed. bfd/ * elf-bfd.h (_bfd_elf_map_sections_to_segments): Add a bool pointer argument. * elf.c (_bfd_elf_map_sections_to_segments): Add a bool pointer argument to indicate if section layout needs update. (assign_file_positions_for_load_sections): Pass NULL to _bfd_elf_map_sections_to_segments. * elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Pass NULL to _bfd_elf_map_sections_to_segments. ld/ * ldelfgen.c (ldelf_map_segments): Pass &need_layout to _bfd_elf_map_sections_to_segments. --- bfd/elf-bfd.h | 2 +- bfd/elf.c | 9 ++++++--- bfd/elflink.c | 3 ++- ld/ldelfgen.c | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 2441b3c0cd7..c4d2ef00d6b 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2718,7 +2718,7 @@ extern struct elf_segment_map * _bfd_elf_make_dynamic_segment (bfd *, asection *); extern bool _bfd_elf_map_sections_to_segments - (bfd *, struct bfd_link_info *); + (bfd *, struct bfd_link_info *, bool *); extern bool _bfd_elf_is_function_type (unsigned int); diff --git a/bfd/elf.c b/bfd/elf.c index ef0d18105ba..8b866b63e18 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -4609,10 +4609,13 @@ elf_modify_segment_map (bfd *abfd, #define IS_TBSS(s) \ ((s->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) == SEC_THREAD_LOCAL) -/* Set up a mapping from BFD sections to program segments. */ +/* Set up a mapping from BFD sections to program segments. Update + NEED_LAYOUT if the section layout is changed. */ bool -_bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) +_bfd_elf_map_sections_to_segments (bfd *abfd, + struct bfd_link_info *info, + bool *need_layout ATTRIBUTE_UNUSED) { unsigned int count; struct elf_segment_map *m; @@ -5416,7 +5419,7 @@ assign_file_positions_for_load_sections (bfd *abfd, unsigned int opb = bfd_octets_per_byte (abfd, NULL); if (link_info == NULL - && !_bfd_elf_map_sections_to_segments (abfd, link_info)) + && !_bfd_elf_map_sections_to_segments (abfd, link_info, NULL)) return false; alloc = 0; diff --git a/bfd/elflink.c b/bfd/elflink.c index 29ef9ddf8b9..bea413ec24e 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -3676,7 +3676,8 @@ _bfd_elf_strip_zero_sized_dynamic_sections (struct bfd_link_info *info) { /* Regenerate program headers. */ elf_seg_map (info->output_bfd) = NULL; - return _bfd_elf_map_sections_to_segments (info->output_bfd, info); + return _bfd_elf_map_sections_to_segments (info->output_bfd, info, + NULL); } return true; diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c index 5c033bbfbe0..58b37c65bc9 100644 --- a/ld/ldelfgen.c +++ b/ld/ldelfgen.c @@ -304,7 +304,8 @@ ldelf_map_segments (bool need_layout) if (lang_phdr_list == NULL) elf_seg_map (link_info.output_bfd) = NULL; if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd, - &link_info)) + &link_info, + &need_layout)) einfo (_("%F%P: map sections to segments failed: %E\n")); if (phdr_size != elf_program_header_size (link_info.output_bfd))