This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi, I have attached a patch to reorder text and data sections in the linker according to a user specified sequence. I have added a new option --final-layout to do this. Currently, this could be done using linker scripts but this patch makes it really easy to do this. Let me explain using a simple example. test.cc void foo() { } void bar() { } int main() { return 0; } $ g++ -ffunction-sections test.cc $ nm -n a.out ... 000000000040038c T _Z3foov 0000000000400392 T _Z3barv .... foo is laid to be before bar. Now, I can change this order as follows. $ (echo "_Z3barv" && echo "_Z3foov") > sequence.txt $ g++ -ffunction-sections test.cc -Wl,--final-layout,sequence.txt $ nm -n a.out ... 0000000000400658 T _Z3barv 000000000040065e T _Z3foov ... The order is changed. This can be done for text or data sections. I am planning to write a linker plugin to be able to do a feed-back directed function/data layout according to the Pettis-Hansen code positioning algorithm. The feed-back information will be supplied by the compiler, FDO in the case of gcc. This patch is the first in the series to do that. Comments please. * layout.cc (Layout::read_layout_from_file): New method. (Layout::section_reorder): New method. (Layout::finalize): Call section_reorder when --final-layout is passed. * layout.h (Layout::read_layout_from_file): New method. (Layout::section_reorder): New method. (Layout::input_section_order): New method. (Layout::input_section_order_): New private member. * options.h (--final-layout): New option. * output.cc (Output_section::add_input_section): Keep input sections when --final-layout is used. (Output_section::reorder_layout): New method. * output.h (Output_section::reorder_layout): New method. (Input_section::Input_section): Initialize secname_. (Input_section::section_name): New method. (Input_section::set_section_name): New method. (Input_section::secname_): New member. * testsuite/Makefile.am (final_layout): New test case. * testsuite.Makefile.in: Regenerate. * testsuite/final_layout.cc: New file. * testsuite/final_layout.sh: New file. Thanks, -Sriraman.
Attachment:
final_layout_patch.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |