[gold][patch] PR 10842: fix for gold crash with LTO and --gc-sections

Cary Coutant ccoutant@google.com
Wed Oct 28 00:15:00 GMT 2009


This patch fixes a gold crash when compiling in LTO with
--gc-sections. If the compiler inlines all occurrences of a function
and removes that function from the generated objects, gold crashes
with a SIGSEGV. The problem was that when the symbol was first added
as an absolute symbol (SHN_ABS), the "is_ordinary" flag was set,
causing gold to later attempt to use SHN_ABS as an actual index into
the section table.

OK?

-cary


	PR 10842
	* symtab.cc (add_from_pluginobj): Pass correct value for is_ordinary.
	* testsuite/Makefile.am (plugin_test_5): New test case.
	* testsuite/Makefile.in: Regenerate.
-------------- next part --------------
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.126
diff -u -p -r1.126 symtab.cc
--- symtab.cc	14 Oct 2009 05:25:02 -0000	1.126
+++ symtab.cc	28 Oct 2009 00:00:13 -0000
@@ -1202,6 +1202,7 @@ Symbol_table::add_from_pluginobj(
     elfcpp::Sym<size, big_endian>* sym)
 {
   unsigned int st_shndx = sym->get_st_shndx();
+  bool is_ordinary = st_shndx < elfcpp::SHN_LORESERVE;
 
   Stringpool::Key ver_key = 0;
   bool def = false;
@@ -1245,7 +1246,7 @@ Symbol_table::add_from_pluginobj(
 
   Sized_symbol<size>* res;
   res = this->add_from_object(obj, name, name_key, ver, ver_key,
-		              def, *sym, st_shndx, true, st_shndx);
+		              def, *sym, st_shndx, is_ordinary, st_shndx);
 
   if (local)
     this->force_local(res);
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.107
diff -u -p -r1.107 Makefile.am
--- testsuite/Makefile.am	14 Oct 2009 05:25:02 -0000	1.107
+++ testsuite/Makefile.am	28 Oct 2009 00:00:13 -0000
@@ -1102,6 +1102,10 @@ plugin_test_4.err: plugin_test_4
 plugin_test_4.a: two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms
 	$(TEST_AR) cr $@ $^
 
+check_PROGRAMS += plugin_test_5
+plugin_test_5: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms unused.syms gcctestdir/ld plugin_test.so
+	$(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv",--gc-sections two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms unused.syms 2>plugin_test_5.err
+
 plugin_test.so: plugin_test.o
 	$(LINK) -Bgcctestdir/ -shared plugin_test.o
 plugin_test.o: plugin_test.c
@@ -1115,9 +1119,19 @@ two_file_test_1b.syms: two_file_test_1b.
 	$(TEST_READELF) -sW $< >$@ 2>/dev/null
 two_file_test_2.syms: two_file_test_2.o
 	$(TEST_READELF) -sW $< >$@ 2>/dev/null
+
 empty.syms:
-	@echo "" >empty.syms
-	@echo "Symbol table" >>empty.syms
+	@echo "" >$@
+	@echo "Symbol table" >>$@
+
+MOSTLYCLEANFILES += unused.c
+unused.syms: unused.o
+	$(TEST_READELF) -sW $< >$@ 2>/dev/null
+	@echo "     1: 00000000     4 FUNC    GLOBAL DEFAULT    1 UNUSED" >>$@
+unused.o: unused.c
+	$(COMPILE) -c -o $@ $<
+unused.c:
+	@cp /dev/null $@
 
 endif PLUGINS
 


More information about the Binutils mailing list