This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix internal error on unterminated --start-lib option.


This fixes the internal error from the following errant comand line:
$ ld.gold --start-lib
ld.gold: internal error in set_thread_count, at ../../gold/workqueue.cc:110

The problem is that while the command line isn't trivially empty, it contains no
input files. As gold tries to configure the number of threads to use based on
the number of input files, this causes the assertion failure above. Fix this
problem by making the logic in gold.cc more robust and also adding a better
error message about --start-lib to options.cc.

	* Makefile.in: Regenerate.
	* gold.cc (queue_initial_tasks) Check for number of real input files.
	* options.cc (Command_line::process) Check for unterminated --start-lib
	options.
	* testsuite/Makefile.am: Add new test script.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/check_empty_command_lines.sh: New test script.
---
 gold/Makefile.in                          |  4 +--
 gold/gold.cc                              |  2 +-
 gold/options.cc                           |  6 +++++
 gold/testsuite/Makefile.am                |  4 +++
 gold/testsuite/Makefile.in                | 27 ++++++++++++-------
 gold/testsuite/empty_command_line_test.sh | 43 +++++++++++++++++++++++++++++++
 6 files changed, 73 insertions(+), 13 deletions(-)
 create mode 100755 gold/testsuite/empty_command_line_test.sh

diff --git a/gold/Makefile.in b/gold/Makefile.in
index 9a51247020..468f28a850 100644
--- a/gold/Makefile.in
+++ b/gold/Makefile.in
@@ -87,8 +87,8 @@ subdir = .
 DIST_COMMON = NEWS README ChangeLog $(srcdir)/Makefile.in \
 	$(srcdir)/Makefile.am $(top_srcdir)/configure \
 	$(am__configure_deps) $(srcdir)/config.in \
-	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in pread.c \
-	ffsll.c mremap.c ftruncate.c yyscript.h yyscript.c \
+	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in \
+	ftruncate.c pread.c mremap.c ffsll.c yyscript.h yyscript.c \
 	$(srcdir)/../depcomp $(srcdir)/../ylwrap
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
diff --git a/gold/gold.cc b/gold/gold.cc
index a76d155f94..3916f892c9 100644
--- a/gold/gold.cc
+++ b/gold/gold.cc
@@ -175,7 +175,7 @@ queue_initial_tasks(const General_options& options,
 		    Workqueue* workqueue, Input_objects* input_objects,
 		    Symbol_table* symtab, Layout* layout, Mapfile* mapfile)
 {
-  if (cmdline.begin() == cmdline.end())
+  if (cmdline.number_of_input_files() == 0)
     {
       bool is_ok = false;
       if (options.printed_version())
diff --git a/gold/options.cc b/gold/options.cc
index ed63b6f04f..f54fb9b1cb 100644
--- a/gold/options.cc
+++ b/gold/options.cc
@@ -1569,6 +1569,12 @@ Command_line::process(int argc, const char** argv)
       usage();
     }
 
+  if (this->inputs_.in_lib())
+    {
+      fprintf(stderr, _("%s: missing lib end\n"), program_name);
+      usage();
+    }
+
   // Normalize the options and ensure they don't contradict each other.
   this->options_.finalize();
 }
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index b9d9c8ce92..23b0ff1804 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -157,6 +157,10 @@ endif NATIVE_OR_CROSS_LINKER
 if NATIVE_LINKER
 if GCC
 
+# Test empty command line error conditions.
+check_SCRIPTS += empty_command_line_test.sh
+empty_command_line_test.sh: gcctestdir/ld
+
 # Each of these .o's is a useful, small complete program.  They're
 # particularly useful for making sure ld-new's flags do what they're
 # supposed to (hence their names), but are used for many tests that
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 8e71ba71fe..c34c878a96 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -74,7 +74,20 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @NATIVE_OR_CROSS_LINKER_TRUE@am__append_1 = object_unittest \
 @NATIVE_OR_CROSS_LINKER_TRUE@	binary_unittest leb128_unittest \
 @NATIVE_OR_CROSS_LINKER_TRUE@	overflow_unittest
-@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = incremental_test.sh \
+
+# ---------------------------------------------------------------------
+# These tests test the output of gold (end-to-end tests).  In
+# particular, they make sure that gold can link "difficult" object
+# files, and the resulting object files run correctly.  These can only
+# run if we've built ld-new for the native architecture (that is,
+# we're not cross-compiling it), since we run ld-new as part of these
+# tests.  We use the gcc-specific flag '-B' to use our linker instead
+# of the default linker, which is why we only run our tests under gcc.
+
+# Test empty command line error conditions.
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 =  \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	empty_command_line_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	incremental_test.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	gc_comdat_test.sh gc_tls_test.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	gc_orphan_section_test.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	pr14265.sh pr20717.sh \
@@ -5085,6 +5098,8 @@ check-html recheck-html:
 	rv=0; $(MAKE) $(AM_MAKEFLAGS) $$target || rv=$$?; \
 	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML) TEST_LOGS= || exit 4; \
 	exit $$rv
+empty_command_line_test.sh.log: empty_command_line_test.sh
+	@p='empty_command_line_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 incremental_test.sh.log: incremental_test.sh
 	@p='incremental_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 gc_comdat_test.sh.log: gc_comdat_test.sh
@@ -5842,15 +5857,7 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@	(cd gcctestdir && $(LN_S) $(abs_top_builddir)/../gas/as-new as)
 @NATIVE_OR_CROSS_LINKER_TRUE@overflow_unittest.o: overflow_unittest.cc
 @NATIVE_OR_CROSS_LINKER_TRUE@	$(CXXCOMPILE) -O3 -c -o $@ $<
-
-# ---------------------------------------------------------------------
-# These tests test the output of gold (end-to-end tests).  In
-# particular, they make sure that gold can link "difficult" object
-# files, and the resulting object files run correctly.  These can only
-# run if we've built ld-new for the native architecture (that is,
-# we're not cross-compiling it), since we run ld-new as part of these
-# tests.  We use the gcc-specific flag '-B' to use our linker instead
-# of the default linker, which is why we only run our tests under gcc.
+@GCC_TRUE@@NATIVE_LINKER_TRUE@empty_command_line_test.sh: gcctestdir/ld
 
 # Each of these .o's is a useful, small complete program.  They're
 # particularly useful for making sure ld-new's flags do what they're
diff --git a/gold/testsuite/empty_command_line_test.sh b/gold/testsuite/empty_command_line_test.sh
new file mode 100755
index 0000000000..ab6a0d847c
--- /dev/null
+++ b/gold/testsuite/empty_command_line_test.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# empty_command_line_test.sh -- test various command lines with no inputs
+
+# Copyright (C) 2017 Free Software Foundation, Inc.
+# Written by Benjamin Peterson <bp@benjamin.pe>
+
+# 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.
+
+check()
+{
+    expected_msg="$1"
+    shift
+    echo "checking empty command line '$@'"
+    err=$(gcctestdir/ld "$@" 2>&1)
+    if [ $? != 1 ]; then
+        echo "gold didn't fail"
+        exit 1
+    fi
+    echo "$err" | grep -q "$expected_msg" || {
+        echo "unexpected error message: $err"
+        exit 1
+    }
+}
+
+check "no input files"
+check "missing lib end" --start-lib
+check "missing group end" --start-group
-- 
2.11.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]