From 504b7d2026f1fbbe912b6f513c069c0d47ba2505 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 16 Oct 2007 14:42:15 +0000 Subject: [PATCH] Support the use of the STT_COMMON type. (In source and object files only at the moment) --- bfd/ChangeLog | 12 ++++ bfd/config.in | 3 + bfd/configure | 68 ++++++++++++++----- bfd/configure.in | 24 ++++++- bfd/elf.c | 6 +- bfd/elfcode.h | 4 ++ binutils/testsuite/ChangeLog | 7 ++ binutils/testsuite/binutils-all/readelf.ss | 2 +- binutils/testsuite/binutils-all/readelf.ss-64 | 2 +- .../testsuite/binutils-all/readelf.ss-mips | 2 +- .../testsuite/binutils-all/readelf.ss-tmips | 2 +- gas/ChangeLog | 7 ++ gas/config/obj-elf.c | 27 ++++++++ gas/testsuite/ChangeLog | 6 ++ gas/testsuite/gas/all/string.d | 9 ++- gas/testsuite/gas/all/string.s | 3 - gas/testsuite/gas/elf/type.e | 1 + gas/testsuite/gas/elf/type.s | 2 + ld/testsuite/ChangeLog | 5 ++ ld/testsuite/ld-elfcomm/elfcomm.exp | 67 ++++++++++++++++-- ld/testsuite/ld-sh/sh64/crangerel1.rd | 1 + ld/testsuite/ld-sh/sh64/crangerel2.rd | 1 + ld/testsuite/ld-sh/sh64/reldl32.rd | 2 + ld/testsuite/ld-sh/sh64/reldl64.rd | 2 + 24 files changed, 227 insertions(+), 38 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a93c10282cf..09d3a7eaa14 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2007-10-16 Nick Clifton + + * configure.in (--enable-elf-stt-common): New configure + option. If enabled then the tools can generate symbols with + the ELF STT_COMMON type. + * config.in: Regenerate. + * configure: Regenerate. + * elf.c (swap_out_syms): If USE_STT_COMMON is defined then set + the type of emitted common symbols to STT_COMMON. + * elfcode.h (elf_slurp_symbol_table): Accept STT_COMMON symbol + types. + 2007-10-15 Alan Modra * coff-arm.c (arm_emit_base_file_entry): Check fwrite return value. diff --git a/bfd/config.in b/bfd/config.in index aa91dd69888..fd14f828b86 100644 --- a/bfd/config.in +++ b/bfd/config.in @@ -285,6 +285,9 @@ /* Define if we should default to creating read-only plt entries */ #undef USE_SECUREPLT +/* Define if we may generate symbols with ELF's STT_COMMON type */ +#undef USE_STT_COMMON + /* Version number of package */ #undef VERSION diff --git a/bfd/configure b/bfd/configure index 019bddd9dfe..806ee7edaa3 100755 --- a/bfd/configure +++ b/bfd/configure @@ -1012,6 +1012,7 @@ Optional Features: --enable-targets alternative target configurations --enable-commonbfdlib build shared BFD/opcodes/libiberty library --enable-secureplt Default to creating read-only plt entries + --enable-elf-stt-common Allow the generation of ELF symbols with the STT_COMMON type --enable-werror treat compile warnings as errors --enable-build-warnings enable build-time compiler warnings --enable-maintainer-mode enable make rules and dependencies not useful @@ -4665,13 +4666,13 @@ if test "${lt_cv_nm_interface+set}" = set; then else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:4668: $ac_compile\"" >&5) + (eval echo "\"\$as_me:4669: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:4671: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:4672: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:4674: output\"" >&5) + (eval echo "\"\$as_me:4675: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -5726,7 +5727,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5729 "configure"' > conftest.$ac_ext + echo '#line 5730 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6826,11 +6827,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6829: $lt_compile\"" >&5) + (eval echo "\"\$as_me:6830: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6833: \$? = $ac_status" >&5 + echo "$as_me:6834: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7148,11 +7149,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7151: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7152: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7155: \$? = $ac_status" >&5 + echo "$as_me:7156: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7253,11 +7254,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7256: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7257: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7260: \$? = $ac_status" >&5 + echo "$as_me:7261: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -7308,11 +7309,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7311: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7312: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7315: \$? = $ac_status" >&5 + echo "$as_me:7316: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10105,7 +10106,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10108 "configure" +#line 10109 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10205,7 +10206,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10208 "configure" +#line 10209 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10449,7 +10450,8 @@ echo "$as_me: error: bad value ${enableval} for 64-bit-bfd option" >&2;} esac else want64=false -fi; # Check whether --enable-targets or --disable-targets was given. +fi; +# Check whether --enable-targets or --disable-targets was given. if test "${enable_targets+set}" = set; then enableval="$enable_targets" case "${enableval}" in @@ -10460,7 +10462,8 @@ echo "$as_me: error: enable-targets option must specify target names or 'all'" > no) enable_targets= ;; *) enable_targets=$enableval ;; esac -fi; # Check whether --enable-commonbfdlib or --disable-commonbfdlib was given. +fi; +# Check whether --enable-commonbfdlib or --disable-commonbfdlib was given. if test "${enable_commonbfdlib+set}" = set; then enableval="$enable_commonbfdlib" case "${enableval}" in @@ -10471,6 +10474,7 @@ echo "$as_me: error: bad value ${enableval} for BFD commonbfdlib option" >&2;} { (exit 1); exit 1; }; } ;; esac fi; + # Check whether --with-mmap or --without-mmap was given. if test "${with_mmap+set}" = set; then withval="$with_mmap" @@ -10506,7 +10510,6 @@ fi DEBUGDIR=${libdir}/debug - # Check whether --with-separate-debug-dir or --without-separate-debug-dir was given. if test "${with_separate_debug_dir+set}" = set; then withval="$with_separate_debug_dir" @@ -10514,6 +10517,37 @@ if test "${with_separate_debug_dir+set}" = set; then fi; +# Check to see if we should allow the generation of +# symbols with the ELF standard's STT_COMMON type. +# Check whether --enable-elf-stt-common or --disable-elf-stt-common was given. +if test "${enable_elf_stt_common+set}" = set; then + enableval="$enable_elf_stt_common" + case "${enableval}" in + yes) want_elf_stt_common=true ;; + no) want_elf_stt_common=false ;; + *) { { echo "$as_me:$LINENO: error: bad value ${enableval} for ELF STT_COMMON option" >&5 +echo "$as_me: error: bad value ${enableval} for ELF STT_COMMON option" >&2;} + { (exit 1); exit 1; }; } ;; + esac +else + # We have to choose a default behaviour. For native builds we could +# test whether the loader supports the STT_COMMON type. For cross +# toolchains we default to assuming that they are not supported. +if test "$cross_compiling" != yes; then + want_elf_stt_common=false + else + # XXX FIXME: Add code to test the loader here. + want_elf_stt_common=false + fi +fi; if test $want_elf_stt_common = true; then + +cat >>confdefs.h <<\_ACEOF +#define USE_STT_COMMON 1 +_ACEOF + +fi + + # Check whether --with-pkgversion or --without-pkgversion was given. diff --git a/bfd/configure.in b/bfd/configure.in index facc1a3b138..ad8440e24a2 100644 --- a/bfd/configure.in +++ b/bfd/configure.in @@ -31,6 +31,7 @@ AC_ARG_ENABLE(64-bit-bfd, no) want64=false ;; *) AC_MSG_ERROR(bad value ${enableval} for 64-bit-bfd option) ;; esac],[want64=false])dnl + AC_ARG_ENABLE(targets, [ --enable-targets alternative target configurations], [case "${enableval}" in @@ -39,6 +40,7 @@ AC_ARG_ENABLE(targets, no) enable_targets= ;; *) enable_targets=$enableval ;; esac])dnl + AC_ARG_ENABLE(commonbfdlib, [ --enable-commonbfdlib build shared BFD/opcodes/libiberty library], [case "${enableval}" in @@ -46,6 +48,7 @@ AC_ARG_ENABLE(commonbfdlib, no) commonbfdlib=false ;; *) AC_MSG_ERROR([bad value ${enableval} for BFD commonbfdlib option]) ;; esac])dnl + AC_ARG_WITH(mmap, [ --with-mmap try using mmap for BFD input files if available], [case "${withval}" in @@ -67,13 +70,32 @@ if test $use_secureplt = true; then fi DEBUGDIR=${libdir}/debug - AC_ARG_WITH(separate-debug-dir, AS_HELP_STRING([--with-separate-debug-dir=DIR], [Look for global separate debug info in DIR [[default=LIBDIR/debug]]]), [DEBUGDIR="${withval}"]) AC_SUBST(DEBUGDIR) +# Check to see if we should allow the generation of +# symbols with the ELF standard's STT_COMMON type. +AC_ARG_ENABLE(elf-stt-common, +[ --enable-elf-stt-common Allow the generation of ELF symbols with the STT_COMMON type], +[case "${enableval}" in + yes) want_elf_stt_common=true ;; + no) want_elf_stt_common=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for ELF STT_COMMON option) ;; + esac], +# We have to choose a default behaviour. For native builds we could +# test whether the loader supports the STT_COMMON type, but that would +# mean that built binaries could not be exported to older systems where +# the loader does not support it. So by default we always choose to +# disable this feature. + want_elf_stt_common=false)dnl +if test $want_elf_stt_common = true; then + AC_DEFINE(USE_STT_COMMON, 1, + [Define if we may generate symbols with ELF's STT_COMMON type]) +fi + ACX_PKGVERSION([GNU Binutils]) ACX_BUGURL([http://www.sourceware.org/bugzilla/]) diff --git a/bfd/elf.c b/bfd/elf.c index b5b51d02a3f..8aac231fa6a 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -6297,7 +6297,11 @@ Unable to find equivalent output section for symbol '%s' from section '%s'"), sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); } else if (bfd_is_com_section (syms[idx]->section)) - sym.st_info = ELF_ST_INFO (STB_GLOBAL, type); + sym.st_info = ELF_ST_INFO (STB_GLOBAL, +#ifdef USE_STT_COMMON + type == STT_OBJECT ? STT_COMMON : +#endif + type); else if (bfd_is_und_section (syms[idx]->section)) sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK) ? STB_WEAK diff --git a/bfd/elfcode.h b/bfd/elfcode.h index e1f58016740..ea2a6d3dada 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1323,6 +1323,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) case STT_FUNC: sym->symbol.flags |= BSF_FUNCTION; break; + case STT_COMMON: + /* FIXME: Do we have to put the size field into the value field + as we do with symbols in SHN_COMMON sections (see above) ? */ + /* Fall through. */ case STT_OBJECT: sym->symbol.flags |= BSF_OBJECT; break; diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog index 82292aa46be..9bd42d8dcda 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-10-16 Nick Clifton + + * binutils-all/readelf.ss: Accept COMMON in readelf's output. + * binutils-all/readelf.ss-64: Likewise. + * binutils-all/readelf.ss-mips: Likewise. + * binutils-all/readelf.ss-tmips: Likewise. + 2007-08-30 Nick Clifton * binutils-all/dumptest.s: New test file. diff --git a/binutils/testsuite/binutils-all/readelf.ss b/binutils/testsuite/binutils-all/readelf.ss index 7daee1b30b3..19677957b6a 100644 --- a/binutils/testsuite/binutils-all/readelf.ss +++ b/binutils/testsuite/binutils-all/readelf.ss @@ -15,4 +15,4 @@ Symbol table '.symtab' contains .* entries: .* .: 00000000 0 NOTYPE GLOBAL DEFAULT 1 text_symbol ..: 00000000 0 NOTYPE GLOBAL DEFAULT UND external_symbol ..: 00000000 0 NOTYPE GLOBAL DEFAULT [34] data_symbol - ..: 00000004 4 OBJECT GLOBAL DEFAULT ( COM|ANSI_COM) common_symbol + ..: 00000004 4 (COMMON|OBJECT) GLOBAL DEFAULT ( COM|ANSI_COM) common_symbol diff --git a/binutils/testsuite/binutils-all/readelf.ss-64 b/binutils/testsuite/binutils-all/readelf.ss-64 index b29276d4760..54eea053f41 100644 --- a/binutils/testsuite/binutils-all/readelf.ss-64 +++ b/binutils/testsuite/binutils-all/readelf.ss-64 @@ -10,4 +10,4 @@ Symbol table '.symtab' contains .* entries: .* .: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 text_symbol .: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND external_symbol .: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 3 data_symbol - .: 0000000000000004 4 OBJECT GLOBAL DEFAULT COM common_symbol + .: 0000000000000004 4 (COMMON|OBJECT) GLOBAL DEFAULT COM common_symbol diff --git a/binutils/testsuite/binutils-all/readelf.ss-mips b/binutils/testsuite/binutils-all/readelf.ss-mips index 073ade018f9..0c2b75ef101 100644 --- a/binutils/testsuite/binutils-all/readelf.ss-mips +++ b/binutils/testsuite/binutils-all/readelf.ss-mips @@ -12,4 +12,4 @@ Symbol table '.symtab' contains 12 entries: 8: 00000000 0 NOTYPE GLOBAL DEFAULT UND external_symbol 9: 00000000 0 OBJECT GLOBAL DEFAULT . data_symbol 10: 00000000 0 NOTYPE LOCAL DEFAULT . static_data_symbol - 11: 00000004 4 OBJECT GLOBAL DEFAULT (PRC|COM) common_symbol + 11: 00000004 4 (COMMON|OBJECT) GLOBAL DEFAULT (PRC|COM) common_symbol diff --git a/binutils/testsuite/binutils-all/readelf.ss-tmips b/binutils/testsuite/binutils-all/readelf.ss-tmips index 4f2fba22284..a76859b4bb1 100644 --- a/binutils/testsuite/binutils-all/readelf.ss-tmips +++ b/binutils/testsuite/binutils-all/readelf.ss-tmips @@ -12,4 +12,4 @@ Symbol table '.symtab' contains 12 entries: 8: 00000000 0 OBJECT GLOBAL DEFAULT 1 text_symbol 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND external_symbol 10: 00000000 0 OBJECT GLOBAL DEFAULT 3 data_symbol - 11: 00000004 4 OBJECT GLOBAL DEFAULT (PRC|COM) common_symbol + 11: 00000004 4 (COMMON|OBJECT) GLOBAL DEFAULT (PRC|COM) common_symbol diff --git a/gas/ChangeLog b/gas/ChangeLog index 8cf8f04f985..1e7e6391d95 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,10 @@ +2007-10-16 Nick Clifton + + * config/obj-elf.c (obj_elf_type): Accept "common" as a valid + symbol type. + * doc/as.texinfo (.type): Document the types accepted by the + type pseudo op, including "common". + 2007-10-15 Peter Bergner * config/tc-ppc.c (ppc_setup_opcodes): Verify instructions are sorted diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 429b32faca9..ab1550df1f4 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -1587,6 +1587,33 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED) else if (strcmp (typename, "notype") == 0 || strcmp (typename, "STT_NOTYPE") == 0) ; + else if (strcmp (typename, "common") == 0 + || strcmp (typename, "STT_COMMON") == 0) + { + type = BSF_OBJECT; + + if (! S_IS_COMMON (sym)) + { + if (S_IS_VOLATILE (sym)) + { + sym = symbol_clone (sym, 1); + S_SET_SEGMENT (sym, bfd_com_section_ptr); + S_SET_VALUE (sym, 0); + S_SET_EXTERNAL (sym); + symbol_set_frag (sym, &zero_address_frag); + S_CLEAR_VOLATILE (sym); + } + else if (S_IS_DEFINED (sym) || symbol_equated_p (sym)) + as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym)); + else + { + /* FIXME: Is it safe to just change the section ? */ + S_SET_SEGMENT (sym, bfd_com_section_ptr); + S_SET_VALUE (sym, 0); + S_SET_EXTERNAL (sym); + } + } + } #ifdef md_elf_symbol_type else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1) ; diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index 1acc54c1e35..b1b06681f38 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-10-16 Nick Clifton + + * gas/elf/elf.exp: Accept COMMON in readelf's output. + * gas/elf/type.s: Add test of common type. + * gas/elf/type.e: Extend expected output. + 2007-10-11 Nick Clifton * gas/elf/elf.exp (run_elf_list_test): Run section6 test. diff --git a/gas/testsuite/gas/all/string.d b/gas/testsuite/gas/all/string.d index da6177d27c6..b8bfd846cc1 100644 --- a/gas/testsuite/gas/all/string.d +++ b/gas/testsuite/gas/all/string.d @@ -4,9 +4,8 @@ .*: .* Contents of section (\.data|\$DATA\$): - 0000 73747238 00000000 00000000 00000000 str8.* - 0010 7374726e 65773800 00000000 00000000 strnew8.* - 0020 (73007400 72003100 36000000 00000000|00730074 00720031 00360000 00000000).* - 0030 (33000000 32000000 00000000 00000000|00000033 00000032 00000000 00000000).* - 0040 (36000000 00000000 34000000 00000000|00000000 00000036 00000000 00000034).* + 0000 7374726e 65773800 00000000 00000000 strnew8.* + 00.. (73007400 72003100 36000000 00000000|00730074 00720031 00360000 00000000).* + 00.. (33000000 32000000 00000000 00000000|00000033 00000032 00000000 00000000).* + 00.. (36000000 00000000 34000000 00000000|00000000 00000036 00000000 00000034).* #pass diff --git a/gas/testsuite/gas/all/string.s b/gas/testsuite/gas/all/string.s index 80743bb7004..6565a71ab85 100644 --- a/gas/testsuite/gas/all/string.s +++ b/gas/testsuite/gas/all/string.s @@ -1,7 +1,4 @@ .data - .string "str8" - - .balign 16 .string8 "strnew8" .balign 16 diff --git a/gas/testsuite/gas/elf/type.e b/gas/testsuite/gas/elf/type.e index 97742e854e6..50a49ab9572 100644 --- a/gas/testsuite/gas/elf/type.e +++ b/gas/testsuite/gas/elf/type.e @@ -2,3 +2,4 @@ .: 0+0 1 OBJECT LOCAL DEFAULT . object .: 0+1 1 TLS LOCAL DEFAULT . tls_object .: 0+2 1 NOTYPE LOCAL DEFAULT . notype + ..: 0+1 1 (COMMON|OBJECT) GLOBAL DEFAULT COM common diff --git a/gas/testsuite/gas/elf/type.s b/gas/testsuite/gas/elf/type.s index fdb76467e2a..11f75bf53c7 100644 --- a/gas/testsuite/gas/elf/type.s +++ b/gas/testsuite/gas/elf/type.s @@ -16,3 +16,5 @@ tls_object: .size notype,1 notype: .byte 0x0 + .comm common, 1 + .type common,STT_COMMON diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index e84bd0a2873..07b1e927190 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-10-16 Nick Clifton + + * lf-elfcomm/elfcomm.exp: Add tests of STT_COMMON symbol + generation. + 2007-10-12 Joseph Myers * ld-mips-elf/multi-got-hidden-1.d, diff --git a/ld/testsuite/ld-elfcomm/elfcomm.exp b/ld/testsuite/ld-elfcomm/elfcomm.exp index bed5258fd7b..400dcad6022 100644 --- a/ld/testsuite/ld-elfcomm/elfcomm.exp +++ b/ld/testsuite/ld-elfcomm/elfcomm.exp @@ -53,12 +53,11 @@ proc dump_common1 { testname } { global exec_output global READELF - send_log "$READELF -s tmpdir/common1.o | grep foo\n" - set exec_output [run_host_cmd "readelf" "-s tmpdir/common1.o | grep foo"] + send_log "$READELF --syms tmpdir/common1.o | grep foo\n" + set exec_output [run_host_cmd "readelf" "--syms tmpdir/common1.o | grep foo"] - if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] - || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo1" $exec_output] } { - send_log "$exec_output\n" + if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)(COMMON|OBJECT)(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] + || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo1" $exec_output] } { verbose $exec_output fail $testname return 0 @@ -67,7 +66,49 @@ proc dump_common1 { testname } { return 1 } -if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o] +proc stt_common_test { options testname } { + global exec_output + global READELF + global ld + + set options "$options tmpdir/common1a.o" + + if { ! [ld_simple_link $ld tmpdir/common.exe $options] } { + unresolved $testname + return 0 + } + + send_log "$READELF --syms tmpdir/common.exe | grep foo\n" + set exec_output [run_host_cmd "readelf" "--syms tmpdir/common.exe | grep foo"] + + if {![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)(\[0-9\]+)(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo2" $exec_output] } { + fail $testname + return 0 + } + + pass $testname + return 1 +} + +# Check to see if the assembler is generating symbols with the STT_COMMON type. +proc assembler_generates_commons {} { + global exec_output + global READELF + + verbose "Check to see if STT_COMMON symbols are being generated:" + set exec_output [run_host_cmd "readelf" "--syms tmpdir/common1a.o | grep foo"] + + if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+).(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] } { + verbose "STT_COMMON not generated" + return 0 + } + + verbose "STT_COMMON's are generated" + return 1 +} + + +if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o] || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } { unresolved $test1 return @@ -90,7 +131,6 @@ if {[istarget mips*-*-*]} { pass $test1w1 } } else { - pass $test1w1 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } { fail $test1w1 @@ -117,3 +157,16 @@ if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/comm if { [dump_common1 $test1c2] } { pass $test1c2 } + +# +# The following tests are for when we are generating STT_COMMON symbols only. +# + +if { ![assembler_generates_commons] } { + return +} + +stt_common_test "-static -e 0" "static link of common symbols" +stt_common_test "-shared" "shared link of common symbols" +stt_common_test "-pie" "position independent link of common symbols" + diff --git a/ld/testsuite/ld-sh/sh64/crangerel1.rd b/ld/testsuite/ld-sh/sh64/crangerel1.rd index 005918e4f64..7b133c6d8a8 100644 --- a/ld/testsuite/ld-sh/sh64/crangerel1.rd +++ b/ld/testsuite/ld-sh/sh64/crangerel1.rd @@ -41,5 +41,6 @@ Hex dump of section '\.text\.mixed': 0x00000010 0000002b 00090009 .* Hex dump of section '\.cranges': +.* 0x00000000 00000000 0000000c 00030000 000c0000 .* 0x00000010 00080001 00000014 00000004 0002 .* diff --git a/ld/testsuite/ld-sh/sh64/crangerel2.rd b/ld/testsuite/ld-sh/sh64/crangerel2.rd index f9c55d5494d..635acfcda88 100644 --- a/ld/testsuite/ld-sh/sh64/crangerel2.rd +++ b/ld/testsuite/ld-sh/sh64/crangerel2.rd @@ -53,6 +53,7 @@ Hex dump of section '\.text\.mixed': 0x00000050 6ff0fff0 6ff0fff0 6ff0fff0 .* Hex dump of section '\.cranges': +.* 0x00000000 00000000 0000000c 00030000 000c0000 .* 0x00000010 00080001 00000014 00000004 00020000 .* 0x00000020 00180000 00100003 00000028 00000014 .* diff --git a/ld/testsuite/ld-sh/sh64/reldl32.rd b/ld/testsuite/ld-sh/sh64/reldl32.rd index d242c5c6a02..98bbbed7110 100644 --- a/ld/testsuite/ld-sh/sh64/reldl32.rd +++ b/ld/testsuite/ld-sh/sh64/reldl32.rd @@ -303,6 +303,7 @@ Symbol table '\.symtab' contains 134 entries: 133: 00000000 0 : 13 GLOBAL DEFAULT UND unresolved8 Hex dump of section '\.text': +.* 0x00000000 6ff0fff0 6ff0fff0 cc0000a0 cc000140 .* 0x00000010 cc000140 cc000140 cc000280 cc0001e0 .* 0x00000020 cc0000a0 cc0000a0 cc000280 cc000140 .* @@ -319,6 +320,7 @@ Hex dump of section '\.text': 0x000000d0 6ff0fff0 .* Hex dump of section '\.data': +.* 0x00000000 00000000 00000000 00000008 00000000 .* 0x00000010 00000000 00000000 00000000 00000000 .* 0x00000020 00000028 00000000 00000000 00000000 .* diff --git a/ld/testsuite/ld-sh/sh64/reldl64.rd b/ld/testsuite/ld-sh/sh64/reldl64.rd index 41aa91e4154..a34537b5604 100644 --- a/ld/testsuite/ld-sh/sh64/reldl64.rd +++ b/ld/testsuite/ld-sh/sh64/reldl64.rd @@ -305,6 +305,7 @@ Symbol table '\.symtab' contains 134 entries: 133: 0000000000000000 0 : 13 GLOBAL DEFAULT UND unresolved8 Hex dump of section '\.text': +.* 0x00000000 6ff0fff0 6ff0fff0 cc0000a0 cc000140 .* 0x00000010 cc000140 cc000140 cc000280 cc0001e0 .* 0x00000020 cc0000a0 cc0000a0 cc000280 cc000140 .* @@ -321,6 +322,7 @@ Hex dump of section '\.text': 0x000000d0 6ff0fff0 6ff0fff0 6ff0fff0 .* Hex dump of section '\.data': +.* 0x00000000 00000000 00000000 00000008 00000000 .* 0x00000010 00000000 00000000 00000000 00000000 .* 0x00000020 00000028 00000000 00000000 00000000 .* -- 2.30.2