From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 816713858D20 for ; Wed, 15 May 2024 16:15:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 816713858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 816713858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715789704; cv=none; b=aEIsT1eHCLseBNVthqDq+JhaASZwCm5ak2EBEL+t5TGOzt8m9jgI4bpVPvROUlUuTXP+/WXoZ0u1fRUVm1mNf1bcAuP2SF+xxRgE2pCWSVs+X+NMMYKPCok/sVcieG6clZB2NF3qBKoFm6gPhKDHVcl0O/bu8epCm2mc9ZFNGMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715789704; c=relaxed/simple; bh=447Kte2ulJ6U8xXCmhDAcyBfZR2Nw/A4lGUpXWKdVFo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hbe/RLPJyY0xJuW4avsoDyC+8X2MwyAweciYBSkzxT7BUBNrjkmIx9XLSwObsk1k6F/UGdO/ktDZJyghx9PeaAA1nRqZxmsHQk6HSJzuO+pJx8X6dI9d+Q3VkGTTXTLOgKXKIg9vPgxqpboH/t11zB1Qq0+xLIggViEqwvvpPxo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715789701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=bL0wrilxDxG8NDtInVaHBxc+Vl+EX9f/nRV5uHzhTg4=; b=Tp/t9LzhiZ8I8Jo1WUUT8Hb79V5s6uBaz2UbtpQIZ6dIENDA3Li1ZXl2DmHcM3kWvVbBxN tYavsyD7OGNwRjO62Ky42Z6ZN9YHNr89MJukC6wcUwae4fnx3fE2UytQz/Ns4WPNuc0ce3 gWGRp3DFDCDQJQBIs0HJNzoMEPxMuVQ= Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-9tF70iLyNESMHrHoOMfhzQ-1; Wed, 15 May 2024 12:14:59 -0400 X-MC-Unique: 9tF70iLyNESMHrHoOMfhzQ-1 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-6f10d71ed9eso3205483a34.2 for ; Wed, 15 May 2024 09:14:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715789698; x=1716394498; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bL0wrilxDxG8NDtInVaHBxc+Vl+EX9f/nRV5uHzhTg4=; b=Ox3cn4KbIpi8f7Qnn48bNjO+oqu1KHa84ONHdewnv5Rvnym+bIYT7MHugkIOiFfoid pMbITlxxwKjH7cG7LYpFtap7tw2d32XzGHazv/p1p+Rk0dH4HTih/Sxyt4pxN8ZtmIAo /qcyWtdv7diQrU51Kb3tar5Tc8ayTKtxX5+VQqCwfPGyXmY7to2Xk7w7aL6Vf+OwS/CR /2OWAdE4wF4IwTI12dtdH+Bl6eE7ag95CegLBIIittBLtqVvg1YxTRxdsknLYsIC3eJM ntIeaje9iiAgZIoe7ooFJo4y6kM2eqWm+FRrZCDmUerl1JlhEk6d9IivTJ3BqvE3BUM+ zggg== X-Gm-Message-State: AOJu0YwPf8Y9Tvqsw8odR+vY1wtcWnKRO6BoPMVUFxuiEDBswoaK9w/i Tl38ZPdFuoThr0TLZJpRXQ0F6LBVaBvLmo21CZ880i+z1HGmv05KdPavfi1ZgKGhTZX3PwiDzAa hYCo++UUwcioxBAO8nsJ2Pxx0hg9QCoI4r/owPD+QfhXUyDnSVRGsvCkmUdzoIPq0iLB5g2981l Y5ekLA8BfR/h4PUBAy9S7qXT6z1X1/OlOyFa8qCw== X-Received: by 2002:a05:6359:a399:b0:186:3c3:b40f with SMTP id e5c5f4694b2df-193bcfe22e0mr1948166255d.20.1715789698039; Wed, 15 May 2024 09:14:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYphpdczpDZxP//lRliFpTwlPPQcsqt4FXqKl4wdkfPngQgno7DyAsi+EQpcxFd1h1AKoZNQ== X-Received: by 2002:a05:6359:a399:b0:186:3c3:b40f with SMTP id e5c5f4694b2df-193bcfe22e0mr1948159655d.20.1715789697043; Wed, 15 May 2024 09:14:57 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a340d25a18sm26109126d6.40.2024.05.15.09.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 09:14:56 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id D4980C1B742C; Wed, 15 May 2024 18:14:54 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] {btf,dwarf,ctf,abixml}-reader: Fix size of subrange type Organization: Red Hat / France X-Operating-System: AlmaLinux 9.3 X-URL: http://www.redhat.com Date: Wed, 15 May 2024 18:14:54 +0200 Message-ID: <87wmnv59xd.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP 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: Hello, While looking at something else, it appeared that the process of setting the size of the array_type_def::subrange_type is wrong for all front-ends. For this patch, I went back to read the DWARF 5 specification at "5.13/ Subrange Type Entries". Basically, the size of the subrange type as described by the DW_TAG_subrange_type DIE is set either: * by the size of the base type designated by the DW_AT_type attribute. * or by the DW_AT_byte_size or DW_AT_bit_size attribute that might be present on the DIE. That is different from the length property carried by the subrange type. The patch updates the four front-rends (DWARF, BTF, CTF and ABIXML) to fix the setting process of the size of the subrange type and adjusts the testsuite accordingly. * src/abg-btf-reader.cc (reader::build_array_type): The size of the subrange is not defined specifically. Let's set it to the default address size of the translation unit. * src/abg-ctf-reader.cc (build_array_ctf_range): If no basis type was found, then set the size of the subrange type to the default address size of the translation unit. * src/abg-dwarf-reader.cc (build_subrange_type): Consider the DW_AT_byte_size and DW_AT_bit_size attribute of DW_TAG_subrange_type if present. Otherwise, if the basis type is present, its size as the size of the subrange type. Otherwise, use the default address size of the translation unit as the size of the subrange type. * src/abg-ir.cc (array_type_def::subrange_type::subrange_type): If the underlying (basis) type is present, then use its size as the size of the subrange type. Otherwise the size is zero. (array_type_def::subrange_type::set_underlying_type): Update the size of the subrange when setting a new underlying (basis) type. * src/abg-reader.cc (build_subrange_type): Read and set the size of the subrange. * tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt: Adjust. * tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt: Likewise. * tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt: Likewise. * tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt: Likewise. * tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt: Likewise. Signed-off-by: Dodji Seketeli Applied to the master branch. --- src/abg-btf-reader.cc | 1 + src/abg-ctf-reader.cc | 3 ++ src/abg-dwarf-reader.cc | 28 +++++++++++++++++-- src/abg-ir.cc | 11 ++++---- src/abg-reader.cc | 17 +++++++++++ .../test1-ada-subrange-report-1.txt | 2 +- .../test1-ada-subrange-report-2.txt | 2 +- .../test2-ada-subrange-redundant-report-1.txt | 2 +- .../test2-ada-subrange-redundant-report-2.txt | 2 +- ...x86_64--2.24.2-30.fc30.x86_64-report-0.txt | 8 +++--- 10 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc index 67206bb4..1cf92dfb 100644 --- a/src/abg-btf-reader.cc +++ b/src/abg-btf-reader.cc @@ -798,6 +798,7 @@ public: lower_bound, upper_bound, location())); subrange->is_non_finite(!arr->nelems); + subrange->set_size_in_bits(cur_tu()->get_address_size()); add_decl_to_scope(subrange, cur_tu()->get_global_scope()); canonicalize(subrange); array_type_def::subranges_type subranges = {subrange}; diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index f381021c..f4fb91ed 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -1263,6 +1263,9 @@ build_array_ctf_range(reader *rdr, ctf_dict_t *dic, index_type, location(), translation_unit::LANG_C)); + if (!index_type) + subrange->set_size_in_bits(rdr->cur_transl_unit()->get_address_size()); + if (!subrange) return nullptr; diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 43e5c85d..3e021a06 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14705,6 +14705,18 @@ build_subrange_type(reader& rdr, is_signed = (ate == DW_ATE_signed || ate == DW_ATE_signed_char); } + // The DW_TAG_subrange_type DIE may have some size related + // attributes (DW_AT_byte_size or DW_AT_bit_size). If not, then the + // size is deduced from the size of its underlying type. + bool has_size_info = false; + uint64_t size = 0; + if ((has_size_info = die_unsigned_constant_attribute(die, + DW_AT_byte_size, size))) + size *= 8; + else + has_size_info = die_unsigned_constant_attribute(die, + DW_AT_bit_size, size); + translation_unit::language language = rdr.cur_transl_unit()->get_language(); array_type_def::subrange_type::bound_value lower_bound = get_default_array_lower_bound(language); @@ -14780,13 +14792,23 @@ build_subrange_type(reader& rdr, name, lower_bound, upper_bound, + underlying_type, location())); result->is_non_finite(is_non_finite); - if (underlying_type) - result->set_underlying_type(underlying_type); + if (has_size_info) + result->set_size_in_bits(size); + else + { + // The DW_TAG_subrange_type doesn't appear to have any size + // attribute. In that case, the size is deduced from the size + // of the underlying type. If there is no underlying type + // specified, then the size of the subrange type is the size + if (!underlying_type) + result->set_size_in_bits(rdr.cur_transl_unit()->get_address_size()); + } - // Let's ensure the resulting subrange looks metabolically healhty. + // Let's ensure the resulting subrange looks metabolically healthy. ABG_ASSERT(result->is_non_finite() || (result->get_length() == (uint64_t) (result->get_upper_bound() diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 6228f0f4..63527baf 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -18608,8 +18608,9 @@ array_type_def::subrange_type::subrange_type(const environment& env, translation_unit::language l) : type_or_decl_base(env, SUBRANGE_TYPE | ABSTRACT_TYPE_BASE | ABSTRACT_DECL_BASE), type_base(env, - upper_bound.get_unsigned_value() - - lower_bound.get_unsigned_value(), + utype + ? utype->get_size_in_bits() + : 0, 0), decl_base(env, name, loc, ""), priv_(new priv(lower_bound, upper_bound, utype, l)) @@ -18638,9 +18639,7 @@ array_type_def::subrange_type::subrange_type(const environment& env, const location& loc, translation_unit::language l) : type_or_decl_base(env, SUBRANGE_TYPE | ABSTRACT_TYPE_BASE | ABSTRACT_DECL_BASE), - type_base(env, - upper_bound.get_unsigned_value() - - lower_bound.get_unsigned_value(), 0), + type_base(env, /*size-in-bits=*/0, /*alignment=*/0), decl_base(env, name, loc, ""), priv_(new priv(lower_bound, upper_bound, l)) { @@ -18689,6 +18688,8 @@ array_type_def::subrange_type::set_underlying_type(const type_base_sptr &u) { ABG_ASSERT(priv_->underlying_type_.expired()); priv_->underlying_type_ = u; + if (u) + set_size_in_bits(u->get_size_in_bits()); } /// Getter of the upper bound of the subrange type. diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 29e593c2..ee578639 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -4609,6 +4609,21 @@ build_subrange_type(reader& rdr, length = strtoull(CHAR_STR(s), NULL, 0); } + uint64_t size_in_bits = 0; + if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "size-in-bits")) + { + char *endptr = nullptr; + size_in_bits = strtoull(CHAR_STR(s), &endptr, 0); + if (*endptr != '\0') + { + if (!strcmp(CHAR_STR(s), "infinite") + ||!strcmp(CHAR_STR(s), "unknown")) + size_in_bits = (size_t) -1; + else + return nil; + } + } + int64_t lower_bound = 0, upper_bound = 0; bool bounds_present = false; if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "lower-bound")) @@ -4662,6 +4677,8 @@ build_subrange_type(reader& rdr, underlying_type, loc)); maybe_set_artificial_location(rdr, node, p); p->is_non_finite(is_non_finite); + if (size_in_bits) + p->set_size_in_bits(size_in_bits); if (rdr.push_and_key_type_decl(p, node, add_to_current_scope)) rdr.map_xml_node_to_decl(node, p); diff --git a/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt b/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt index 69f3eb5f..8b2bc4c5 100644 --- a/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt +++ b/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt @@ -6,7 +6,7 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable [C] 'function test1__my_int[6] test1__first_function(void)' at test1.adb:6:1 has some indirect sub-type changes: return type changed: type name changed from 'test1__my_int[6]' to 'test1__my_int[7]' - array type size changed from 6000 to 7000 + array type size changed from 96 to 112 array type subrange 1 changed length from 6 to 7 [C] 'function test1__my_index test1__second_function(void)' at test1.adb:14:1 has some indirect sub-type changes: diff --git a/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt b/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt index 7c299ea9..29c30481 100644 --- a/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt +++ b/tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt @@ -8,7 +8,7 @@ Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable [C] 'function test1__my_int[6] test1__first_function(void)' at test1.adb:6:1 has some sub-type changes: return type changed: type name changed from 'test1__my_int[6]' to 'test1__my_int[7]' - array type size changed from 6000 to 7000 + array type size changed from 96 to 112 array type subrange 1 changed length from 6 to 7 [C] 'function test1__my_index test1__second_function(void)' at test1.adb:14:1 has some sub-type changes: diff --git a/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt b/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt index 742dda83..2fd51473 100644 --- a/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt +++ b/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt @@ -6,7 +6,7 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable [C] 'function test__my_int[101] test__first_function(test__my_int[101]&)' at test.adb:6:1 has some indirect sub-type changes: return type changed: type name changed from 'test__my_int[101]' to 'test__my_int[201]' - array type size changed from 101000 to 201000 + array type size changed from 1616 to 3216 array type subrange 1 changed length from 101 to 201 [C] 'function test__my_index test__second_function(const test__my_index)' at test.adb:12:1 has some indirect sub-type changes: diff --git a/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt b/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt index 45e1c527..f9d75049 100644 --- a/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt +++ b/tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt @@ -8,7 +8,7 @@ Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable [C] 'function test__my_int[101] test__first_function(test__my_int[101]&)' at test.adb:6:1 has some sub-type changes: return type changed: type name changed from 'test__my_int[101]' to 'test__my_int[201]' - array type size changed from 101000 to 201000 + array type size changed from 1616 to 3216 array type subrange 1 changed length from 101 to 201 [C] 'function test__my_index test__second_function(const test__my_index)' at test.adb:12:1 has some sub-type changes: diff --git a/tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt b/tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt index 868e6ed1..bc705318 100644 --- a/tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt +++ b/tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt @@ -17,10 +17,10 @@ 2 data member changes: type of 'integer LB0' changed: entity changed from 'integer' to '[2147483648]' - type size changed from 32 to 2147483647 (in bits) + type size hasn't changed type of 'integer UB0' changed: entity changed from 'integer' to '[2147483648]' - type size changed from 32 to 2147483647 (in bits) + type size hasn't changed [C] 'function gtk__glarea__gtk_glarea gtk__glarea__gtk_new(gtk__glarea__gtk_glarea, const gtk__glarea__attributes_array___XUP)' at gtk-glarea.adb:63:1 has some indirect sub-type changes: parameter 2 of type 'const gtk__glarea__attributes_array___XUP' has sub-type changes: @@ -33,10 +33,10 @@ 2 data member changes: type of 'integer LB0' changed: entity changed from 'integer' to '[2147483648]' - type size changed from 32 to 2147483647 (in bits) + type size hasn't changed type of 'integer UB0' changed: entity changed from 'integer' to '[2147483648]' - type size changed from 32 to 2147483647 (in bits) + type size hasn't changed 6 Removed variable symbols not referenced by debug info: -- 2.43.0 -- Dodji