diff --git a/gold/ChangeLog b/gold/ChangeLog index f0f0990..b465f09 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,13 @@ +2013-06-04 Alexander Ivchenko + + * layout.cc (Layout::set_segment_offsets): Taking care of the case when + the maximum segment alignment is larger than the page size. + * testsuite/Makefile.am (large_symbol_alignment): Test Gold correctly + aligns the symbols with large alignemnt. + * testsuite/Makefile.in: Regenerate. + * testsuite/large_symbol_alignment.c: New file. + * testsuite/large_symbol_alignment.sh: New file. + 2013-05-30 Alexander Ivchenko Sriraman Tallam diff --git a/gold/layout.cc b/gold/layout.cc index 65c3de6..f91b049 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -3485,7 +3485,14 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg, if (!parameters->options().nmagic() && !parameters->options().omagic()) - off = align_file_offset(off, addr, abi_pagesize); + { + // Taking care of the case when the maximum segment alignment + // is larger than the page size. + uint64_t align = ((*p)->maximum_alignment() < abi_pagesize + ? abi_pagesize + : (*p)->maximum_alignment()); + off = align_file_offset(off, addr, align); + } else { // This is -N or -n with a section script which prevents diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index bccf54d..2a19dee 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -283,6 +283,16 @@ section_sorting_name: section_sorting_name.o gcctestdir/ld section_sorting_name.stdout: section_sorting_name $(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout +check_SCRIPTS += large_symbol_alignment.sh +check_DATA += large_symbol_alignment.stdout +MOSTLYCLEANFILES += large_symbol_alignment +large_symbol_alignment.o: large_symbol_alignment.c + $(COMPILE) -O0 -c -g -o $@ $< +large_symbol_alignment: large_symbol_alignment.o gcctestdir/ld + $(LINK) -Bgcctestdir/ large_symbol_alignment.o +large_symbol_alignment.stdout: large_symbol_alignment + $(TEST_OBJDUMP) -t large_symbol_alignment > large_symbol_alignment.stdout + check_PROGRAMS += icf_virtual_function_folding_test MOSTLYCLEANFILES += icf_virtual_function_folding_test icf_virtual_function_folding_test.map icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index aa01015..b45c9fb 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -85,6 +85,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ large_symbol_alignment.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.sh \ @@ -121,6 +122,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ large_symbol_alignment.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.stdout \ @@ -143,6 +145,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ large_symbol_alignment \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test.map \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \ @@ -3762,6 +3765,8 @@ text_section_grouping.sh.log: text_section_grouping.sh @p='text_section_grouping.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) section_sorting_name.sh.log: section_sorting_name.sh @p='section_sorting_name.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +large_symbol_alignment.sh.log: large_symbol_alignment.sh + @p='large_symbol_alignment.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) icf_preemptible_functions_test.sh.log: icf_preemptible_functions_test.sh @p='icf_preemptible_functions_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) icf_string_merge_test.sh.log: icf_string_merge_test.sh @@ -4435,6 +4440,12 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--sort-section=name section_sorting_name.o @GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name.stdout: section_sorting_name @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment.o: large_symbol_alignment.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment: large_symbol_alignment.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ large_symbol_alignment.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment.stdout: large_symbol_alignment +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -t large_symbol_alignment > large_symbol_alignment.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld diff --git a/gold/testsuite/large_symbol_alignment.c b/gold/testsuite/large_symbol_alignment.c new file mode 100644 index 0000000..63523f6 --- /dev/null +++ b/gold/testsuite/large_symbol_alignment.c @@ -0,0 +1,35 @@ +// large_symbol_alignment.cc -- a test case for gold + +// Copyright 2013 Free Software Foundation, Inc. +// Written by Alexander Ivchenko . + +// This file is part of gold. + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +// MA 02110-1301, USA. + +// The goal of this program is to verify that Gold correctly aligns +// the symbol with a large alignemnt (often larger than the page size). + +__attribute__((aligned(16384)))int aligned_16k_var; +__attribute__((aligned(8192)))int aligned_8k_var; +__attribute__((aligned(4096)))int aligned_4k_var; + +int +main (int argc __attribute__ ((unused)), + char** argv __attribute__ ((unused))) +{ + return 0; +} diff --git a/gold/testsuite/large_symbol_alignment.sh b/gold/testsuite/large_symbol_alignment.sh new file mode 100755 index 0000000..3b68a97 --- /dev/null +++ b/gold/testsuite/large_symbol_alignment.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# large_symbol_alignment.sh -- test + +# Copyright 2013 Free Software Foundation, Inc. +# Written by Alexander Ivchenko . + +# This file is part of gold. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +# The goal of this program is to verify that Gold correctly aligns +# the symbol with a large alignemnt (often larger than the page size). + +check() +{ + address=`grep "$2" "$1" | cut -d' ' -f1` + if [ -z $address ] + then + echo "Couldn't find the address of the variable" + echo "or the variable itself in the object file" + exit 1 + fi + + remainder=$((16#$address % $3)) + if [ "$remainder" -ne "0" ] + then + echo "Variable $2 at $address must be aligned by $3" + exit 1 + fi +} + +check large_symbol_alignment.stdout aligned_16k_var 16384 +check large_symbol_alignment.stdout aligned_8k_var 8192 +check large_symbol_alignment.stdout aligned_4k_var 4096