summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillermo E. Martinez <guillermo.e.martinez@oracle.com>2022-05-06 20:43:05 -0500
committerDodji Seketeli <dodji@redhat.com>2022-05-13 14:08:28 +0200
commita846964b0b75c3a4f5b7fd1f567abb87709f1a1b (patch)
treef4259f38808753734cca0bd91eef2347e1cc0a0c
parentFix numbering error in the abidiff manual. (diff)
downloadlibabigail-a846964b0b75c3a4f5b7fd1f567abb87709f1a1b.tar.gz
libabigail-a846964b0b75c3a4f5b7fd1f567abb87709f1a1b.tar.bz2
libabigail-a846964b0b75c3a4f5b7fd1f567abb87709f1a1b.tar.xz
ctf-reader: shows incomplete summary changes
During corpus comparison with ctf support, summary changes for functions and variables are shown like to the binaries doesn't have ctf debug information, even though they were compiled with '-gctf' compiler modifier, e.g: 2 Removed function symbols not referenced by debug info: [D] elf32_test_main@@ELFUTILS_1.7 [D] elf64_test_main@@ELFUTILS_1.7 So, expected changes summary should be: 2 Removed functions: [D] 'function long int elf32_test_main()' {elf32_test_main@@ELFUTILS_1.7} [D] 'function long int elf64_test_main()' {elf64_test_main@@ELFUTILS_1.7} * src/abg-ctf-reader.cc (read_context::exported_decls_builder_): Add new data member. (read_context::exported_decls_builder): Add new get/set member functions. (read_context::maybe_add_{fn,var}_to_exported_decls): Likewise. (read_context::initialize): Initialize exported_decls_builder_ member. (read_context::build_ir_node_for_variadic_parameter_type): Add new function. (read_context::process_ctf_function_type): Add additional code to handle function's variadic parameter. (read_context::process_ctf_archive): Rename variable for clarity from `ctf_var_type' to `ctf_sym_type', using new member functions `maybe_add_{fn,var}_to_exported_decls'. (read_context::read_corpus): Set `exported_decls_builder'. * tests/test-read-common.cc (test_task::run_abidw): Fix error message. * tests/data/test-read-ctf/test-PR26568-1.o.abi: Adjust test case. * tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise. * tests/data/test-read-ctf/test-anonymous-fields.o.abi Likewise. * tests/data/test-read-ctf/test5.o.abi: Likewise. * tests/data/test-read-ctf/test7.o.abi: Likewise. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
-rw-r--r--src/abg-ctf-reader.cc104
-rw-r--r--tests/data/test-read-ctf/test5.o.abi1
-rw-r--r--tests/data/test-read-ctf/test7.o.abi1
-rw-r--r--tests/test-read-common.cc4
4 files changed, 101 insertions, 9 deletions
diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index 95c81f0e..a6a0b74e 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -84,6 +84,52 @@ public:
84 84
85 corpus_sptr cur_corpus_; 85 corpus_sptr cur_corpus_;
86 corpus_group_sptr cur_corpus_group_; 86 corpus_group_sptr cur_corpus_group_;
87 corpus::exported_decls_builder* exported_decls_builder_;
88
89 /// Setter of the exported decls builder object.
90 ///
91 /// Note that this @ref read_context is not responsible for the live
92 /// time of the exported_decls_builder object. The corpus is.
93 ///
94 /// @param b the new builder.
95 void
96 exported_decls_builder(corpus::exported_decls_builder* b)
97 {exported_decls_builder_ = b;}
98
99 /// Getter of the exported decls builder object.
100 ///
101 /// @return the exported decls builder.
102 corpus::exported_decls_builder*
103 exported_decls_builder()
104 {return exported_decls_builder_;}
105
106 /// If a given function decl is suitable for the set of exported
107 /// functions of the current corpus, this function adds it to that
108 /// set.
109 ///
110 /// @param fn the function to consider for inclusion into the set of
111 /// exported functions of the current corpus.
112 void
113 maybe_add_fn_to_exported_decls(function_decl* fn)
114 {
115 if (fn)
116 if (corpus::exported_decls_builder* b = exported_decls_builder())
117 b->maybe_add_fn_to_exported_fns(fn);
118 }
119
120 /// If a given variable decl is suitable for the set of exported
121 /// variables of the current corpus, this variable adds it to that
122 /// set.
123 ///
124 /// @param fn the variable to consider for inclusion into the set of
125 /// exported variables of the current corpus.
126 void
127 maybe_add_var_to_exported_decls(var_decl* var)
128 {
129 if (var)
130 if (corpus::exported_decls_builder* b = exported_decls_builder())
131 b->maybe_add_var_to_exported_vars(var);
132 }
87 133
88 /// Getter of the current corpus group being constructed. 134 /// Getter of the current corpus group being constructed.
89 /// 135 ///
@@ -241,6 +287,7 @@ public:
241 is_elf_exec = false; 287 is_elf_exec = false;
242 symtab.reset(); 288 symtab.reset();
243 cur_corpus_group_.reset(); 289 cur_corpus_group_.reset();
290 exported_decls_builder_ = 0;
244 } 291 }
245 292
246 ~read_context() 293 ~read_context()
@@ -392,6 +439,26 @@ process_ctf_base_type(read_context *ctxt,
392 return result; 439 return result;
393} 440}
394 441
442/// Build the IR node for a variadic parameter type.
443///
444/// @param ctxt the read context to use.
445///
446/// @return the variadic parameter type.
447static decl_base_sptr
448build_ir_node_for_variadic_parameter_type(read_context &ctxt,
449 translation_unit_sptr tunit)
450{
451
452 ir::environment* env = ctxt.ir_env;
453 ABG_ASSERT(env);
454 type_base_sptr t = env->get_variadic_parameter_type();
455 decl_base_sptr type_declaration = get_type_declaration(t);
456 if (!has_scope(type_declaration))
457 add_decl_to_scope(type_declaration, tunit->get_global_scope());
458 canonicalize(t);
459 return type_declaration;
460}
461
395/// Build and return a function type libabigail IR. 462/// Build and return a function type libabigail IR.
396/// 463///
397/// @param ctxt the read context. 464/// @param ctxt the read context.
@@ -442,11 +509,24 @@ process_ctf_function_type(read_context *ctxt,
442 function_decl::parameter_sptr parm 509 function_decl::parameter_sptr parm
443 (new function_decl::parameter(arg_type, "", 510 (new function_decl::parameter(arg_type, "",
444 location(), 511 location(),
445 vararg_p && (i == argc - 1), 512 false,
446 false /* is_artificial */)); 513 false /* is_artificial */));
447 function_parms.push_back(parm); 514 function_parms.push_back(parm);
448 } 515 }
449 516
517 if (vararg_p)
518 {
519 type_base_sptr arg_type =
520 is_type(build_ir_node_for_variadic_parameter_type(*ctxt, tunit));
521
522 function_decl::parameter_sptr parm
523 (new function_decl::parameter(arg_type, "",
524 location(),
525 true,
526 false /* is_artificial */));
527 function_parms.push_back(parm);
528 }
529
450 result = dynamic_pointer_cast<function_type>(ctxt->lookup_type(ctf_dictionary, 530 result = dynamic_pointer_cast<function_type>(ctxt->lookup_type(ctf_dictionary,
451 ctf_type)); 531 ctf_type));
452 if (result) 532 if (result)
@@ -1144,22 +1224,22 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp)
1144 for (const auto& symbol : symtab_reader::filtered_symtab(*symtab, filter)) 1224 for (const auto& symbol : symtab_reader::filtered_symtab(*symtab, filter))
1145 { 1225 {
1146 std::string sym_name = symbol->get_name(); 1226 std::string sym_name = symbol->get_name();
1147 ctf_id_t ctf_var_type; 1227 ctf_id_t ctf_sym_type;
1148 1228
1149 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN) 1229 if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
1150 || ctxt->is_elf_exec) 1230 || ctxt->is_elf_exec)
1151 ctf_var_type= ctf_lookup_variable (ctf_dict, sym_name.c_str()); 1231 ctf_sym_type= ctf_lookup_variable (ctf_dict, sym_name.c_str());
1152 else 1232 else
1153 ctf_var_type = ctf_lookup_by_symbol_name(ctf_dict, sym_name.c_str()); 1233 ctf_sym_type = ctf_lookup_by_symbol_name(ctf_dict, sym_name.c_str());
1154 1234
1155 if (ctf_var_type == (ctf_id_t) -1) 1235 if (ctf_sym_type == (ctf_id_t) -1)
1156 continue; 1236 continue;
1157 1237
1158 if (ctf_type_kind (ctf_dict, ctf_var_type) != CTF_K_FUNCTION) 1238 if (ctf_type_kind (ctf_dict, ctf_sym_type) != CTF_K_FUNCTION)
1159 { 1239 {
1160 const char *var_name = sym_name.c_str(); 1240 const char *var_name = sym_name.c_str();
1161 type_base_sptr var_type = lookup_type(ctxt, corp, ir_translation_unit, 1241 type_base_sptr var_type = lookup_type(ctxt, corp, ir_translation_unit,
1162 ctf_dict, ctf_var_type); 1242 ctf_dict, ctf_sym_type);
1163 if (!var_type) 1243 if (!var_type)
1164 /* Ignore variable if its type can't be sorted out. */ 1244 /* Ignore variable if its type can't be sorted out. */
1165 continue; 1245 continue;
@@ -1173,11 +1253,13 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp)
1173 var_declaration->set_symbol(symbol); 1253 var_declaration->set_symbol(symbol);
1174 add_decl_to_scope(var_declaration, 1254 add_decl_to_scope(var_declaration,
1175 ir_translation_unit->get_global_scope()); 1255 ir_translation_unit->get_global_scope());
1256 var_declaration->set_is_in_public_symbol_table(true);
1257 ctxt->maybe_add_var_to_exported_decls(var_declaration.get());
1176 } 1258 }
1177 else 1259 else
1178 { 1260 {
1179 const char *func_name = sym_name.c_str(); 1261 const char *func_name = sym_name.c_str();
1180 ctf_id_t ctf_sym = ctf_var_type; 1262 ctf_id_t ctf_sym = ctf_sym_type;
1181 type_base_sptr func_type = lookup_type(ctxt, corp, ir_translation_unit, 1263 type_base_sptr func_type = lookup_type(ctxt, corp, ir_translation_unit,
1182 ctf_dict, ctf_sym); 1264 ctf_dict, ctf_sym);
1183 if (!func_type) 1265 if (!func_type)
@@ -1193,6 +1275,8 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp)
1193 func_declaration->set_symbol(symbol); 1275 func_declaration->set_symbol(symbol);
1194 add_decl_to_scope(func_declaration, 1276 add_decl_to_scope(func_declaration,
1195 ir_translation_unit->get_global_scope()); 1277 ir_translation_unit->get_global_scope());
1278 func_declaration->set_is_in_public_symbol_table(true);
1279 ctxt->maybe_add_fn_to_exported_decls(func_declaration.get());
1196 } 1280 }
1197 } 1281 }
1198 1282
@@ -1370,6 +1454,10 @@ read_corpus(read_context *ctxt, elf_reader::status &status)
1370 return corp; 1454 return corp;
1371 } 1455 }
1372 1456
1457 // Set the set of exported declaration that are defined.
1458 ctxt->exported_decls_builder
1459 (ctxt->cur_corpus_->get_exported_decls_builder().get());
1460
1373 int errp; 1461 int errp;
1374 if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN) 1462 if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
1375 { 1463 {
diff --git a/tests/data/test-read-ctf/test5.o.abi b/tests/data/test-read-ctf/test5.o.abi
index f7bcdeb1..1dafd13e 100644
--- a/tests/data/test-read-ctf/test5.o.abi
+++ b/tests/data/test-read-ctf/test5.o.abi
@@ -32,6 +32,7 @@
32 <return type-id='type-id-7'/> 32 <return type-id='type-id-7'/>
33 </function-decl> 33 </function-decl>
34 <function-decl name='bar' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='8' elf-symbol-id='bar'> 34 <function-decl name='bar' visibility='default' binding='global' size-in-bits='64' alignment-in-bits='8' elf-symbol-id='bar'>
35 <parameter type-id='type-id-9'/>
35 <parameter is-variadic='yes'/> 36 <parameter is-variadic='yes'/>
36 <return type-id='type-id-12'/> 37 <return type-id='type-id-12'/>
37 </function-decl> 38 </function-decl>
diff --git a/tests/data/test-read-ctf/test7.o.abi b/tests/data/test-read-ctf/test7.o.abi
index a13af174..ca572400 100644
--- a/tests/data/test-read-ctf/test7.o.abi
+++ b/tests/data/test-read-ctf/test7.o.abi
@@ -26,6 +26,7 @@
26 <return type-id='type-id-10'/> 26 <return type-id='type-id-10'/>
27 </function-decl> 27 </function-decl>
28 <function-type size-in-bits='64' alignment-in-bits='8' id='type-id-9'> 28 <function-type size-in-bits='64' alignment-in-bits='8' id='type-id-9'>
29 <parameter is-variadic='yes'/>
29 <return type-id='type-id-10'/> 30 <return type-id='type-id-10'/>
30 </function-type> 31 </function-type>
31 <type-decl name='void' id='type-id-10'/> 32 <type-decl name='void' id='type-id-10'/>
diff --git a/tests/test-read-common.cc b/tests/test-read-common.cc
index 9681ac27..b441945c 100644
--- a/tests/test-read-common.cc
+++ b/tests/test-read-common.cc
@@ -95,6 +95,8 @@ test_task::run_abidw(const string& extargs)
95{ 95{
96 string abidw = string(get_build_dir()) + "/tools/abidw"; 96 string abidw = string(get_build_dir()) + "/tools/abidw";
97 string drop_private_types; 97 string drop_private_types;
98 set_in_abi_path();
99
98 if (!in_public_headers_path.empty()) 100 if (!in_public_headers_path.empty())
99 drop_private_types += "--headers-dir " + in_public_headers_path + 101 drop_private_types += "--headers-dir " + in_public_headers_path +
100 " --drop-private-types"; 102 " --drop-private-types";
@@ -103,7 +105,7 @@ test_task::run_abidw(const string& extargs)
103 if (system(cmd.c_str())) 105 if (system(cmd.c_str()))
104 { 106 {
105 error_message = string("ABIs differ:\n") 107 error_message = string("ABIs differ:\n")
106 + in_elf_path 108 + in_abi_path
107 + "\nand:\n" 109 + "\nand:\n"
108 + out_abi_path 110 + out_abi_path
109 + "\n"; 111 + "\n";