From 19d9b7d3f82720e648f9cda6ab93a64d9d9c0fa1 Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Mon, 5 Feb 2007 20:16:32 +0000 Subject: [PATCH] Support for Toshiba MeP. --- ld/ChangeLog | 8 + ld/Makefile.am | 4 + ld/Makefile.in | 4 + ld/configure.tgt | 1 + ld/emulparams/elf32mep.sh | 55 +++ ld/scripttempl/mep.sc | 446 ++++++++++++++++++++++++ ld/testsuite/ChangeLog | 5 + ld/testsuite/ld-mep/mep.exp | 35 ++ ld/testsuite/ld-mep/mep1.ld | 8 + ld/testsuite/ld-mep/mep1.s | 13 + ld/testsuite/ld-undefined/undefined.exp | 1 + 11 files changed, 580 insertions(+) create mode 100755 ld/emulparams/elf32mep.sh create mode 100644 ld/scripttempl/mep.sc create mode 100644 ld/testsuite/ld-mep/mep.exp create mode 100644 ld/testsuite/ld-mep/mep1.ld create mode 100644 ld/testsuite/ld-mep/mep1.s diff --git a/ld/ChangeLog b/ld/ChangeLog index 58f095f02a..4155b2a052 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2007-02-05 Dave Brolley + + * Makefile.am (ALL_EMULATIONS): Add support for Toshiba MeP. + * configure.tgt: Likewise. + * scripttempl/mep.sc: New file. + * emulparams/elf32mep.sh: New file. + * Makefile.in: Regenerate. + 2006-01-29 Julian Brown * NEWS: Mention --vfp11-denorm-fix option. diff --git a/ld/Makefile.am b/ld/Makefile.am index 5cf46bac6d..c57871d4bd 100644 --- a/ld/Makefile.am +++ b/ld/Makefile.am @@ -177,6 +177,7 @@ ALL_EMULATIONS = \ eelf32lppcsim.o \ eelf32m32c.o \ eelf32mcore.o \ + eelf32mep.o \ eelf32mipswindiss.o \ eelf32mt.o \ eelf32openrisc.o \ @@ -692,6 +693,9 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \ eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32mcore "$(tdir_mcore)" +eelf32mep.c: $(srcdir)/emulparams/elf32mep.sh \ + $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/mep.sc ${GEN_DEPENDS} + ${GENSCRIPTS} elf32mep "$(tdir_mep)" em32relf.c: $(srcdir)/emulparams/m32relf.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} m32relf "$(tdir_m32r)" diff --git a/ld/Makefile.in b/ld/Makefile.in index 7c802b481d..543edea9f6 100644 --- a/ld/Makefile.in +++ b/ld/Makefile.in @@ -412,6 +412,7 @@ ALL_EMULATIONS = \ eelf32lppcsim.o \ eelf32m32c.o \ eelf32mcore.o \ + eelf32mep.o \ eelf32mipswindiss.o \ eelf32mt.o \ eelf32openrisc.o \ @@ -1506,6 +1507,9 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \ eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32mcore "$(tdir_mcore)" +eelf32mep.c: $(srcdir)/emulparams/elf32mep.sh \ + $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/mep.sc ${GEN_DEPENDS} + ${GENSCRIPTS} elf32mep "$(tdir_mep)" em32relf.c: $(srcdir)/emulparams/m32relf.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} m32relf "$(tdir_m32r)" diff --git a/ld/configure.tgt b/ld/configure.tgt index 86232354f4..4229f964fa 100644 --- a/ld/configure.tgt +++ b/ld/configure.tgt @@ -321,6 +321,7 @@ mcore-*-pe) targ_emul=mcorepe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; mcore-*-elf) targ_emul=elf32mcore ;; +mep-*-elf) targ_emul=elf32mep ;; mips*-*-pe) targ_emul=mipspe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; mips*-dec-ultrix*) targ_emul=mipslit ;; diff --git a/ld/emulparams/elf32mep.sh b/ld/emulparams/elf32mep.sh new file mode 100755 index 0000000000..886ca47285 --- /dev/null +++ b/ld/emulparams/elf32mep.sh @@ -0,0 +1,55 @@ +MACHINE= +SCRIPT_NAME=mep +OUTPUT_FORMAT="elf32-mep" +TEXT_START_ADDR=0x1000 +ARCH=mep +MAXPAGESIZE=256 +ENTRY=_start +EMBEDDED=yes +TEMPLATE_NAME=elf32 +DATA_START_SYMBOLS='__data_start = . ;' +OTHER_GOT_SYMBOLS=' + . = ALIGN(4); + __sdabase = . + 0x8000; + .srodata : { *(.srodata) *(.srodata.*) *(.gnu.linkonce.srd.*) } +' +OTHER_SDATA_SECTIONS=' + PROVIDE (__sdabase = .); + __assert_tiny_size = ASSERT ((. < __sdabase) || ((. - __sdabase) <= 0x8000), + "tiny section overflow"); +' +OTHER_READONLY_SECTIONS=' + __stack = 0x001ffff0; + __stack_size = 0x100000; + __stack0 = (__stack - (0 * (__stack_size / 1)) + 15) / 16 * 16; + + .rostacktab : + { + /* Emit a table describing the location of the different stacks. + Only 1 processor in the default configuration. */ + . = ALIGN(4); + __stack_table = .; + LONG (__stack0); + } +' +OTHER_END_SYMBOLS=' + PROVIDE (__heap = _end); + PROVIDE (__heap_end = 0); +' +OTHER_TEXT_SECTIONS=' + *(.ftext) *(.ftext.*) *(.gnu.linkonce.ft.*) + . = ALIGN(8); + *(.vftext) *(.vftext.*) *(.gnu.linkonce.vf.*) + *(.frodata) *(.frodata.*) *(.gnu.linkonce.frd.*) +' +OTHER_READWRITE_SECTIONS=' + . = ALIGN(4); + __tpbase = .; + .based : { *(.based) *(.based.*) *(.gnu.linkonce.based.*) } + __assert_based_size = ASSERT ((. - __tpbase) <= 0x80, "based section overflow"); + .far : { *(.far) *(.far.*) *(.gnu.linkonce.far.*) } +' +OTHER_BSS_SECTIONS=' + __assert_near_size = ASSERT (. <= 0x1000000, "near section overflow"); + .farbss : { PROVIDE (__farbss_start = .); *(.farbss) *(.farbss.*) PROVIDE (__farbss_end = .); } +' diff --git a/ld/scripttempl/mep.sc b/ld/scripttempl/mep.sc new file mode 100644 index 0000000000..0d459c65b0 --- /dev/null +++ b/ld/scripttempl/mep.sc @@ -0,0 +1,446 @@ +# +# Unusual variables checked by this code: +# NOP - four byte opcode for no-op (defaults to 0) +# NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not +# empty. +# SMALL_DATA_CTOR - .ctors contains small data. +# SMALL_DATA_DTOR - .dtors contains small data. +# DATA_ADDR - if end-of-text-plus-one-page isn't right for data start +# INITIAL_READONLY_SECTIONS - at start of text segment +# OTHER_READONLY_SECTIONS - other than .text .init .rodata ... +# (e.g., .PARISC.milli) +# OTHER_TEXT_SECTIONS - these get put in .text when relocating +# OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ... +# (e.g., .PARISC.global) +# OTHER_RELRO_SECTIONS - other than .data.rel.ro ... +# (e.g. PPC32 .fixup, .got[12]) +# OTHER_BSS_SECTIONS - other than .bss .sbss ... +# OTHER_SECTIONS - at the end +# EXECUTABLE_SYMBOLS - symbols that must be defined for an +# executable (e.g., _DYNAMIC_LINK) +# TEXT_START_ADDR - the first byte of the text segment, after any +# headers. +# TEXT_BASE_ADDRESS - the first byte of the text segment. +# TEXT_START_SYMBOLS - symbols that appear at the start of the +# .text section. +# DATA_START_SYMBOLS - symbols that appear at the start of the +# .data section. +# OTHER_GOT_SYMBOLS - symbols defined just before .got. +# OTHER_GOT_SECTIONS - sections just after .got. +# OTHER_SDATA_SECTIONS - sections just after .sdata. +# OTHER_BSS_SYMBOLS - symbols that appear at the start of the +# .bss section besides __bss_start. +# DATA_PLT - .plt should be in data segment, not text segment. +# PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement. +# BSS_PLT - .plt should be in bss segment +# TEXT_DYNAMIC - .dynamic in text segment, not data segment. +# EMBEDDED - whether this is for an embedded system. +# SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set +# start address of shared library. +# INPUT_FILES - INPUT command of files to always include +# WRITABLE_RODATA - if set, the .rodata section should be writable +# INIT_START, INIT_END - statements just before and just after +# combination of .init sections. +# FINI_START, FINI_END - statements just before and just after +# combination of .fini sections. +# STACK_ADDR - start of a .stack section. +# OTHER_END_SYMBOLS - symbols to place right at the end of the script. +# SEPARATE_GOTPLT - if set, .got.plt should be separate output section, +# so that .got can be in the RELRO area. It should be set to +# the number of bytes in the beginning of .got.plt which can be +# in the RELRO area as well. +# +# When adding sections, do note that the names of some sections are used +# when specifying the start address of the next. +# + +# Many sections come in three flavours. There is the 'real' section, +# like ".data". Then there are the per-procedure or per-variable +# sections, generated by -ffunction-sections and -fdata-sections in GCC, +# and useful for --gc-sections, which for a variable "foo" might be +# ".data.foo". Then there are the linkonce sections, for which the linker +# eliminates duplicates, which are named like ".gnu.linkonce.d.foo". +# The exact correspondences are: +# +# Section Linkonce section +# .text .gnu.linkonce.t.foo +# .rodata .gnu.linkonce.r.foo +# .data .gnu.linkonce.d.foo +# .bss .gnu.linkonce.b.foo +# .sdata .gnu.linkonce.s.foo +# .sbss .gnu.linkonce.sb.foo +# .sdata2 .gnu.linkonce.s2.foo +# .sbss2 .gnu.linkonce.sb2.foo +# .debug_info .gnu.linkonce.wi.foo +# .tdata .gnu.linkonce.td.foo +# .tbss .gnu.linkonce.tb.foo +# +# Each of these can also have corresponding .rel.* and .rela.* sections. + +test -z "$ENTRY" && ENTRY=_start +test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT} +test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} +if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi +test -z "${ELFSIZE}" && ELFSIZE=32 +test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8" +test "$LD_FLAG" = "N" && DATA_ADDR=. +test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE="" +test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE="" +test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT +DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))" +DATA_SEGMENT_RELRO_END="" +DATA_SEGMENT_RELRO_GOTPLT_END="" +DATA_SEGMENT_END="" +if test -n "${COMMONPAGESIZE}"; then + DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" + DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);" + if test -n "${SEPARATE_GOTPLT}"; then + DATA_SEGMENT_RELRO_GOTPLT_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT}, .);" + else + DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (0, .);" + fi +fi +INTERP=".interp ${RELOCATING-0} : { *(.interp) }" +PLT=".plt ${RELOCATING-0} : { *(.plt) }" +if test -z "$GOT"; then + if test -z "$SEPARATE_GOTPLT"; then + GOT=".got ${RELOCATING-0} : { *(.got.plt) *(.got) }" + else + GOT=".got ${RELOCATING-0} : { *(.got) }" + GOTPLT="${RELOCATING+${DATA_SEGMENT_RELRO_GOTPLT_END}} + .got.plt ${RELOCATING-0} : { *(.got.plt) }" + fi +fi +DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }" +RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }" +DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }" +STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }" +if test -z "${NO_SMALL_DATA}"; then + SBSS=".sbss ${RELOCATING-0} : + { + ${RELOCATING+PROVIDE (__sbss_start = .);} + ${RELOCATING+PROVIDE (___sbss_start = .);} + ${CREATE_SHLIB+*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)} + *(.dynsbss) + *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*}) + *(.scommon) + ${RELOCATING+PROVIDE (__sbss_end = .);} + ${RELOCATING+PROVIDE (___sbss_end = .);} + }" + SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }" + SDATA="/* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata ${RELOCATING-0} : + { + ${RELOCATING+${SDATA_START_SYMBOLS}} + ${CREATE_SHLIB+*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)} + *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*}) + }" + SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }" + REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) } + .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }" + REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) } + .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }" + REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) } + .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }" + REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) } + .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }" +else + NO_SMALL_DATA=" " +fi +test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" " +CTOR=".ctors ${CONSTRUCTING-0} : + { + ${CONSTRUCTING+${CTOR_START}} + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + + KEEP (*crtbegin*.o(.ctors)) + + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + + KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ${CONSTRUCTING+${CTOR_END}} + }" +DTOR=".dtors ${CONSTRUCTING-0} : + { + ${CONSTRUCTING+${DTOR_START}} + KEEP (*crtbegin*.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ${CONSTRUCTING+${DTOR_END}} + }" +STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : + { + ${RELOCATING+_stack = .;} + *(.stack) + }" + +# if this is for an embedded system, don't add SIZEOF_HEADERS. +if [ -z "$EMBEDDED" ]; then + test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS" +else + test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}" +fi + +cat < + + * ld-undefined/undefined.exp: XFAIL the undefined test + * ld-mep: New, with content. + 2007-02-05 H.J. Lu * ld-i386/pcrel16.d: Undo the last change. diff --git a/ld/testsuite/ld-mep/mep.exp b/ld/testsuite/ld-mep/mep.exp new file mode 100644 index 0000000000..812e407e2c --- /dev/null +++ b/ld/testsuite/ld-mep/mep.exp @@ -0,0 +1,35 @@ +# Expect script for ld-mep 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Written by DJ Delorie (dj@redhat.com) +# + +# Test MeP linking for special cases. + +if ![istarget mep*-*-*] { + return +} + +set testbsrweak "MeP bsr to undefined weak function" + +if ![ld_assemble $as "$srcdir/$subdir/mep1.s" tmpdir/mep1.o] { + unresolved $testbsrweak +} else { if ![ld_simple_link $ld tmpdir/mep1 "-T$srcdir/$subdir/mep1.ld tmpdir/mep1.o"] { + fail $testbsrweak +} else { + pass $testbsrweak +} } diff --git a/ld/testsuite/ld-mep/mep1.ld b/ld/testsuite/ld-mep/mep1.ld new file mode 100644 index 0000000000..d0a41043b6 --- /dev/null +++ b/ld/testsuite/ld-mep/mep1.ld @@ -0,0 +1,8 @@ +SECTIONS +{ + /* This is beyond the normal range of a PCREL24 (bsr) relocation. */ + . = 0x100000; + .text1 : { *(.text1) } + . = 0x900000; + .text2 : { *(.text2) } +} diff --git a/ld/testsuite/ld-mep/mep1.s b/ld/testsuite/ld-mep/mep1.s new file mode 100644 index 0000000000..ab5414f655 --- /dev/null +++ b/ld/testsuite/ld-mep/mep1.s @@ -0,0 +1,13 @@ + .weak bar + + # This will be in low memory. + .section .text1,"ax" + bsr bar + jmp bar + + # This will be in high memory. + .section .text2,"ax" + # This needs special handling + bsr bar + # This shouldn't + jmp bar diff --git a/ld/testsuite/ld-undefined/undefined.exp b/ld/testsuite/ld-undefined/undefined.exp index 07fca0571f..4fe2696734 100644 --- a/ld/testsuite/ld-undefined/undefined.exp +++ b/ld/testsuite/ld-undefined/undefined.exp @@ -119,6 +119,7 @@ set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'" # hence the xfails below. setup_xfail mcore-*-elf +setup_xfail mep-*-* setup_xfail mips-sgi-irix6* setup_xfail "sh64-*-*" -- 2.34.1