stuff.
$(INSTALL) -m 755 $(srcdir)/ld-elf2flt $(bindir)/$(TARGET)-ld
$(INSTALL) -m 755 $(srcdir)/ld-elf2flt $(target_bindir)/ld
$(INSTALL) -m 644 $(srcdir)/elf2flt.ld $(target_libdir)
- $(INSTALL) -m 644 $(srcdir)/elf2flt.movdat.ld $(target_libdir)
#include <strings.h>
#include <unistd.h> /* Userland prototypes of the Unix std system calls */
#include <fcntl.h> /* Flag value for file handling functions */
+#include <time.h>
#include <netinet/in.h> /* Consts and structs defined by the internet system */
s->lma, s->_cooked_size, s->output_offset,
s->alignment_power, s->filepos);
}
- if (text_len != data_vma) {
- if (text_len > data_vma) {
+ if ((text_vma + text_len) != data_vma) {
+ if ((text_vma + text_len) > data_vma) {
printf("ERROR: text=%x overlaps data=%x ?\n", text_len, data_vma);
exit(1);
}
if (verbose)
printf("WARNING: data=%x does not directly follow text=%x\n",
data_vma, text_len);
- text_len = data_vma;
+ text_len = data_vma - text_vma;
}
if (bfd_get_section_contents(abs_bfd,
s->alignment_power, s->filepos);
}
- if ((text_len + data_len) != bss_vma) {
- if ((text_len + data_len) > bss_vma) {
+ if ((text_vma + text_len + data_len) != bss_vma) {
+ if ((text_vma + text_len + data_len) > bss_vma) {
printf("ERROR: text=%x + data=%x overlaps bss=%x ?\n", text_len,
data_len, bss_vma);
exit(1);
if (verbose)
printf("WARNING: bss=%x does not directly follow text=%x + data=%x(%x)\n",
bss_vma, text_len, data_len, text_len + data_len);
- data_len = bss_vma - text_len;
+ data_len = bss_vma - data_vma;
}
reloc = (unsigned long *) output_relocs (abs_bfd, symbol_table,
| (pic_with_got ? FLAT_FLAG_GOTPIC : 0)
| (compress ? (compress == 2 ? FLAT_FLAG_GZDATA : FLAT_FLAG_GZIP) : 0)
);
+ hdr.build_date = htonl((unsigned long)time(NULL));
bzero(hdr.filler, sizeof(hdr.filler));
for (i=0; i<reloc_len; i++) reloc[i] = htonl(reloc[i]);
ENTRY (_start)
MEMORY {
- flatmem : ORIGIN = 0x0, LENGTH = 0x100000
+ flatmem : ORIGIN = 0x0, LENGTH = 0xffffff
junk : ORIGIN = 0x0, LENGTH = 0x100000
}
SECTIONS {
- .text 0 : {
+ .text 0x0 : {
. = . + 4;
. = ALIGN(0x4) ;
_stext = . ;
*(.init)
*(.fini)
+W_RODAT *(.rodata)
+W_RODAT *(.rodata1)
+W_RODAT *(.rodata.*)
+
/* This is special code area at the end of the normal
text section. It contains a small lookup table at
the start followed by the code pointed to by entries
*(.got.plt)
*(.got)
LONG(-1)
- *(.rodata)
- *(.rodata1)
- *(.rodata.*)
+R_RODAT *(.rodata)
+R_RODAT *(.rodata1)
+R_RODAT *(.rodata.*)
*(.gnu.linkonce.r*)
*(.data)
*(.data1)
+++ /dev/null
-
-ENTRY (_start)
-
-MEMORY {
- flatmem : ORIGIN = 0x0, LENGTH = 0x100000
- junk : ORIGIN = 0x0, LENGTH = 0x100000
-}
-
-SECTIONS {
- .text 0 : {
- . = . + 4;
- . = ALIGN(0x4) ;
- _stext = . ;
- *(.text)
- *(.text.*)
- *(.gnu.warning)
- *(.stub)
- *(.gnu.linkonce.t*)
- *(.glue_7t)
- *(.glue_7)
- *(.init)
- *(.fini)
-
- *(.rodata)
- *(.rodata1)
- *(.rodata.*)
-
- /* This is special code area at the end of the normal
- text section. It contains a small lookup table at
- the start followed by the code pointed to by entries
- in the lookup table. */
- . = ALIGN (4) ;
- PROVIDE(__ctbp = .);
- *(.call_table_data)
- *(.call_table_text)
-
- . = ALIGN(0x10) ;
- _etext = . ;
- } > flatmem
- .data : {
- . = ALIGN(0x4) ;
- _sdata = . ;
- __data_start = . ;
- data_start = . ;
- *(.got.plt)
- *(.got)
- LONG(-1)
- *(.gnu.linkonce.r*)
- *(.data)
- *(.data1)
- *(.data.*)
- *(.gnu.linkonce.d*)
- *(.data1)
- *(.eh_frame)
- *(.gcc_except_table)
- *(.sdata)
- *(.sdata.*)
- *(.gnu.linkonce.s.*)
- *(__libc_atexit)
- *(__libc_subinit)
- *(__libc_subfreeres)
- *(.note.ABI-tag)
- . = ALIGN(4) ;
- *(.ctors.*)
- *(.ctors)
- LONG(0)
- *(.dtors.*)
- *(.dtors)
- LONG(0)
- . = ALIGN(0x10) ;
- _edata = . ;
- } > flatmem
- .bss : {
- . = ALIGN(0x4) ;
- _sbss = ALIGN(0x4) ;
- __bss_start = . ;
- *(.dynsbss)
- *(.sbss)
- *(.sbss.*)
- *(.scommon)
- *(.dynbss)
- *(.bss)
- *(.bss.*)
- *(COMMON)
- . = ALIGN(0x4) ;
- _ebss = . ;
- _end = . ;
- end = . ;
- } > flatmem
-
- .junk : {
- *(.rel*)
- *(.rela*)
- } > junk
-}
beginning of file */
unsigned long reloc_count; /* Number of relocation records */
unsigned long flags;
- unsigned long filler[6]; /* Reservered, set to zero */
+ unsigned long build_date; /* When the program/library was built */
+ unsigned long filler[5]; /* Reservered, set to zero */
};
#define FLAT_FLAG_RAM 0x0001 /* load program entirely into RAM */
/*
* A simple program to manipulate flat files
*
- * Copyright (C) 2001 SnapGear Inc, davidm@snapgear.com
+ * Copyright (C) 2001,2002 SnapGear Inc, davidm@snapgear.com
* Copyright (C) 2001 Lineo, davidm@lineo.com
*/
/****************************************************************************/
#include <stdio.h> /* Userland pieces of the ANSI C standard I/O package */
#include <unistd.h> /* Userland prototypes of the Unix std system calls */
+#include <time.h>
/* macros for conversion between host and (internet) network byte order */
#include <netinet/in.h> /* Consts and structs defined by the internet system */
new_stack = stacksize;
if (print == 1) {
+ time_t t;
+
printf("%s\n", ifile);
printf(" Magic: %4.4s\n", old_hdr.magic);
printf(" Rev: %d\n", ntohl(old_hdr.rev));
+ t = (time_t) htonl(old_hdr.build_date);
+ printf(" Build Date: %s", t?ctime(&t):"not specified\n");
printf(" Entry: 0x%x\n", ntohl(old_hdr.entry));
printf(" Data Start: 0x%x\n", ntohl(old_hdr.data_start));
printf(" Data End: 0x%x\n", ntohl(old_hdr.data_end));
# Install by renaming all m68k-elf-ld/ld to XXX.real, and put this
# script in their place.
#
-# Copyright (C) 2000, Lineo.
-# davidm@lineo.com
+# Copyright (C) 2002 David McCullough <davidm@snapgear.com>
+# Copyright (C) 2000, Lineo. davidm@lineo.com
#
LINKER="$0.real" # the original renamed-linker
ELF2FLT="`expr $0 : '\(.*\)ld'`elf2flt"
TOOLDIR="`dirname $0`" # let gcc find the tools for us
+SHARED_ID=""
+NEWLDSCRIPT=""
#
# if we have the elf2flt options, run it
-move-rodata)
MOVDAT="y";; # Put rodata in ROM if possible
+
+ -shared-lib-id)
+ shift; SHARED_ID="$1";; # Shared library ID
-o) shift; OFILE="$1";; # the final outfile
-o*) OFILE="`expr \"$1\" : '-o\(.*\)'`";;
if [ "$FINAL" = "yes" ]
then
+ NEWLDSCRIPT=`mktemp /tmp/flt-XXXXXX`
+ SEDOP=" -e s/^R_RODAT// -e /^W_RODAT/d"
if [ "$MOVDAT" ]
then
$LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $?
then
echo "warning: .rodata section contains relocations"
else
- [ -z "$LDSCRIPT" ] && LDSCRIPT="elf2flt.movdat.ld"
+ SEDOP="-e /^R_RODAT/d -e s/^W_RODAT//"
fi
fi
+ if [ "$SHARED_ID" ]
+ then
+ # Massage the linker script into something useful. These
+ # regexps are ugly due to some bizzare shell quoting rules.
+ # SEDOP="$SEDOP -e \"s/ORIGIN = 0x0,/ORIGIN = 0x${SHARED_ID}000000,/\""
+ # SEDOP="$SEDOP -e \"s/.text 0x0 :/.text 0x${SHARED_ID}000000 :/\""
+ SEDOP="$SEDOP -e s/\\(ORIGIN.=.0\\)x0,/\\1x${SHARED_ID}000000,/"
+ SEDOP="$SEDOP -e s/\\([.]text.0\\)x0[^0-9]:/\\1x${SHARED_ID}000000:/"
+
+ if [ "$SHARED_ID" -gt 0 ]
+ then
+ # Non application modules enter via main not _start
+ # SEDOP="$SEDOP -e 's/ENTRY (_start)/ENTRY (main)/'"
+ SEDOP="$SEDOP -e s/\\(ENTRY.\\)(_start)/\1(lib_main)/"
+ fi
+
+ # Provide the magic parameter that defines the library data segment pointer offset
+ ARG1="$ARG1 -defsym _current_shared_library_a5_offset_=`expr ${SHARED_ID} '*' -4 - 4`"
+ fi
+
+ # Provide a default linker script
[ -z "$LDSCRIPT" ] && LDSCRIPT="elf2flt.ld"
+
+ # Reprocess the linker script as required.
+ # We do this in a subshell so a relatively pathed script can be found
+ ( cd /usr/local/m68k-elf/lib
+ sed $SEDOP < "$LDSCRIPT" > "$NEWLDSCRIPT"
+ )
+
$LINKER -r -d -o $OFILE.elf2flt $ARG1 || exit $?
- $LINKER $SDIRS -T $LDSCRIPT -Ur -o $OFILE.elf $OFILE.elf2flt || exit $?
- $LINKER $SDIRS -T $LDSCRIPT -o $OFILE.gdb $OFILE.elf2flt || exit $?
+ $LINKER $SDIRS -T $NEWLDSCRIPT -Ur -o $OFILE.elf $OFILE.elf2flt || exit $?
+ $LINKER $SDIRS -T $NEWLDSCRIPT -o $OFILE.gdb $OFILE.elf2flt || exit $?
rm -f $OFILE.elf2flt
if grep _GLOBAL_OFFSET_TABLE_ $OFILE.gdb > /dev/null
then
$ELF2FLT $FLTFLAGS -o $OFILE -r $OFILE.elf || exit $?
fi
rm -f $OFILE.elf # not needed for any reason
+ rm -f "$NEWLDSCRIPT"
exit 0
fi