diff options
author | Sriraman Tallam <tmsriram@google.com> | 2012-08-24 18:35:35 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2012-08-24 18:35:35 +0000 |
commit | 16164a6b00372ebc0360f6aa71337e5613278817 (patch) | |
tree | 503893149fa2b29775eafe985a0a537cf7433132 /gold/testsuite | |
parent | 92a289b3800274d15d440cea98c0df067da4c2ec (diff) | |
download | gdb-16164a6b00372ebc0360f6aa71337e5613278817.zip gdb-16164a6b00372ebc0360f6aa71337e5613278817.tar.gz gdb-16164a6b00372ebc0360f6aa71337e5613278817.tar.bz2 |
Patch adds support to allow plugins to map selected subset of sections to unique
segments.
2012-08-24 Sriraman Tallam <tmsriram@google.com>
* gold.cc (queue_middle_tasks): Call layout again when unique
segments for sections is desired.
* layout.cc (Layout::Layout): Initialize new members.
(Layout::get_output_section_flags): New function.
(Layout::choose_output_section): Call get_output_section_flags.
(Layout::layout): Make output section for mapping to a unique segment.
(Layout::insert_section_segment_map): New function.
(Layout::attach_allocated_section_to_segment): Make unique segment for
output sections marked so.
(Layout::segment_precedes): Check for unique segments when sorting.
* layout.h (Layout::Unique_segment_info): New struct.
(Layout::Section_segment_map): New typedef.
(Layout::insert_section_segment_map): New function.
(Layout::get_output_section_flags): New function.
(Layout::is_unique_segment_for_sections_specified): New function.
(Layout::set_unique_segment_for_sections_specified): New function.
(Layout::unique_segment_for_sections_specified_): New member.
(Layout::section_segment_map_): New member.
* object.cc (Sized_relobj_file<size, big_endian>::do_layout):
Rename is_gc_pass_one to is_pass_one.
Rename is_gc_pass_two to is_pass_two.
Rename is_gc_or_icf to is_two_pass.
Check for which pass based on whether symbols data is present.
Make it two pass when unique segments for sections is desired.
* output.cc (Output_section::Output_section): Initialize new
members.
* output.h (Output_section::is_unique_segment): New function.
(Output_section::set_is_unique_segment): New function.
(Output_section::is_unique_segment_): New member.
(Output_section::extra_segment_flags): New function.
(Output_section::set_extra_segment_flags): New function.
(Output_section::extra_segment_flags_): New member.
(Output_section::segment_alignment): New function.
(Output_section::set_segment_alignment): New function.
(Output_section::segment_alignment_): New member.
(Output_segment::Output_segment): Initialize is_unique_segment_.
(Output_segment::is_unique_segment): New function.
(Output_segment::set_is_unique_segment): New function.
(Output_segment::is_unique_segment_): New member.
* plugin.cc (allow_unique_segment_for_sections): New function.
(unique_segment_for_sections): New function.
(Plugin::load): Add new functions to transfer vector.
* Makefile.am (plugin_final_layout.readelf.stdout): Add readelf output.
* Makefile.in: Regenerate.
* testsuite/plugin_final_layout.sh: Check if unique segment
functionality works.
* testsuite/plugin_section_order.c (onload): Check if new interfaces
are available.
(allow_unique_segment_for_sections): New global.
(unique_segment_for_sections): New global.
(claim_file_hook): Call allow_unique_segment_for_sections.
(all_symbols_read_hook): Call unique_segment_for_sections.
2012-08-24 Sriraman Tallam <tmsriram@google.com>
* plugin-api.h (ld_plugin_allow_unique_segment_for_sections):
New interface.
(ld_plugin_unique_segment_for_sections): New interface.
(LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS): New enum val.
(LDPT_UNIQUE_SEGMENT_FOR_SECTIONS): New enum val.
(tv_allow_unique_segment_for_sections): New member.
(tv_unique_segment_for_sections): New member.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 4 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 5 | ||||
-rwxr-xr-x | gold/testsuite/plugin_final_layout.sh | 30 | ||||
-rw-r--r-- | gold/testsuite/plugin_section_order.c | 35 |
4 files changed, 65 insertions, 9 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 0e98e6a..146c7e0 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1529,13 +1529,15 @@ unused.c: @cp /dev/null $@ check_SCRIPTS += plugin_final_layout.sh -check_DATA += plugin_final_layout.stdout +check_DATA += plugin_final_layout.stdout plugin_final_layout_readelf.stdout plugin_final_layout.o: plugin_final_layout.cc $(CXXCOMPILE) -O0 -c -ffunction-sections -fdata-sections -g -o $@ $< plugin_final_layout: plugin_final_layout.o plugin_section_order.so gcctestdir/ld $(CXXLINK) -Bgcctestdir/ -Wl,--plugin,"./plugin_section_order.so" plugin_final_layout.o plugin_final_layout.stdout: plugin_final_layout $(TEST_NM) -n plugin_final_layout > plugin_final_layout.stdout +plugin_final_layout_readelf.stdout: plugin_final_layout + $(TEST_READELF) -Wl plugin_final_layout > plugin_final_layout_readelf.stdout plugin_section_order.so: plugin_section_order.o $(LINK) -Bgcctestdir/ -shared plugin_section_order.o diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index a3a4506..b937ff0 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -329,7 +329,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_9.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_final_layout.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_final_layout.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_final_layout.readelf.stdout # Make a copy of two_file_test_1.o, which does not define the symbol _Z4t16av. @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_36 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \ @@ -4875,6 +4876,8 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--plugin,"./plugin_section_order.so" plugin_final_layout.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_final_layout.stdout: plugin_final_layout @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_NM) -n plugin_final_layout > plugin_final_layout.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_final_layout.readelf.stdout: plugin_final_layout +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_READELF) -Wl plugin_final_layout > plugin_final_layout_readelf.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_section_order.so: plugin_section_order.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(LINK) -Bgcctestdir/ -shared plugin_section_order.o diff --git a/gold/testsuite/plugin_final_layout.sh b/gold/testsuite/plugin_final_layout.sh index 600f8e2..75a40d3 100755 --- a/gold/testsuite/plugin_final_layout.sh +++ b/gold/testsuite/plugin_final_layout.sh @@ -56,5 +56,35 @@ END { }" $1 } +# With readelf -l, an ELF Section to Segment mapping is printed as : +############################################## +# Section to Segment mapping: +# Segment Sections... +# ... +# 0x .text.plugin_created_unique +# ... +############################################## +# Check of .text.plugin_created_unique is the only section in the segment. +check_unique_segment() +{ + awk " +BEGIN { saw_section = 0; saw_unique = 0; } +/$2/ { saw_section = 1; } +/[ ]*0[0-9][ ]*$2[ ]*\$/ { saw_unique = 1; } +END { + if (!saw_section) + { + printf \"Section $2 not seen in output\\n\"; + exit 1; + } + else if (!saw_unique) + { + printf \"Unique segment not seen for: $2\\n\"; + exit 1; + } + }" $1 +} + check plugin_final_layout.stdout "_Z3foov" "_Z3barv" check plugin_final_layout.stdout "_Z3barv" "_Z3bazv" +check_unique_segment plugin_final_layout_readelf.stdout ".text.plugin_created_unique" diff --git a/gold/testsuite/plugin_section_order.c b/gold/testsuite/plugin_section_order.c index 0e2079b..fdc6fe4 100644 --- a/gold/testsuite/plugin_section_order.c +++ b/gold/testsuite/plugin_section_order.c @@ -36,6 +36,9 @@ static ld_plugin_get_input_section_name get_input_section_name = NULL; static ld_plugin_get_input_section_contents get_input_section_contents = NULL; static ld_plugin_update_section_order update_section_order = NULL; static ld_plugin_allow_section_ordering allow_section_ordering = NULL; +static ld_plugin_allow_unique_segment_for_sections + allow_unique_segment_for_sections = NULL; +static ld_plugin_unique_segment_for_sections unique_segment_for_sections = NULL; enum ld_plugin_status onload(struct ld_plugin_tv *tv); enum ld_plugin_status claim_file_hook(const struct ld_plugin_input_file *file, @@ -52,11 +55,13 @@ onload(struct ld_plugin_tv *tv) switch (entry->tv_tag) { case LDPT_REGISTER_CLAIM_FILE_HOOK: - assert((*entry->tv_u.tv_register_claim_file) (claim_file_hook) == LDPS_OK); + assert((*entry->tv_u.tv_register_claim_file) (claim_file_hook) + == LDPS_OK); break; case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: - assert((*entry->tv_u.tv_register_all_symbols_read) (all_symbols_read_hook) - == LDPS_OK); + assert((*entry->tv_u.tv_register_all_symbols_read) + (all_symbols_read_hook) + == LDPS_OK); break; case LDPT_GET_INPUT_SECTION_COUNT: get_input_section_count = *entry->tv_u.tv_get_input_section_count; @@ -68,7 +73,8 @@ onload(struct ld_plugin_tv *tv) get_input_section_name = *entry->tv_u.tv_get_input_section_name; break; case LDPT_GET_INPUT_SECTION_CONTENTS: - get_input_section_contents = *entry->tv_u.tv_get_input_section_contents; + get_input_section_contents + = *entry->tv_u.tv_get_input_section_contents; break; case LDPT_UPDATE_SECTION_ORDER: update_section_order = *entry->tv_u.tv_update_section_order; @@ -76,6 +82,13 @@ onload(struct ld_plugin_tv *tv) case LDPT_ALLOW_SECTION_ORDERING: allow_section_ordering = *entry->tv_u.tv_allow_section_ordering; break; + case LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS: + allow_unique_segment_for_sections + = *entry->tv_u.tv_allow_unique_segment_for_sections; + case LDPT_UNIQUE_SEGMENT_FOR_SECTIONS: + unique_segment_for_sections + = *entry->tv_u.tv_unique_segment_for_sections; + break; default: break; } @@ -86,7 +99,9 @@ onload(struct ld_plugin_tv *tv) || get_input_section_name == NULL || get_input_section_contents == NULL || update_section_order == NULL - || allow_section_ordering == NULL) + || allow_section_ordering == NULL + || allow_unique_segment_for_sections == NULL + || unique_segment_for_sections == NULL) { fprintf(stderr, "Some interfaces are missing\n"); return LDPS_ERR; @@ -117,6 +132,9 @@ claim_file_hook(const struct ld_plugin_input_file *file, int *claimed) { /* Inform the linker to prepare for section reordering. */ (*allow_section_ordering)(); + /* Inform the linker to prepare to map some sections to unique + segments. */ + (*allow_unique_segment_for_sections)(); is_ordering_specified = 1; } @@ -160,8 +178,11 @@ enum ld_plugin_status all_symbols_read_hook(void) { if (num_entries == 3) - update_section_order(section_list, num_entries); + { + update_section_order(section_list, num_entries); + unique_segment_for_sections (".text.plugin_created_unique", 0, 0x1000, + section_list, num_entries); + } return LDPS_OK; } - |