Linker plugins should be aware of --defsym during symbol resolution

Cary Coutant ccoutant@gmail.com
Thu Feb 15 22:21:00 GMT 2018


> * expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
>       New method.
> (Unary_expression::set_expr_sym_in_real_elf): New method.
> (Binary_expression::set_expr_sym_in_real_elf): New method.
> (Trinary_expression::set_expr_sym_in_real_elf): New method.
> * plugin.cc (get_symbol_resolution_info): Fix symbol resolution if
> defined or used in defsyms.
> * plugin.h (Plugin_manager::is_defsym_def): New method.
> (Plugin_manager::Plugin_manager): Initialize defsym_defines_set_.
> (Plugin_manager::defsym_defines_set_): New member.
> (Plugin_manager::Defsym_defines_set): New typedef.
> * script.cc (Script_options::set_defsym_uses_in_real_elf): New method.
> (Script_options::find_defsym_defs): New method.
> * script.h (Expression::set_expr_sym_in_real_elf): New method.
> (Symbol_assignment::is_defsym): New method.
> (Symbol_assignment::value): New method.
> (Script_options::find_defsym_defs): New method.
> (Script_options::set_defsym_uses_in_real_elf): New method.
> * testsuite/Makefile.am (plugin_test_defsym): New test.
> * testsuite/Makefile.in: Regenerate.
> * testsuite/plugin_test.c: Check for new symbol resolution.
> * testsuite/plugin_test_defsym.sh: New script.
> * testsuite/plugin_test_defsym.c: New test source.

+// Populates the set with symbols used in defsym LHS.
+
+void Script_options::find_defsym_defs(Unordered_set<std::string>& defsym_set)
+{
+  for (Symbol_assignments::const_iterator p =
this->symbol_assignments_.begin();
+       p != this->symbol_assignments_.end();
+       ++p)
+    {
+      if ((*p)->is_defsym())
+        defsym_set.insert((*p)->name());
+    }
+}
+
+void
+Script_options::set_defsym_uses_in_real_elf(Symbol_table* symtab) const
+{
+  for (Symbol_assignments::const_iterator p =
this->symbol_assignments_.begin();
+       p != this->symbol_assignments_.end();
+       ++p)
+    {
+      if ((*p)->is_defsym())
+        (*p)->value()->set_expr_sym_in_real_elf(symtab);
+    }
+}

Are you intentionally excluding symbols defined in scripts? It seems
to me that they should be treated the same as --defsym.

+  // Sets all symbols used in expressions as seen in a real ELF object.
+  virtual void
+  set_expr_sym_in_real_elf(Symbol_table*) const
+  { return; }

Omit "return;".

-cary



More information about the Binutils mailing list