[GOLD][PATCH] Add .{fini,init,preinit}_array and add DT_BSYMBOLIC tags as needed.
Doug Kwan (關振德)
dougkwan@google.com
Thu Oct 15 08:03:00 GMT 2009
Hi
This patch adds the necessary tags in the dynamic section to
support uses of .fini_array, .init_array and .preinit_array sections.
It also cause DT_BSYMBOLIC tag to be added if -Bsymbolic is given in
the command line.
-Doug
2009-10-15 Doug Kwan <dougkwan@google.com>
* layout.cc (Layout::finish_dynamic_section): Generate tags
DT_FINI_ARRAY, DT_FINI_ARRAYSZ, DT_INIT_ARRAY, DT_INIT_ARRAYSZ,
DT_PREINIT_ARRAY, DT_PREINIT_ARRAYSZ and DT_BSYMBOLIC as needed.
-------------- next part --------------
Index: gold/layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.139
diff -u -p -r1.139 layout.cc
--- gold/layout.cc 14 Oct 2009 05:25:01 -0000 1.139
+++ gold/layout.cc 15 Oct 2009 07:55:40 -0000
@@ -3104,8 +3104,29 @@ Layout::finish_dynamic_section(const Inp
if (sym != NULL && sym->is_defined() && !sym->is_from_dynobj())
odyn->add_symbol(elfcpp::DT_FINI, sym);
- // FIXME: Support DT_INIT_ARRAY and DT_FINI_ARRAY.
-
+ // Look for .init_array, .preinit_array and .fini_array by checking
+ // section types.
+ for(Layout::Section_list::const_iterator p = this->section_list_.begin();
+ p != this->section_list_.end();
+ ++p)
+ switch((*p)->type())
+ {
+ case elfcpp::SHT_FINI_ARRAY:
+ odyn->add_section_address(elfcpp::DT_FINI_ARRAY, *p);
+ odyn->add_section_size(elfcpp::DT_FINI_ARRAYSZ, *p);
+ break;
+ case elfcpp::SHT_INIT_ARRAY:
+ odyn->add_section_address(elfcpp::DT_INIT_ARRAY, *p);
+ odyn->add_section_size(elfcpp::DT_INIT_ARRAYSZ, *p);
+ break;
+ case elfcpp::SHT_PREINIT_ARRAY:
+ odyn->add_section_address(elfcpp::DT_PREINIT_ARRAY, *p);
+ odyn->add_section_size(elfcpp::DT_PREINIT_ARRAYSZ, *p);
+ break;
+ default:
+ break;
+ }
+
// Add a DT_RPATH entry if needed.
const General_options::Dir_list& rpath(parameters->options().rpath());
if (!rpath.empty())
@@ -3186,6 +3207,8 @@ Layout::finish_dynamic_section(const Inp
flags |= elfcpp::DF_STATIC_TLS;
if (parameters->options().origin())
flags |= elfcpp::DF_ORIGIN;
+ if (parameters->options().Bsymbolic())
+ flags |= elfcpp::DF_SYMBOLIC;
if (parameters->options().now())
flags |= elfcpp::DF_BIND_NOW;
odyn->add_constant(elfcpp::DT_FLAGS, flags);
More information about the Binutils
mailing list