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 COMMITTED: Let gold build with gcc 4.3.0


I committed this patch to let gold build with gcc 4.3.0.

There were two mildly interesting things.  First, gcc 4.3.0 found a
bug in gold using the array bounds check: x86_64.cc was using a 64-bit
swap where it should have been using a 32-bit swap.  Second, I had to
add a configure test for a bug in gcc 4.3.0, gcc bug 35546.

Ian


2008-03-26  Ian Lance Taylor  <iant@google.com>

	PR gold/5986
	Fix problems building gold with gcc 4.3.0.
	* gold.h (TEMPLATE_ATTRIBUTE_PRINTF_4): Define.
	(gold_error_at_location, gold_warning_at_location): Use it.
	* configure.ac: Check whether we can compile and use a template
	function with a printf attribute.
	* x86_64.cc (Target_x86_64::do_code_fill): Swap out a 32-bit value
	when jumping over bytes.
	* object.cc: Instantiate Object::read_section_data.
	* debug.h: Include <cstring>
	* dwarf_reader.cc: Include <algorithm>
	* main.cc: Include <cstring>.
	* options.cc: Include <cstring>.
	* output.cc: Include <cstring>.
	* script.cc: Include <cstring>.
	* script.h: Include <string>.
	* symtab.cc: Include <cstring> and <algorithm>.
	* target-select.cc: Include <cstring>.
	* version.cc: Include <string>.
	* testsuite/testmain.cc: Include <cstdlib>.
	* configure, config.in: Rebuild.


Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gold/configure.ac,v
retrieving revision 1.24
diff -p -u -r1.24 configure.ac
--- configure.ac	14 Mar 2008 05:57:19 -0000	1.24
+++ configure.ac	26 Mar 2008 23:27:43 -0000
@@ -244,6 +244,22 @@ AC_CHECK_HEADERS(tr1/unordered_set tr1/u
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_FUNCS(mallinfo)
 
+# gcc 4.3.0 doesn't recognize the printf attribute on a template
+# function.  Check for that.  This is gcc bug 35546.  This test can
+# probably be removed after the bug has been fixed for a while.
+AC_CACHE_CHECK([whether we can use attributes with template functions],
+[gold_cv_template_attribute],
+[AC_COMPILE_IFELSE([
+template<typename T> extern void foo(const char*, ...)
+  __attribute__ ((__format__ (__printf__, 1, 2)));
+template<typename T> void foo(const char* format, ...) {}
+void bar() { foo<int>("%s\n", "foo"); }
+], [gold_cv_template_attribute=yes], [gold_cv_template_attribute=no])])
+if test "$gold_cv_template_attribute" = "yes"; then
+  AC_DEFINE(HAVE_TEMPLATE_ATTRIBUTES, 1,
+	    [Define if attributes work on C++ templates])
+fi
+
 AC_LANG_POP(C++)
 
 AM_MAINTAINER_MODE
Index: debug.h
===================================================================
RCS file: /cvs/src/src/gold/debug.h,v
retrieving revision 1.5
diff -p -u -r1.5 debug.h
--- debug.h	13 Mar 2008 21:04:21 -0000	1.5
+++ debug.h	26 Mar 2008 23:27:43 -0000
@@ -23,6 +23,8 @@
 #ifndef GOLD_DEBUG_H
 #define GOLD_DEBUG_H
 
+#include <cstring>
+
 #include "parameters.h"
 #include "errors.h"
 
Index: dwarf_reader.cc
===================================================================
RCS file: /cvs/src/src/gold/dwarf_reader.cc,v
retrieving revision 1.17
diff -p -u -r1.17 dwarf_reader.cc
--- dwarf_reader.cc	13 Mar 2008 21:04:21 -0000	1.17
+++ dwarf_reader.cc	26 Mar 2008 23:27:43 -0000
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <algorithm>
+
 #include "elfcpp_swap.h"
 #include "dwarf.h"
 #include "object.h"
Index: gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.24
diff -p -u -r1.24 gold.h
--- gold.h	22 Mar 2008 18:51:35 -0000	1.24
+++ gold.h	26 Mar 2008 23:27:43 -0000
@@ -157,13 +157,21 @@ gold_error(const char* msg, ...) ATTRIBU
 extern void
 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
 
+// Work around a bug in gcc 4.3.0.  http://gcc.gnu.org/PR35546 .  This
+// can probably be removed after the bug has been fixed for a while.
+#ifdef HAVE_TEMPLATE_ATTRIBUTES
+#define TEMPLATE_ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF_4
+#else
+#define TEMPLATE_ATTRIBUTE_PRINTF_4
+#endif
+
 // This function is called to issue an error at the location of a
 // reloc.
 template<int size, bool big_endian>
 extern void
 gold_error_at_location(const Relocate_info<size, big_endian>*,
 		       size_t, off_t, const char* format, ...)
-  ATTRIBUTE_PRINTF_4;
+  TEMPLATE_ATTRIBUTE_PRINTF_4;
 
 // This function is called to issue a warning at the location of a
 // reloc.
@@ -171,7 +179,7 @@ template<int size, bool big_endian>
 extern void
 gold_warning_at_location(const Relocate_info<size, big_endian>*,
 			 size_t, off_t, const char* format, ...)
-  ATTRIBUTE_PRINTF_4;
+  TEMPLATE_ATTRIBUTE_PRINTF_4;
 
 // This function is called to report an undefined symbol.
 template<int size, bool big_endian>
Index: main.cc
===================================================================
RCS file: /cvs/src/src/gold/main.cc,v
retrieving revision 1.21
diff -p -u -r1.21 main.cc
--- main.cc	4 Mar 2008 23:10:38 -0000	1.21
+++ main.cc	26 Mar 2008 23:27:43 -0000
@@ -22,9 +22,12 @@
 
 #include "gold.h"
 
+#include <cstring>
+
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif
+
 #include "libiberty.h"
 
 #include "script.h"
Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.64
diff -p -u -r1.64 object.cc
--- object.cc	24 Mar 2008 03:48:29 -0000	1.64
+++ object.cc	26 Mar 2008 23:27:43 -0000
@@ -1546,8 +1546,35 @@ make_elf_object(const std::string& name,
     }
 }
 
-// Instantiate the templates we need.  We could use the configure
-// script to restrict this to only the ones for implemented targets.
+// Instantiate the templates we need.
+
+#ifdef HAVE_TARGET_32_LITTLE
+template
+void
+Object::read_section_data<32, false>(elfcpp::Elf_file<32, false, Object>*,
+				     Read_symbols_data*);
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+template
+void
+Object::read_section_data<32, true>(elfcpp::Elf_file<32, true, Object>*,
+				    Read_symbols_data*);
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+template
+void
+Object::read_section_data<64, false>(elfcpp::Elf_file<64, false, Object>*,
+				     Read_symbols_data*);
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+template
+void
+Object::read_section_data<64, true>(elfcpp::Elf_file<64, true, Object>*,
+				    Read_symbols_data*);
+#endif
 
 #ifdef HAVE_TARGET_32_LITTLE
 template
Index: options.cc
===================================================================
RCS file: /cvs/src/src/gold/options.cc,v
retrieving revision 1.66
diff -p -u -r1.66 options.cc
--- options.cc	25 Mar 2008 23:48:25 -0000	1.66
+++ options.cc	26 Mar 2008 23:27:43 -0000
@@ -23,6 +23,7 @@
 #include "gold.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <vector>
 #include <iostream>
 #include <sys/stat.h>
Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.65
diff -p -u -r1.65 output.cc
--- output.cc	25 Mar 2008 18:37:16 -0000	1.65
+++ output.cc	26 Mar 2008 23:27:43 -0000
@@ -23,6 +23,7 @@
 #include "gold.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <cerrno>
 #include <fcntl.h>
 #include <unistd.h>
Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.41
diff -p -u -r1.41 script.cc
--- script.cc	4 Mar 2008 23:10:38 -0000	1.41
+++ script.cc	26 Mar 2008 23:27:43 -0000
@@ -22,11 +22,12 @@
 
 #include "gold.h"
 
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 #include <fnmatch.h>
 #include <string>
 #include <vector>
-#include <cstdio>
-#include <cstdlib>
 #include "filenames.h"
 
 #include "elfcpp.h"
Index: script.h
===================================================================
RCS file: /cvs/src/src/gold/script.h,v
retrieving revision 1.17
diff -p -u -r1.17 script.h
--- script.h	29 Feb 2008 00:04:06 -0000	1.17
+++ script.h	26 Mar 2008 23:27:43 -0000
@@ -31,6 +31,7 @@
 #define GOLD_SCRIPT_H
 
 #include <cstdio>
+#include <string>
 #include <vector>
 
 #include "script-sections.h"
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.82
diff -p -u -r1.82 symtab.cc
--- symtab.cc	25 Mar 2008 18:37:16 -0000	1.82
+++ symtab.cc	26 Mar 2008 23:27:43 -0000
@@ -22,7 +22,9 @@
 
 #include "gold.h"
 
+#include <cstring>
 #include <stdint.h>
+#include <algorithm>
 #include <set>
 #include <string>
 #include <utility>
Index: target-select.cc
===================================================================
RCS file: /cvs/src/src/gold/target-select.cc,v
retrieving revision 1.7
diff -p -u -r1.7 target-select.cc
--- target-select.cc	25 Mar 2008 21:39:01 -0000	1.7
+++ target-select.cc	26 Mar 2008 23:27:43 -0000
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <cstring>
+
 #include "elfcpp.h"
 #include "target-select.h"
 
Index: version.cc
===================================================================
RCS file: /cvs/src/src/gold/version.cc,v
retrieving revision 1.10
diff -p -u -r1.10 version.cc
--- version.cc	25 Mar 2008 23:30:48 -0000	1.10
+++ version.cc	26 Mar 2008 23:27:43 -0000
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <string>
+
 #include "../bfd/bfdver.h"
 
 namespace gold
Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.57
diff -p -u -r1.57 x86_64.cc
--- x86_64.cc	25 Mar 2008 21:39:01 -0000	1.57
+++ x86_64.cc	26 Mar 2008 23:27:43 -0000
@@ -2161,7 +2161,7 @@ Target_x86_64::do_code_fill(section_size
       // Build a jmpq instruction to skip over the bytes.
       unsigned char jmp[5];
       jmp[0] = 0xe9;
-      elfcpp::Swap_unaligned<64, false>::writeval(jmp + 1, length - 5);
+      elfcpp::Swap_unaligned<32, false>::writeval(jmp + 1, length - 5);
       return (std::string(reinterpret_cast<char*>(&jmp[0]), 5)
               + std::string(length - 5, '\0'));
     }
Index: testsuite/testmain.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/testmain.cc,v
retrieving revision 1.3
diff -p -u -r1.3 testmain.cc
--- testsuite/testmain.cc	13 Mar 2008 21:04:21 -0000	1.3
+++ testsuite/testmain.cc	26 Mar 2008 23:27:43 -0000
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <cstdlib>
+
 #include "test.h"
 
 using namespace gold_testsuite;

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