From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by sourceware.org (Postfix) with ESMTPS id 3BBD63857835 for ; Sun, 1 Jan 2023 17:32:28 +0000 (GMT) Received: (Authenticated sender: dodji@seketeli.org) by mail.gandi.net (Postfix) with ESMTPSA id F3538240002 for ; Sun, 1 Jan 2023 17:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seketeli.org; s=gm1; t=1672594347; 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=u5fUGAHx9kw2SW+PnLQ0OuoD2REf//EMzTLMvmzl1L4=; b=Q2ylBYpodi1/VAsmsYZ4ZZryReefS1WnZ24Bu0sdM8mx6qEd7B/MBtz2+6VmC89jOwaK93 6TRAw1H4eDQ6M0Tpz4QkgjuiLkhtCCLH39myLsaPAcAQxqGVT8TcPAFRKzNQJlM9eCRk9y /MXcFwqB2HvXMDzWhTz2Y70bXTFPuvT8atmyWh/BDnwuhSbF+QP3KMXLGAno1KjJAx8bAx DvCxvTnZUlvRZCWchtS5qRmtD7pFI585Jj6DWYKDgMs1soNSUm3txwRgVNICxX/IK22lrp +IF42l57VS1Yk4zdCPfbwJBzU3RsOdC4grEjh2FD7NjI+47E0IBEpspLEhuOKQ== Received: by localhost (Postfix, from userid 1000) id E3092581C59; Sun, 1 Jan 2023 18:32:25 +0100 (CET) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] dwarf-reader: Bug 29811 - Support updating of variable type Organization: Me, myself and I X-Operating-System: Fedora 38 X-URL: http://www.seketeli.net/~dodji Date: Sun, 01 Jan 2023 18:32:25 +0100 Message-ID: <87mt72ma8m.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,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, Let's look at the source code reported at https://sourceware.org/bugzilla/show_bug.cgi?id=29811: extern unsigned int is_basic_table[]; unsigned int is_basic_table[] = {0}; Let's look at the DWARF output from GCC. The variable is_basic_table is described by the DIE at offset 0x51: [ 51] variable abbrev: 7 specification (ref4) [ 2f] decl_line (data1) 3 decl_column (data1) 14 type (ref4) [ 3b] location (exprloc) [ 0] addr .bss+0 The type of the variable is defined at the offset 0x3b: [ 3b] array_type abbrev: 1 type (ref4) [ 29] sibling (ref4) [ 4b] [ 44] subrange_type abbrev: 6 type (ref4) [ 4b] upper_bound (data1) 0 But then, we see that the DIE at 0x51 has a DW_AT_specification attribute that refers to the DIE at offset 0x2f: [ 2f] variable abbrev: 5 name (strp) "is_basic_table" decl_file (data1) test-v2.c (1) decl_line (data1) 1 decl_column (data1) 21 type (ref4) [ 1e] external (flag_present) yes declaration (flag_present) yes That DIE at offset 0x2f represents the first external variable declared in the source code. It's type is an array defined at offset 0x1e: [ 1e] array_type abbrev: 1 type (ref4) [ 29] sibling (ref4) [ 29] [ 27] subrange_type abbrev: 4 This array has one dimension of 'unknown' size; this is because the dimension is described by the DIE at offset 0x27 of kind DW_TAG_subrange_type and has no DW_AT_upper_bound DIE. But then, I said earlier, the real type of the is_basic_table variable is the DIE at offset 0x3b, which is an array which single dimension described by the DIE at offset 0x44 of kind DW_TAG_subrange_type with a DW_AT_upper_bound attribute of value 0. Let's see the output of abidw on this program, from the DWARF debug info: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The variable is_basic_table is described by the element at line 14: 14 Its type has the ID 'type-id-5' which is defined at line 10: 10 11 12 Which has an unknown size. But the, at line 7, there is another array type defined with a size of 32 bits: 7 8 9 So, libabigail links the is_basic_table variable to the wrong array type. This is because when the DWARF reader builds the internal representation for the DW_TAG_variable DIE at offset 0x51, it first builds it with the type (and the other properties such as the name for instance) of the "declaration" DIE specified by the DW_AT_specification attribute. But then, this DW_TAG_variable DIE has its own type at offset 0x3b ; libabigail should update the internal representation it just built to set the type to the one referred to at offset 0x3b. It's that updating that is not being done. So the variable wrongly points to the type of the "declaration" DIE at offset 0x2f. This patch fixes build_var_decl to make it update the type of the variable when necessary. * include/abg-ir.h (var_decl::set_type): Declare new member function. * src/abg-ir.cc (var_decl::priv::set_type): Define new member function. (var_decl::set_type): Likewise. * src/abg-dwarf-reader.cc (build_var_decl): In "updating mode", update the type of the variable as well. * tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o: Add new test binary input. * tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o: Likewise. * tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-report.txt: Add test reference output. * tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf.c: Add source code of the new test binary input. * tests/data/Makefile.am: Add the new files above to source distribution. * tests/test-diff-filter.cc (in_out_specs): Add the input binaries to the test harness. * tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Adjust. * tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise. Signed-off-by: Dodji Seketeli --- include/abg-ir.h | 3 +++ src/abg-dwarf-reader.cc | 7 +++++-- src/abg-ir.cc | 17 +++++++++++++++++ tests/data/Makefile.am | 4 ++++ ...t19-pr19023-libtcmalloc_and_profiler.so.abi | 6 +++--- ...-PR29811-unknown-size-array-dwarf-ctf-CTF.o | Bin 0 -> 1416 bytes ...R29811-unknown-size-array-dwarf-ctf-DWARF.o | Bin 0 -> 2744 bytes ...811-unknown-size-array-dwarf-ctf-report.txt | 0 ...test-PR29811-unknown-size-array-dwarf-ctf.c | 12 ++++++++++++ ...t19-pr19023-libtcmalloc_and_profiler.so.abi | 6 +++--- tests/test-diff-filter.cc | 9 +++++++++ 11 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o create mode 100644 tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o create mode 100644 tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-report.txt create mode 100644 tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf.c diff --git a/include/abg-ir.h b/include/abg-ir.h index ada61e9f..93959e92 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -2910,6 +2910,9 @@ public: const type_base_sptr get_type() const; + void + set_type(type_base_sptr&); + const type_base* get_naked_type() const; diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 4d581ee5..d2848a30 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -14447,7 +14447,7 @@ build_var_decl(reader& rdr, ABG_ASSERT(type); } - if (!type) + if (!type && !result) return result; string name, linkage_name; @@ -14460,9 +14460,12 @@ build_var_decl(reader& rdr, { // We were called to append properties that might have been // missing from the first version of the variable. And usually - // that missing property is the mangled name. + // that missing property is the mangled name or the type. if (!linkage_name.empty()) result->set_linkage_name(linkage_name); + + if (type) + result->set_type(type); } // Check if a variable symbol with this name is exported by the elf diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 6e41d849..33bd3a0e 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -18900,6 +18900,16 @@ struct var_decl::priv naked_type_(t.get()), binding_(b) {} + + /// Setter of the type of the variable. + /// + /// @param t the new variable type. + void + set_type(type_base_sptr t) + { + type_ = t; + naked_type_ = t.get(); + } }; // end struct var_decl::priv /// Constructor of the @ref var_decl type. @@ -18936,6 +18946,13 @@ const type_base_sptr var_decl::get_type() const {return priv_->type_.lock();} +/// Setter of the type of the variable. +/// +/// @param the new type of the variable. +void +var_decl::set_type(type_base_sptr& t) +{priv_->set_type(t);} + /// Getter of the type of the variable. /// /// This getter returns a bare pointer, as opposed to a smart pointer. diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 0f1f4e26..c995930f 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -1131,6 +1131,10 @@ test-diff-filter/test-PR29387-v0.c \ test-diff-filter/test-PR29387-v1.o \ test-diff-filter/test-PR29387-v0.o \ test-diff-filter/test-PR29387-report.txt \ +test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o \ +test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o \ +test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-report.txt \ +test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf.c \ \ test-diff-suppr/test0-type-suppr-v0.cc \ test-diff-suppr/test0-type-suppr-v1.cc \ diff --git a/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi b/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi index cdecfae7..2b19b1de 100644 --- a/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi +++ b/tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi @@ -32581,11 +32581,11 @@ - + - + @@ -32593,7 +32593,7 @@ - + diff --git a/tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o b/tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o new file mode 100644 index 0000000000000000000000000000000000000000..da169cb71f74180dfce3f8cda4f38e048bf87df5 GIT binary patch literal 1416 zcmbtT&2H2%5T2A}`I8Xkgv2FqVJi`*iF$wvRgqTE3L%6laYU7~NmJ8ZXBB%X%K_el zcR=D1IPwiEIv|i9Hk(fZg$U zI~?skf4LDRsYpcdpA>t&qS&Z z;Kwh&5FxM*7dp7>{V&(@h6lndXE+d0h zzT>~?yZ7Ka`TP5b`#p)8(So+)6}>Ga$RTW#$US@Sh;a|2l=U39dsv_Pi3xr19PU%Z zE}`?k&GgSs?>`sKs&7Q|wN(G^^m~qc#qn5wtB3our_#tZedKr?{A;aa;XHle^siXx HqOboADv5}Z literal 0 HcmV?d00001 diff --git a/tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o b/tests/data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o new file mode 100644 index 0000000000000000000000000000000000000000..94f5ca47e0edb1ebd3642cd8a0e3d6be6adc8b89 GIT binary patch literal 2744 zcmcIm%}*0S6o1?DU8q3g2ZFK~jiBz9Z3yyh6QV#+Lr938Y_{#Nth8IQyA{xbiC3@w z2^w!+y>c}1>VbIjU+_kviM}_Tfn`_{HSr}g@4esq?97|CFYn&Jm(Vnjq`@2M@+ zPvhRs6OsuuOp3HWNImM zr*EbY(+|N?CYu6i9fO5T!;-jwz5}=txBz%%E=9K-D$QuSfgBt7k?tZ!r-KWHL4HsP zZ7^}Bk%kA?y})%mR@PlFgoTG|`n+{pw{m9AwDjC)E@xReOCMfEhebOS24ieQH>zRX zW3vwPnD3TQwf)k@?9RlvF+Qdn4!A*~Xa{bo5Zc8GgG$YF^kcQM8?`FSmTTpwZq{+b zY{f0wMc1+2N_J&6H#uQh*)2b0K^Oq-h5(Jax9QckJtJ_RGsE_Md)Fv$+y1&y3fIjN z{HL^k(*i8a&rj*Yc$g!9aFYBMXxemKG;kP)_pI&l2}GSp6FR@b1{AxKy$QbmiZdqB z5=TjBiG%Tdw4Z|GaK=y)I!~YmB0Y_l#%+fk{LOhPqeO}13+O=k=-B~u@hSj>(^*Qr zH-giry(#o_3NBQ*7{L#FMoh-Z{L+6k;!kxS3;ltDJ3@aVINevPkcr8gp!|_X3Ri>= z;pFp3=(iO7mC!8({~&ZQgWW2=NaUg4;2Tm3*-i*%*$! - + - + - + diff --git a/tests/test-diff-filter.cc b/tests/test-diff-filter.cc index 37966d5a..ac7855da 100644 --- a/tests/test-diff-filter.cc +++ b/tests/test-diff-filter.cc @@ -822,6 +822,15 @@ InOutSpec in_out_specs[] = "data/test-diff-filter/test-PR29387-report.txt", "output/test-diff-filter/test-PR29387-report.txt", }, +#ifdef WITH_CTF + { + "data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o", + "data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-CTF.o", + "--ctf --no-default-suppression", + "data/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-report.txt", + "output/test-diff-filter/test-PR29811-unknown-size-array-dwarf-ctf-report.txt", + }, +#endif // This should be the last entry {NULL, NULL, NULL, NULL, NULL} }; -- 2.39.0 -- Dodji