Fix problem where absolute local symbols are omitted when output has many sections. 2016-12-05 Cary Coutant Tristan Gingold gold/ * object.cc (Sized_relobj_file::do_count_local_symbols): Check is_ordinary before using shndx. * testsuite/Makefile.am (file_in_many_sections_test.sh): New test case. * testsuite/Makefile.in: Regenerate. * testsuite/file_in_many_sections.c: New source file. * testsuite/file_in_many_sections_test.sh: New script. diff --git a/gold/object.cc b/gold/object.cc index a631c99..72afc45 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -2225,8 +2225,9 @@ Sized_relobj_file::do_count_local_symbols(Stringpool* pool, // Decide whether this symbol should go into the output file. - if ((shndx < shnum && out_sections[shndx] == NULL) - || shndx == this->discarded_eh_frame_shndx_) + if (is_ordinary + && ((shndx < shnum && out_sections[shndx] == NULL) + || shndx == this->discarded_eh_frame_shndx_)) { lv.set_no_output_symtab_entry(); gold_assert(!lv.needs_output_dynsym_entry()); diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 1575aa3..17f45d6 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1339,6 +1339,16 @@ many_sections_r_test.o: many_sections_test.o gcctestdir/ld many_sections_r_test: many_sections_r_test.o gcctestdir/ld $(CXXLINK) -Bgcctestdir/ many_sections_r_test.o $(LIBS) +check_SCRIPTS += file_in_many_sections_test.sh +check_DATA += file_in_many_sections.stdout +MOSTLYCLEANFILES += file_in_many_sections +file_in_many_sections.o: file_in_many_sections.c many_sections_define.h + $(COMPILE) -c -fdata-sections -o $@ $(srcdir)/file_in_many_sections.c +file_in_many_sections: file_in_many_sections.o gcctestdir/ld + $(LINK) -Bgcctestdir/ file_in_many_sections.o -Wl,--gc-sections +file_in_many_sections.stdout: file_in_many_sections + $(TEST_READELF) -s $< > $@ + check_PROGRAMS += initpri1 initpri1_SOURCES = initpri1.c initpri1_DEPENDENCIES = gcctestdir/ld diff --git a/gold/testsuite/file_in_many_sections.c b/gold/testsuite/file_in_many_sections.c new file mode 100644 index 0000000..64146cf --- /dev/null +++ b/gold/testsuite/file_in_many_sections.c @@ -0,0 +1,34 @@ +// file_in_many_sections.c -- test STT_FILE when more than 64k sections + +// Copyright (C) 2016 Free Software Foundation, Inc. +// Written by Tristan Gingold + +// 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 program tests having many sections. It uses a generated .h +// files to define 70,000 variables, each in a different section. It +// uses another generated .h file to verify that they all have the +// right value. + +#include "many_sections_define.h" + +int +main (void) +{ + return 0; +} diff --git a/gold/testsuite/file_in_many_sections_test.sh b/gold/testsuite/file_in_many_sections_test.sh new file mode 100644 index 0000000..453bc67 --- /dev/null +++ b/gold/testsuite/file_in_many_sections_test.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# file_in_many_sections.sh -- test + +# Copyright (C) 2016 Free Software Foundation, Inc. +# Written by Tristan Gingold + +# 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 .text sections are grouped +# according to prefix. .text.unlikely, .text.startup and .text.hot should +# be grouped and placed together. + +set -e + +grep file_in_many_sections.c file_in_many_sections.stdout