2013-06-05 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 that Gold correctly aligns the symbols with large alignemnt. * testsuite/Makefile.in: Regenerate. * testsuite/large_symbol_alignment.cc: New file. diff --git a/gold/layout.cc b/gold/layout.cc index 65c3de6..818773a 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -3485,7 +3485,13 @@ 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); + { + // Here we are also taking care of the case when + // the maximum segment alignment is larger than the page size. + off = align_file_offset(off, addr, + std::max(abi_pagesize, + (*p)->maximum_alignment())); + } 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..e7f3b94 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -322,6 +322,11 @@ icf_sht_rel_addend_test: icf_sht_rel_addend_test_1.o icf_sht_rel_addend_test_2.o icf_sht_rel_addend_test.stdout: icf_sht_rel_addend_test $(TEST_NM) icf_sht_rel_addend_test > icf_sht_rel_addend_test.stdout +check_PROGRAMS += large_symbol_alignment +large_symbol_alignment_SOURCES = large_symbol_alignment.cc +large_symbol_alignment_DEPENDENCIES = gcctestdir/ld +large_symbol_alignment_LDFLAGS = -Bgcctestdir/ + check_SCRIPTS += merge_string_literals.sh check_DATA += merge_string_literals.stdout MOSTLYCLEANFILES += merge_string_literals diff --git a/gold/testsuite/large_symbol_alignment.cc b/gold/testsuite/large_symbol_alignment.cc new file mode 100644 index 0000000..1b4a63d --- /dev/null +++ b/gold/testsuite/large_symbol_alignment.cc @@ -0,0 +1,49 @@ +// 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). + +#include + +__attribute__ ((aligned(8192))) int aligned_8k_var; +__attribute__ ((aligned(4096))) int aligned_4k_var; +__attribute__ ((aligned(16384))) int aligned_16k_var; + +bool +is_aligned(const int& var, int align) __attribute__((noinline)); + +bool +is_aligned(const int& var, int align) +{ + return (reinterpret_cast(&var) & (align - 1)) == 0; +} + +int +main() +{ + if (!is_aligned(aligned_16k_var, 16384) + || !is_aligned(aligned_8k_var, 8192) + || !is_aligned(aligned_4k_var, 4096)) + return 1; + return 0; +} -- 1.7.11.7