From 2fd322316ec7699c44d24b1c465c80ada336754d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 28 Mar 2008 22:42:34 +0000 Subject: * layout.cc (Layout::layout): If we see an input section with a name that needs sorting, set the must_sort flag for the output section. (Layout::make_output_section): If the name of the output section indicates that it might require sorting, set the may_sort flag. * output.h (Output_section::may_sort_attached_input_sections): New function. (Output_section::set_may_sort_attached_input_sections): New function. (Output_section::must_sort_attached_input_sections): New function. (Output_section::set_must_sort_attached_input_sections): New function. (class Output_section): Declare Input_section_sort_entry. Define Input_section_sort_compare. Declare sort_attached_input_sections. Add new fields: may_sort_attached_input_sections_, must_sort_attached_input_sections_, attached_input_sections_are_sorted_. * output.cc (Output_section::Output_section): Initialize new fields. (Output_section::add_input_section): Add an entry to input_sections_ if may_sort or must_sort are true. (Output_section::set_final_data_size): Call sort_attached_input_sections if necessary. (Output_section::Input_section_sort_entry): Define new class. (Output_section::Input_section_sort_compare::operator()): New function. (Output_section::sort_attached_input_sections): New function. * configure.ac: Check whether the compiler supports constructor priorities. Define a CONSTRUCTOR_PRIORITY automake conditional. * testsuite/initpri1.c: New file. * testsuite/Makefile.am (check_PROGRAMS): Add initpri1 if CONSTRUCTOR_PRIORITY. (initpri1_SOURCES, initpri1_DEPENDENCIES): New variables. (initpri1_LDFLAGS): New variable. * configure, Makefile.in, testsuite/Makefile.in: Rebuild. --- gold/testsuite/initpri1.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 gold/testsuite/initpri1.c (limited to 'gold/testsuite/initpri1.c') diff --git a/gold/testsuite/initpri1.c b/gold/testsuite/initpri1.c new file mode 100644 index 0000000..4826389 --- /dev/null +++ b/gold/testsuite/initpri1.c @@ -0,0 +1,87 @@ +/* initpri1.c -- test constructor priorities. + + Copyright 2007, 2008 Free Software Foundation, Inc. + Copied from the gcc testsuite, where the test was contributed by + Mark Mitchell . + + 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. + + This is a test of a common symbol in the main program and a + versioned symbol in a shared library. The common symbol in the + main program should override the shared library symbol. */ + +#include + +int i; +int j; + +void c1() __attribute__((constructor (500))); +void c2() __attribute__((constructor (700))); +void c3() __attribute__((constructor (600))); + +void c1() { + if (i++ != 0) + abort (); +} + +void c2() { + if (i++ != 2) + abort (); +} + +void c3() { + if (i++ != 1) + abort (); +} + +void d1() __attribute__((destructor (500))); +void d2() __attribute__((destructor (700))); +void d3() __attribute__((destructor (600))); + +void d1() { + if (--i != 0) + abort (); +} + +void d2() { + if (--i != 2) + abort (); +} + +void d3() { + if (j != 2) + abort (); + if (--i != 1) + abort (); +} + +void cd4() __attribute__((constructor (800), destructor (800))); + +void cd4() { + if (i != 3) + abort (); + ++j; +} + +int main () { + if (i != 3) + return 1; + if (j != 1) + abort (); + return 0; +} -- cgit v1.1