From patchwork Tue Dec 4 18:16:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 30536 Received: (qmail 122713 invoked by alias); 4 Dec 2018 18:16:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 122703 invoked by uid 89); 4 Dec 2018 18:16:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Dec 2018 18:16:53 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71C5988E48 for ; Tue, 4 Dec 2018 18:16:52 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC90C5D77E for ; Tue, 4 Dec 2018 18:16:51 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Fix gdb build on 32-bit hosts w/ --enable-64-bit-bfd Date: Tue, 4 Dec 2018 18:16:50 +0000 Message-Id: <20181204181650.18188-1-palves@redhat.com> MIME-Version: 1.0 Building for x86_64/-m32 with --enable-64-bit-bfd, compilation fails with: src/gdb/dwarf2read.c: In instantiation of ‘gdb::array_view get_gdb_index_contents_from_section(objfile*, T*) [with T = dwarf2_per_objfile]’: src/gdb/dwarf2read.c:6266:54: required from here src/gdb/dwarf2read.c:6192:37: error: narrowing conversion of ‘section->dwarf2_section_info::size’ from ‘bfd_size_type {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing] return {section->buffer, section->size}; ~~~~~~~~~^~~~ This fixes it. gdb/ChangeLog: 2018-12-04 Pedro Alves * dwarf2read.c (get_gdb_index_contents_from_section): Use gdb::make_array_view. --- gdb/dwarf2read.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 8bfbd693940..30bc101f11c 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -6189,7 +6189,13 @@ get_gdb_index_contents_from_section (objfile *obj, T *section_owner) dwarf2_read_section (obj, section); - return {section->buffer, section->size}; + /* dwarf2_section_info::size is a bfd_size_type, while + gdb::array_view works with size_t. On 32-bit hosts, with + --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t + is 32-bit. So we need an explicit narrowing conversion here. + This is fine, because it's impossible to allocate or mmap an + array/buffer larger than what size_t can represent. */ + return gdb::make_array_view (section->buffer, section->size); } /* Lookup the index cache for the contents of the index associated to