PR gold/5986
authorIan Lance Taylor <ian@airs.com>
Wed, 26 Mar 2008 23:36:46 +0000 (23:36 +0000)
committerIan Lance Taylor <ian@airs.com>
Wed, 26 Mar 2008 23:36:46 +0000 (23:36 +0000)
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.

18 files changed:
gold/ChangeLog
gold/config.in
gold/configure
gold/configure.ac
gold/debug.h
gold/dwarf_reader.cc
gold/gold.h
gold/main.cc
gold/object.cc
gold/options.cc
gold/output.cc
gold/script.cc
gold/script.h
gold/symtab.cc
gold/target-select.cc
gold/testsuite/testmain.cc
gold/version.cc
gold/x86_64.cc

index 5a98a07..0e207ac 100644 (file)
@@ -1,3 +1,27 @@
+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.
+
 2008-03-25  Ian Lance Taylor  <iant@google.com>
 
        * options.cc: Include "../bfd/bfdver.h".
index 81da6aa..4f544fc 100644 (file)
@@ -64,6 +64,9 @@
 /* Define to support 64-bit little-endian targets */
 #undef HAVE_TARGET_64_LITTLE
 
+/* Define if attributes work on C++ templates */
+#undef HAVE_TEMPLATE_ATTRIBUTES
+
 /* Define to 1 if you have the <tr1/unordered_map> header file. */
 #undef HAVE_TR1_UNORDERED_MAP
 
index 45e84d9..01cdf16 100755 (executable)
@@ -4666,6 +4666,16 @@ echo "$as_me: error: bad value ${enableval} for --enable-werror" >&2;}
    esac
 fi;
 
+# Enable -Wno-format by default when using gcc on mingw
+case "${host}" in
+  *-*-mingw32*)
+    if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
+      GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
+    fi
+    ;;
+  *) ;;
+esac
+
 # Enable -Werror by default when using gcc
 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
     ERROR_ON_WARNING=yes
@@ -6233,6 +6243,63 @@ fi
 done
 
 
+# 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.
+echo "$as_me:$LINENO: checking whether we can use attributes with template functions" >&5
+echo $ECHO_N "checking whether we can use attributes with template functions... $ECHO_C" >&6
+if test "${gold_cv_template_attribute+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+
+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"); }
+
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_cxx_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  gold_cv_template_attribute=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+gold_cv_template_attribute=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $gold_cv_template_attribute" >&5
+echo "${ECHO_T}$gold_cv_template_attribute" >&6
+if test "$gold_cv_template_attribute" = "yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_TEMPLATE_ATTRIBUTES 1
+_ACEOF
+
+fi
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
index e930fd6..d9d965e 100644 (file)
@@ -244,6 +244,22 @@ AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 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 9bc9c85..8428dc8 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef GOLD_DEBUG_H
 #define GOLD_DEBUG_H
 
+#include <cstring>
+
 #include "parameters.h"
 #include "errors.h"
 
index f2ae53a..7ce6c7e 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <algorithm>
+
 #include "elfcpp_swap.h"
 #include "dwarf.h"
 #include "object.h"
index b34e032..1b1a84c 100644 (file)
@@ -157,13 +157,21 @@ gold_error(const char* msg, ...) ATTRIBUTE_PRINTF_1;
 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 e4f9003..2966d03 100644 (file)
 
 #include "gold.h"
 
+#include <cstring>
+
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif
+
 #include "libiberty.h"
 
 #include "script.h"
index 6c81f23..378238d 100644 (file)
@@ -1546,8 +1546,35 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset,
     }
 }
 
-// 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 58ac9cf..b6e4711 100644 (file)
@@ -23,6 +23,7 @@
 #include "gold.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <vector>
 #include <iostream>
 #include <sys/stat.h>
index 3a11aa4..d4fc2a7 100644 (file)
@@ -23,6 +23,7 @@
 #include "gold.h"
 
 #include <cstdlib>
+#include <cstring>
 #include <cerrno>
 #include <fcntl.h>
 #include <unistd.h>
index b8ecf9d..a808b2e 100644 (file)
 
 #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 26abd46..af0f53c 100644 (file)
@@ -31,6 +31,7 @@
 #define GOLD_SCRIPT_H
 
 #include <cstdio>
+#include <string>
 #include <vector>
 
 #include "script-sections.h"
index 3bd3833..5ad5ae8 100644 (file)
@@ -22,7 +22,9 @@
 
 #include "gold.h"
 
+#include <cstring>
 #include <stdint.h>
+#include <algorithm>
 #include <set>
 #include <string>
 #include <utility>
index 092a1df..b81f5a2 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <cstring>
+
 #include "elfcpp.h"
 #include "target-select.h"
 
index 47c59b6..ac99000 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <cstdlib>
+
 #include "test.h"
 
 using namespace gold_testsuite;
index 9e3ec28..4b034b9 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <string>
+
 #include "../bfd/bfdver.h"
 
 namespace gold
index 26f7348..973787f 100644 (file)
@@ -2161,7 +2161,7 @@ Target_x86_64::do_code_fill(section_size_type length) const
       // 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'));
     }