From 04bf70729db030f7f0a4ec74699d1f052d13b06c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 26 Mar 2008 23:36:46 +0000 Subject: [PATCH] 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 * dwarf_reader.cc: Include * main.cc: Include . * options.cc: Include . * output.cc: Include . * script.cc: Include . * script.h: Include . * symtab.cc: Include and . * target-select.cc: Include . * version.cc: Include . * testsuite/testmain.cc: Include . * configure, config.in: Rebuild. --- gold/ChangeLog | 24 ++++++++++++++ gold/config.in | 3 ++ gold/configure | 67 ++++++++++++++++++++++++++++++++++++++ gold/configure.ac | 16 +++++++++ gold/debug.h | 2 ++ gold/dwarf_reader.cc | 2 ++ gold/gold.h | 12 +++++-- gold/main.cc | 3 ++ gold/object.cc | 31 ++++++++++++++++-- gold/options.cc | 1 + gold/output.cc | 1 + gold/script.cc | 5 +-- gold/script.h | 1 + gold/symtab.cc | 2 ++ gold/target-select.cc | 2 ++ gold/testsuite/testmain.cc | 2 ++ gold/version.cc | 2 ++ gold/x86_64.cc | 2 +- 18 files changed, 171 insertions(+), 7 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index 5a98a0784eb..0e207acaaea 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,27 @@ +2008-03-26 Ian Lance Taylor + + 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 + * dwarf_reader.cc: Include + * main.cc: Include . + * options.cc: Include . + * output.cc: Include . + * script.cc: Include . + * script.h: Include . + * symtab.cc: Include and . + * target-select.cc: Include . + * version.cc: Include . + * testsuite/testmain.cc: Include . + * configure, config.in: Rebuild. + 2008-03-25 Ian Lance Taylor * options.cc: Include "../bfd/bfdver.h". diff --git a/gold/config.in b/gold/config.in index 81da6aaad33..4f544fc8dc2 100644 --- a/gold/config.in +++ b/gold/config.in @@ -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 header file. */ #undef HAVE_TR1_UNORDERED_MAP diff --git a/gold/configure b/gold/configure index 45e84d968cb..01cdf169d06 100755 --- a/gold/configure +++ b/gold/configure @@ -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 extern void foo(const char*, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); +template void foo(const char* format, ...) {} +void bar() { foo("%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' diff --git a/gold/configure.ac b/gold/configure.ac index e930fd6cb7f..d9d965e1c36 100644 --- a/gold/configure.ac +++ b/gold/configure.ac @@ -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 extern void foo(const char*, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); +template void foo(const char* format, ...) {} +void bar() { foo("%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 diff --git a/gold/debug.h b/gold/debug.h index 9bc9c855110..8428dc81f07 100644 --- a/gold/debug.h +++ b/gold/debug.h @@ -23,6 +23,8 @@ #ifndef GOLD_DEBUG_H #define GOLD_DEBUG_H +#include + #include "parameters.h" #include "errors.h" diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc index f2ae53a955f..7ce6c7effe2 100644 --- a/gold/dwarf_reader.cc +++ b/gold/dwarf_reader.cc @@ -22,6 +22,8 @@ #include "gold.h" +#include + #include "elfcpp_swap.h" #include "dwarf.h" #include "object.h" diff --git a/gold/gold.h b/gold/gold.h index b34e0320b06..1b1a84c1b02 100644 --- a/gold/gold.h +++ b/gold/gold.h @@ -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 extern void gold_error_at_location(const Relocate_info*, 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 extern void gold_warning_at_location(const Relocate_info*, size_t, off_t, const char* format, ...) - ATTRIBUTE_PRINTF_4; + TEMPLATE_ATTRIBUTE_PRINTF_4; // This function is called to report an undefined symbol. template diff --git a/gold/main.cc b/gold/main.cc index e4f9003b215..2966d0351ed 100644 --- a/gold/main.cc +++ b/gold/main.cc @@ -22,9 +22,12 @@ #include "gold.h" +#include + #ifdef HAVE_MALLINFO #include #endif + #include "libiberty.h" #include "script.h" diff --git a/gold/object.cc b/gold/object.cc index 6c81f231bc6..378238d3fdc 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -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 diff --git a/gold/options.cc b/gold/options.cc index 58ac9cf9ac5..b6e4711881c 100644 --- a/gold/options.cc +++ b/gold/options.cc @@ -23,6 +23,7 @@ #include "gold.h" #include +#include #include #include #include diff --git a/gold/output.cc b/gold/output.cc index 3a11aa48e80..d4fc2a7a9a3 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -23,6 +23,7 @@ #include "gold.h" #include +#include #include #include #include diff --git a/gold/script.cc b/gold/script.cc index b8ecf9d9acf..a808b2e31d1 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -22,11 +22,12 @@ #include "gold.h" +#include +#include +#include #include #include #include -#include -#include #include "filenames.h" #include "elfcpp.h" diff --git a/gold/script.h b/gold/script.h index 26abd463ac4..af0f53cb4ae 100644 --- a/gold/script.h +++ b/gold/script.h @@ -31,6 +31,7 @@ #define GOLD_SCRIPT_H #include +#include #include #include "script-sections.h" diff --git a/gold/symtab.cc b/gold/symtab.cc index 3bd38337179..5ad5ae83c71 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -22,7 +22,9 @@ #include "gold.h" +#include #include +#include #include #include #include diff --git a/gold/target-select.cc b/gold/target-select.cc index 092a1df46fa..b81f5a28ea8 100644 --- a/gold/target-select.cc +++ b/gold/target-select.cc @@ -22,6 +22,8 @@ #include "gold.h" +#include + #include "elfcpp.h" #include "target-select.h" diff --git a/gold/testsuite/testmain.cc b/gold/testsuite/testmain.cc index 47c59b60745..ac99000edc7 100644 --- a/gold/testsuite/testmain.cc +++ b/gold/testsuite/testmain.cc @@ -22,6 +22,8 @@ #include "gold.h" +#include + #include "test.h" using namespace gold_testsuite; diff --git a/gold/version.cc b/gold/version.cc index 9e3ec2877a2..4b034b99d3c 100644 --- a/gold/version.cc +++ b/gold/version.cc @@ -22,6 +22,8 @@ #include "gold.h" +#include + #include "../bfd/bfdver.h" namespace gold diff --git a/gold/x86_64.cc b/gold/x86_64.cc index 26f73480924..973787fe7d1 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -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(&jmp[0]), 5) + std::string(length - 5, '\0')); } -- 2.30.2