From: Sriraman Tallam Date: Fri, 22 May 2009 18:31:22 +0000 (+0000) Subject: * object.cc (Sized_relobj::map_to_kept_section): Return NULL if the X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=531813adfc6b4fd3d27183f8be16e755e8fc003d;p=binutils-gdb.git * object.cc (Sized_relobj::map_to_kept_section): Return NULL if the kept comdat section was garbage collected. * testsuite/Makefile.am: Add test gc_comdat_test.sh. * testsuite/Makefile.in: Regenerate. * testsuite/gc_comdat_test.sh: New file. * testsuite/gc_comdat_test_1.cc: New file. * testsuite/gc_comdat_test_2.cc: New file. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index e06c35f622e..a56d2e9d0c8 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,13 @@ +2009-05-21 Sriraman Tallam + + * object.cc (Sized_relobj::map_to_kept_section): Return NULL if the + kept comdat section was garbage collected. + * testsuite/Makefile.am: Add test gc_comdat_test.sh. + * testsuite/Makefile.in: Regenerate. + * testsuite/gc_comdat_test.sh: New file. + * testsuite/gc_comdat_test_1.cc: New file. + * testsuite/gc_comdat_test_2.cc: New file. + 2009-05-19 Doug Kwan * archive.cc (Archive::Archive): Move constructor from archive.h diff --git a/gold/object.cc b/gold/object.cc index 9e61831e199..75fb67970ea 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -1873,8 +1873,8 @@ Sized_relobj::map_to_kept_section( *found = true; Output_section* os = kept->object_->output_section(kept->shndx_); Address offset = kept->object_->get_output_section_offset(kept->shndx_); - gold_assert(os != NULL && offset != invalid_address); - return os->address() + offset; + if (os != NULL && offset != invalid_address) + return os->address() + offset; } *found = false; return 0; diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 80298ce0e81..766807353e6 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -23,6 +23,7 @@ TEST_OBJDUMP = $(top_builddir)/../binutils/objdump TEST_CXXFILT = $(top_builddir)/../binutils/cxxfilt TEST_STRIP = $(top_builddir)/../binutils/strip-new TEST_AR = $(top_builddir)/../binutils/ar +TEST_NM = $(top_builddir)/../binutils/nm-new if PLUGINS LIBDL = -ldl @@ -103,6 +104,18 @@ flagstest_ndebug.o: constructor_test.cc $(CXXCOMPILE) -O0 -c -o $@ $< +check_SCRIPTS += gc_comdat_test.sh +check_DATA += gc_comdat_test.stdout +gc_comdat_test_1.o: gc_comdat_test_1.cc + $(CXXCOMPILE) -O0 -c -g -o $@ $< +gc_comdat_test_2.o: gc_comdat_test_2.cc + $(CXXCOMPILE) -O0 -c -g -o $@ $< +gc_comdat_test: gc_comdat_test_1.o gc_comdat_test_2.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ --gc-sections gc_comdat_test_1.o gc_comdat_test_2.o +gc_comdat_test.stdout: gc_comdat_test + $(TEST_NM) -C gc_comdat_test > gc_comdat_test.stdout + + check_PROGRAMS += basic_test check_PROGRAMS += basic_static_test check_PROGRAMS += basic_pic_test diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 40ee958a26f..77ebf90adcd 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -49,7 +49,45 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ $(am__EXEEXT_10) $(am__EXEEXT_11) $(am__EXEEXT_12) \ $(am__EXEEXT_13) $(am__EXEEXT_14) $(am__EXEEXT_15) \ $(am__EXEEXT_16) $(am__EXEEXT_17) -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = basic_test \ + +# Test --detect-odr-violations + +# Similar to --detect-odr-violations: check for undefined symbols in .so's + +# Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new, +# and --dynamic-list-cpp-typeinfo +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = gc_comdat_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.sh weak_plt.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg.sh undef_symbol.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_1.sh ver_test_2.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_4.sh ver_test_5.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_7.sh ver_test_10.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.sh dynamic_list.sh + +# Create the data files that debug_msg.sh analyzes. + +# See if we can also detect problems when we're linking .so's, not .o's. + +# We also want to make sure we do something reasonable when there's no +# debug info available. For the best test, we use .so's. +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = gc_comdat_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_plt_shared.so debug_msg.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_so.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_ndebug.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ undef_symbol.err ver_test_1.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_2.syms ver_test_4.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_5.syms ver_test_7.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_3 = basic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_test basic_pic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_pic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test \ @@ -102,43 +140,6 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1) \ @NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1) -# Test --detect-odr-violations - -# Similar to --detect-odr-violations: check for undefined symbols in .so's - -# Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new, -# and --dynamic-list-cpp-typeinfo -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = two_file_shared.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_plt.sh debug_msg.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ undef_symbol.sh ver_test_1.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_2.sh ver_test_4.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_5.sh ver_test_7.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.sh dynamic_list.sh - -# Create the data files that debug_msg.sh analyzes. - -# See if we can also detect problems when we're linking .so's, not .o's. - -# We also want to make sure we do something reasonable when there's no -# debug info available. For the best test, we use .so's. -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_3 = two_file_shared.dbg \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_plt_shared.so debug_msg.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_so.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_ndebug.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ undef_symbol.err ver_test_1.syms \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_2.syms ver_test_4.syms \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_5.syms ver_test_7.syms \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout - # The nonpic tests will fail on platforms which can not put non-PIC # code into shared libraries, so we just don't run them in that case. @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_4 = two_file_shared_1_nonpic_test \ @@ -1166,6 +1167,7 @@ TEST_OBJDUMP = $(top_builddir)/../binutils/objdump TEST_CXXFILT = $(top_builddir)/../binutils/cxxfilt TEST_STRIP = $(top_builddir)/../binutils/strip-new TEST_AR = $(top_builddir)/../binutils/ar +TEST_NM = $(top_builddir)/../binutils/nm-new @PLUGINS_TRUE@LIBDL = -ldl @THREADS_TRUE@THREADSLIB = -lpthread @OMP_SUPPORT_TRUE@TLS_TEST_C_CFLAGS = -fopenmp @@ -1180,8 +1182,8 @@ MOSTLYCLEANFILES = *.so $(am__append_16) $(am__append_23) \ # We will add to these later, for each individual test. Note # that we add each test under check_SCRIPTS or check_PROGRAMS; # the TESTS variable is automatically populated from these. -check_SCRIPTS = $(am__append_2) $(am__append_21) $(am__append_25) -check_DATA = $(am__append_3) $(am__append_22) $(am__append_26) +check_SCRIPTS = $(am__append_1) $(am__append_21) $(am__append_25) +check_DATA = $(am__append_2) $(am__append_22) $(am__append_26) BUILT_SOURCES = $(am__append_14) TESTS = $(check_SCRIPTS) $(check_PROGRAMS) @@ -1530,9 +1532,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu testsuite/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign testsuite/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu testsuite/Makefile + $(AUTOMAKE) --foreign testsuite/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -2223,6 +2225,14 @@ uninstall-am: uninstall-info-am @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -g -c -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@flagstest_ndebug.o: constructor_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@gc_comdat_test_1.o: gc_comdat_test_1.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@gc_comdat_test_2.o: gc_comdat_test_2.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -g -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@gc_comdat_test: gc_comdat_test_1.o gc_comdat_test_2.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ --gc-sections gc_comdat_test_1.o gc_comdat_test_2.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@gc_comdat_test.stdout: gc_comdat_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -C gc_comdat_test > gc_comdat_test.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test.o: basic_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test: basic_test.o gcctestdir/ld diff --git a/gold/testsuite/gc_comdat_test.sh b/gold/testsuite/gc_comdat_test.sh new file mode 100755 index 00000000000..875d6d73879 --- /dev/null +++ b/gold/testsuite/gc_comdat_test.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# gc_comdat_test.sh -- test --gc-sections + +# Copyright 2009 Free Software Foundation, Inc. +# Written by Sriraman Tallam . + +# 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 if comdat's and garbage +# collection work together. Files gc_comdat_test_1.cc and +# gc_comdat_test_2.cc are used in this test. This program checks +# if the kept comdat section is garbage collected. + +check() +{ + if ! grep -q "$2" "$1" + then + echo "Garbage collection failed to collect :" + echo " $2" + exit 1 + fi +} + +check gc_comdat_test.stdout "foo()" +check gc_comdat_test.stdout "bar()" +check gc_comdat_test.stdout "int GetMax(int, int)" diff --git a/gold/testsuite/gc_comdat_test_1.cc b/gold/testsuite/gc_comdat_test_1.cc new file mode 100644 index 00000000000..0b4b286d51f --- /dev/null +++ b/gold/testsuite/gc_comdat_test_1.cc @@ -0,0 +1,42 @@ +// gc_comdat_test_1.cc -- a test case for gold + +// Copyright 2009 Free Software Foundation, Inc. +// Written by Sriraman Tallam . + +// 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 if comdat's and garbage +// collection work together. This file is compiled with -g. The +// comdat kept function for GetMax is garbage. + +int foo(); +template +T GetMax (T a, T b) +{ + return (a > b)?a:b; +} + +int bar () +{ + return GetMax (4,5); +} + +int main() +{ + return 0; +} diff --git a/gold/testsuite/gc_comdat_test_2.cc b/gold/testsuite/gc_comdat_test_2.cc new file mode 100644 index 00000000000..5841bdf0688 --- /dev/null +++ b/gold/testsuite/gc_comdat_test_2.cc @@ -0,0 +1,35 @@ +// gc_comdat_test_2.cc -- a test case for gold + +// Copyright 2009 Free Software Foundation, Inc. +// Written by Sriraman Tallam . + +// 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 if comdat's and garbage +// collection work together. This file is compiled with -g. + +template +T GetMax (T a, T b) +{ + return (a > b)?a:b; +} + +int foo () +{ + return GetMax (10,11); +}