2002-08-20 Stephen Clarke , Richard Shann * bfd/elf32-sh.c: Set LSB of DT_INIT value if .init is an SHmedia function. Set LSB of DT_FINI value if .fini is an SHmedia function. * bfd/elf64-sh64.c: Likewise. 2002-08-20 Stephen Clarke * ld-sh/sh64/rd-sh64.exp: New framework file. * ld-sh/sh64/init-cmpct.d, ld-sh/sh64/init-media.d, ld-sh/sh64/init64.d, ld-sh/sh64/init.s: New tests for correct setting of ISA bit for init and fini entry-points. Index: bfd/elf32-sh.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-sh.c,v retrieving revision 1.53 diff -u -c -3 -p -r1.53 elf32-sh.c *** bfd/elf32-sh.c 16 Aug 2002 18:40:54 -0000 1.53 --- bfd/elf32-sh.c 21 Aug 2002 04:34:55 -0000 *************** sh_elf_finish_dynamic_sections (output_b *** 5697,5702 **** --- 5697,5703 ---- Elf_Internal_Dyn dyn; const char *name; asection *s; + struct elf_link_hash_entry *h; bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); *************** sh_elf_finish_dynamic_sections (output_b *** 5704,5709 **** --- 5705,5731 ---- { default: break; + + #ifdef INCLUDE_SHMEDIA + case DT_INIT: + name = info->init_function; + goto get_sym; + + case DT_FINI: + name = info->fini_function; + get_sym: + if (dyn.d_un.d_val != 0) + { + h = elf_link_hash_lookup (elf_hash_table (info), name, + false, false, true); + if (h != NULL && (h->other & STO_SH5_ISA32)) + { + dyn.d_un.d_val |= 1; + bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); + } + } + break; + #endif case DT_PLTGOT: name = ".got"; Index: bfd/elf64-sh64.c =================================================================== RCS file: /cvs/src/src/bfd/elf64-sh64.c,v retrieving revision 1.16 diff -u -c -3 -p -r1.16 elf64-sh64.c *** bfd/elf64-sh64.c 16 Aug 2002 18:40:54 -0000 1.16 --- bfd/elf64-sh64.c 21 Aug 2002 04:34:56 -0000 *************** sh64_elf64_finish_dynamic_sections (outp *** 3990,4001 **** --- 3990,4021 ---- Elf_Internal_Dyn dyn; const char *name; asection *s; + struct elf_link_hash_entry *h; bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); switch (dyn.d_tag) { default: + break; + + case DT_INIT: + name = info->init_function; + goto get_sym; + + case DT_FINI: + name = info->fini_function; + get_sym: + if (dyn.d_un.d_val != 0) + { + h = elf_link_hash_lookup (elf_hash_table (info), name, + false, false, true); + if (h != NULL && (h->other & STO_SH5_ISA32)) + { + dyn.d_un.d_val |= 1; + bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); + } + } break; case DT_PLTGOT: Index: ld/testsuite/ld-sh/sh64/init-cmpct.d =================================================================== RCS file: ld/testsuite/ld-sh/sh64/init-cmpct.d diff -N ld/testsuite/ld-sh/sh64/init-cmpct.d *** /dev/null 1 Jan 1970 00:00:00 -0000 --- ld/testsuite/ld-sh/sh64/init-cmpct.d 21 Aug 2002 04:34:58 -0000 *************** *** 0 **** --- 1,20 ---- + #source: init.s + #as: --abi=32 --isa=SHcompact + #ld: -shared -mshelf32 + #readelf: -d + #target: sh64-*-elf + + # Make sure that the lsb of DT_INIT and DT_FINI entries is not set + # when _init and _fini are SHcompact code. + + Dynamic segment at offset 0x358 contains 8 entries: + Tag Type Name/Value + 0x0000000c \(INIT\) 0x346 + 0x0000000d \(FINI\) 0x34e + 0x00000004 \(HASH\) 0x94 + 0x00000005 \(STRTAB\) 0x2d4 + 0x00000006 \(SYMTAB\) 0x144 + 0x0000000a \(STRSZ\) 114 \(bytes\) + 0x0000000b \(SYMENT\) 16 \(bytes\) + 0x00000000 \(NULL\) 0x0 + Index: ld/testsuite/ld-sh/sh64/init-media.d =================================================================== RCS file: ld/testsuite/ld-sh/sh64/init-media.d diff -N ld/testsuite/ld-sh/sh64/init-media.d *** /dev/null 1 Jan 1970 00:00:00 -0000 --- ld/testsuite/ld-sh/sh64/init-media.d 21 Aug 2002 04:34:58 -0000 *************** *** 0 **** --- 1,19 ---- + #source: init.s + #as: --abi=32 --isa=SHmedia + #ld: -shared -mshelf32 + #readelf: -d + #target: sh64-*-elf + + # Make sure that the lsb of DT_INIT and DT_FINI entries is set + # when _init and _fini are SHmedia code. + + Dynamic segment at offset 0x368 contains 8 entries: + Tag Type Name/Value + 0x0000000c \(INIT\) 0x347 + 0x0000000d \(FINI\) 0x357 + 0x00000004 \(HASH\) 0x94 + 0x00000005 \(STRTAB\) 0x2d4 + 0x00000006 \(SYMTAB\) 0x144 + 0x0000000a \(STRSZ\) 114 \(bytes\) + 0x0000000b \(SYMENT\) 16 \(bytes\) + 0x00000000 \(NULL\) 0x0 Index: ld/testsuite/ld-sh/sh64/init.s =================================================================== RCS file: ld/testsuite/ld-sh/sh64/init.s diff -N ld/testsuite/ld-sh/sh64/init.s *** /dev/null 1 Jan 1970 00:00:00 -0000 --- ld/testsuite/ld-sh/sh64/init.s 21 Aug 2002 04:34:58 -0000 *************** *** 0 **** --- 1,16 ---- + .section .text,"ax" + .global _init + .type _init,@function + _init: + nop + nop + nop + nop + + .global _fini + .type _fini,@function + _fini: + nop + nop + nop + nop Index: ld/testsuite/ld-sh/sh64/init64.d =================================================================== RCS file: ld/testsuite/ld-sh/sh64/init64.d diff -N ld/testsuite/ld-sh/sh64/init64.d *** /dev/null 1 Jan 1970 00:00:00 -0000 --- ld/testsuite/ld-sh/sh64/init64.d 21 Aug 2002 04:34:58 -0000 *************** *** 0 **** --- 1,19 ---- + #source: init.s + #as: --abi=64 + #ld: -shared -mshelf64 + #readelf: -d + #target: sh64-*-elf + + # Make sure that the lsb of DT_INIT and DT_FINI entries is set + # when _init and _fini are SHmedia code. + + Dynamic segment at offset 0x488 contains 8 entries: + Tag Type Name/Value + 0x000000000000000c \(INIT\) 0x463 + 0x000000000000000d \(FINI\) 0x473 + 0x0000000000000004 \(HASH\) 0xe8 + 0x0000000000000005 \(STRTAB\) 0x3f0 + 0x0000000000000006 \(SYMTAB\) 0x198 + 0x000000000000000a \(STRSZ\) 114 \(bytes\) + 0x000000000000000b \(SYMENT\) 24 \(bytes\) + 0x0000000000000000 \(NULL\) 0x0 Index: ld/testsuite/ld-sh/sh64/rd-sh64.exp =================================================================== RCS file: ld/testsuite/ld-sh/sh64/rd-sh64.exp diff -N ld/testsuite/ld-sh/sh64/rd-sh64.exp *** /dev/null 1 Jan 1970 00:00:00 -0000 --- ld/testsuite/ld-sh/sh64/rd-sh64.exp 21 Aug 2002 04:34:58 -0000 *************** *** 0 **** --- 1,30 ---- + # Expect script for run_dump_test based ld-sh/sh64 tests. + # Copyright 2002 Free Software Foundation, Inc. + # + # This file 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + # + # Written by Stephen Clarke (stephen.clarke@superh.com) + # + + if ![istarget sh64-*-*] { + return + } + + set rd_test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] + foreach sh64test $rd_test_list { + # We need to strip the ".d", but can leave the dirname. + verbose [file rootname $sh64test] + run_dump_test [file rootname $sh64test] + }