[applied] dwarf-reader: Bug 29811 - Support updating of variable type
Commit Message
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 <is_basic_table>
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 <abi-corpus version='2.1' path='test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o' architecture='elf-amd-x86_64'>
2 <elf-variable-symbols>
3 <elf-symbol name='is_basic_table' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
4 </elf-variable-symbols>
5 <abi-instr address-size='64' path='test-PR29811-unknown-size-array-dwarf-ctf.c' comp-dir-path='/home/dodji/git/libabigail/PR29811/prtests' language='LANG_C11'>
6 <type-decl name='unsigned int' size-in-bits='32' id='type-id-1'/>
7 <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='32' id='type-id-2'>
8 <subrange length='1' type-id='type-id-3' id='type-id-4'/>
9 </array-type-def>
10 <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='infinite' id='type-id-5'>
11 <subrange length='infinite' id='type-id-6'/>
12 </array-type-def>
13 <type-decl name='unsigned long int' size-in-bits='64' id='type-id-3'/>
14 <var-decl name='is_basic_table' type-id='type-id-5' mangled-name='is_basic_table' visibility='default' filepath='/home/dodji/git/libabigail/PR29811/prtests/test-PR29811-unknown-size-array-dwarf-ctf.c' line='10' column='1' elf-symbol-id='is_basic_table'/>
15 </abi-instr>
16 </abi-corpus>
The variable is_basic_table is described by the element at line 14:
14 <var-decl name='is_basic_table' type-id='type-id-5' mangled-name='is_basic_table' visibility='default' filepath='/home/dodji/git/libabigail/PR29811/prtests/test-PR29811-unknown-size-array-dwarf-ctf.c' line='10' column='1' elf-symbol-id='is_basic_table'/>
Its type has the ID 'type-id-5' which is defined at line 10:
10 <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='infinite' id='type-id-5'>
11 <subrange length='infinite' id='type-id-6'/>
12 </array-type-def>
Which has an unknown size.
But the, at line 7, there is another array type defined with a size of
32 bits:
7 <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='32' id='type-id-2'>
8 <subrange length='1' type-id='type-id-3' id='type-id-4'/>
9 </array-type-def>
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 <dodji@redhat.com>
---
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
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`@2<X%YoE
zXg-qjT+BlTdZC1JGiYrDC26}vn<Q-nC0b38Xd;kj(K^mvMwuIzQD~tJAi<NgW>M@+
zPvhRs6OsuuO<T%n8Fab|snpz1Ych@XdbDflOe#6pKiGX9YYd@d^B5%4Q>p3HWNImM
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*%*$!<mi$MUU&nmWAX2rTwaJ}^!
z+PG{Ni#~gH%xwF%=dj};71v`j1WQPf-~!i6wQ7~&myYSxLT2LB8$oE7HihnZb#u$F
zZ81OGmCgS<@5fL&Yk9shQ(g)RSKrwX+6jx!8inL(iy<}sI{MJeo)#aSF-oWEbf0QY
z^2^hPB<HH3o%E$Sp`3Z?Ab6W7v@i5-<OIq0MZY^lv$*2wzvotfHNhoQeOFG2|0x1=
z87R0Kzl?ZX|KCLavQO%t-jmvY88I~{LNFk}aZ)0r`WDa@SN}lNUlg%apT0HK`df%m
z&QV-ZS`~%V5tsEPe}O@9@t=jm*Jx7VOOT9zEo8O+y99Xw(7%`{$vDa1pi#<Ezb_&_
zijl1PzD11gMRng7fZCTlKgvZ!`P5j#+r)#~BL%4kSKR&6ov3e*{67hBhLi}Y{Zrn!
Q_&ooI2=FlyOQIV88^I&}uK)l5
literal 0
HcmV?d00001
@@ -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;
@@ -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
@@ -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.
@@ -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 \
@@ -32581,11 +32581,11 @@
</data-member>
<data-member access='private' static='yes'>
<!-- static tcmalloc::PageHeapAllocator<tcmalloc::Span> tcmalloc::Static::span_allocator_ -->
- <var-decl name='span_allocator_' type-id='type-id-1507' mangled-name='_ZN8tcmalloc6Static15span_allocator_E' visibility='default' filepath='src/static_vars.h' line='99' column='1' elf-symbol-id='_ZN8tcmalloc6Static15span_allocator_E'/>
+ <var-decl name='span_allocator_' type-id='type-id-1281' mangled-name='_ZN8tcmalloc6Static15span_allocator_E' visibility='default' filepath='src/static_vars.h' line='99' column='1' elf-symbol-id='_ZN8tcmalloc6Static15span_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
<!-- static tcmalloc::PageHeapAllocator<tcmalloc::StackTrace> tcmalloc::Static::stacktrace_allocator_ -->
- <var-decl name='stacktrace_allocator_' type-id='type-id-1510' mangled-name='_ZN8tcmalloc6Static21stacktrace_allocator_E' visibility='default' filepath='src/static_vars.h' line='100' column='1' elf-symbol-id='_ZN8tcmalloc6Static21stacktrace_allocator_E'/>
+ <var-decl name='stacktrace_allocator_' type-id='type-id-1147' mangled-name='_ZN8tcmalloc6Static21stacktrace_allocator_E' visibility='default' filepath='src/static_vars.h' line='100' column='1' elf-symbol-id='_ZN8tcmalloc6Static21stacktrace_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
<!-- static tcmalloc::Span tcmalloc::Static::sampled_objects_ -->
@@ -32593,7 +32593,7 @@
</data-member>
<data-member access='private' static='yes'>
<!-- static tcmalloc::PageHeapAllocator<tcmalloc::StackTraceTable::Bucket> tcmalloc::Static::bucket_allocator_ -->
- <var-decl name='bucket_allocator_' type-id='type-id-1554' mangled-name='_ZN8tcmalloc6Static17bucket_allocator_E' visibility='default' filepath='src/static_vars.h' line='102' column='1' elf-symbol-id='_ZN8tcmalloc6Static17bucket_allocator_E'/>
+ <var-decl name='bucket_allocator_' type-id='type-id-1305' mangled-name='_ZN8tcmalloc6Static17bucket_allocator_E' visibility='default' filepath='src/static_vars.h' line='102' column='1' elf-symbol-id='_ZN8tcmalloc6Static17bucket_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
<!-- static tcmalloc::StackTrace* tcmalloc::Static::growth_stacks_ -->
new file mode 100644
GIT binary patch
literal 1416
zcmbtT&2H2%5T2A}`I8Xkgv2FqVJi`*iF$wvRgqTE3L%6laYU7~NmJ8ZXBB%X%K_el
zcR=D1IPw<o3h)9j(|EGMEeFI%;~9VRedBnNe0coq$yyKqTL3$-+A#|7b#0Yrr)dV)
z;41w5Hs~tj6$J*ElV5gz1LGY1Bl<=3E$5WG^M=F^(XXSU4cowFxJi5B@_~0-!jR6$
z+ML#oNBvHFFSJpWE{jlU3vX&wfHDWUG-`5SWj-xoTI(wOgXIz8qk2}xMP0mBaiwfL
zRk_SnCDk;3v7bJCkR<WEv8AylrZsY4w9v=8KGBg;@5)Fvja){>iEIv|i9Hk(fZg$U
zI~?skf4LDRsYpc<rkiP+Bxw?k_VI!Dq;-X8YlAMwGorbn3}+F1A&f0>dpA>t&qS&Z
z;Kwh&5FxM*7dp7>{V&(@h6lndXE<n#wrS%LXSRH6K@`$T5V<iRa4@*kvssDnO6b~_
z0`D0aD<{WpU+IOIH}$-1?6P~%|4eS9o@T-y9k<Ik@uEN9J6I=dHMv%hwc*U_>+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
new file mode 100644
new file mode 100644
@@ -0,0 +1,12 @@
+/*
+ Compile this file twice. Once with DWARF debug info and once with
+ CTF debug info:
+
+ gcc -g -c test-PR29811-unknown-size-array-dwarf-ctf.c -o test-PR29811-unknown-size-array-dwarf-ctf-DWARF.o
+
+ gcc -gctf -c test-PR29811-unknown-size-array-dwarf-ctf.c -o test-PR29811-unknown-size-array-dwarf-ctf-CTF.o
+
+*/
+extern unsigned int is_basic_table[];
+
+unsigned int is_basic_table[] = {0};
@@ -20374,16 +20374,16 @@
<var-decl name='central_cache_' type-id='type-id-1431' mangled-name='_ZN8tcmalloc6Static14central_cache_E' visibility='default' filepath='src/static_vars.h' line='98' column='1' elf-symbol-id='_ZN8tcmalloc6Static14central_cache_E'/>
</data-member>
<data-member access='private' static='yes'>
- <var-decl name='span_allocator_' type-id='type-id-1507' mangled-name='_ZN8tcmalloc6Static15span_allocator_E' visibility='default' filepath='src/static_vars.h' line='99' column='1' elf-symbol-id='_ZN8tcmalloc6Static15span_allocator_E'/>
+ <var-decl name='span_allocator_' type-id='type-id-1281' mangled-name='_ZN8tcmalloc6Static15span_allocator_E' visibility='default' filepath='src/static_vars.h' line='99' column='1' elf-symbol-id='_ZN8tcmalloc6Static15span_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
- <var-decl name='stacktrace_allocator_' type-id='type-id-1510' mangled-name='_ZN8tcmalloc6Static21stacktrace_allocator_E' visibility='default' filepath='src/static_vars.h' line='100' column='1' elf-symbol-id='_ZN8tcmalloc6Static21stacktrace_allocator_E'/>
+ <var-decl name='stacktrace_allocator_' type-id='type-id-1147' mangled-name='_ZN8tcmalloc6Static21stacktrace_allocator_E' visibility='default' filepath='src/static_vars.h' line='100' column='1' elf-symbol-id='_ZN8tcmalloc6Static21stacktrace_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='sampled_objects_' type-id='type-id-144' mangled-name='_ZN8tcmalloc6Static16sampled_objects_E' visibility='default' filepath='src/static_vars.h' line='101' column='1' elf-symbol-id='_ZN8tcmalloc6Static16sampled_objects_E'/>
</data-member>
<data-member access='private' static='yes'>
- <var-decl name='bucket_allocator_' type-id='type-id-1554' mangled-name='_ZN8tcmalloc6Static17bucket_allocator_E' visibility='default' filepath='src/static_vars.h' line='102' column='1' elf-symbol-id='_ZN8tcmalloc6Static17bucket_allocator_E'/>
+ <var-decl name='bucket_allocator_' type-id='type-id-1305' mangled-name='_ZN8tcmalloc6Static17bucket_allocator_E' visibility='default' filepath='src/static_vars.h' line='102' column='1' elf-symbol-id='_ZN8tcmalloc6Static17bucket_allocator_E'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='growth_stacks_' type-id='type-id-1560' mangled-name='_ZN8tcmalloc6Static14growth_stacks_E' visibility='default' filepath='src/static_vars.h' line='108' column='1' elf-symbol-id='_ZN8tcmalloc6Static14growth_stacks_E'/>
@@ -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}
};