From c82eb01c2b45f580f175f6511d348a75ea41d5a7 Mon Sep 17 00:00:00 2001 From: David McCullough Date: Thu, 11 Apr 2002 00:05:51 +0000 Subject: [PATCH] cleanup a few things while adding support for the shared library flat file stuff. --- Makefile.in | 1 - elf2flt.c | 14 ++++--- elf2flt.ld | 14 ++++--- elf2flt.movdat.ld | 95 ----------------------------------------------- flat.h | 3 +- flthdr.c | 7 +++- ld-elf2flt | 46 ++++++++++++++++++++--- 7 files changed, 66 insertions(+), 114 deletions(-) delete mode 100644 elf2flt.movdat.ld diff --git a/Makefile.in b/Makefile.in index 89a7f7c..c7714d8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -51,5 +51,4 @@ install: $(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) diff --git a/elf2flt.c b/elf2flt.c index 5acee44..7bc4e78 100644 --- a/elf2flt.c +++ b/elf2flt.c @@ -38,6 +38,7 @@ #include #include /* Userland prototypes of the Unix std system calls */ #include /* Flag value for file handling functions */ +#include #include /* Consts and structs defined by the internet system */ @@ -926,15 +927,15 @@ int main(int argc, char *argv[]) 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, @@ -958,8 +959,8 @@ int main(int argc, char *argv[]) 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); @@ -967,7 +968,7 @@ int main(int argc, char *argv[]) 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, @@ -991,6 +992,7 @@ int main(int argc, char *argv[]) | (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 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 -} diff --git a/flat.h b/flat.h index ab0d53a..28fa5bd 100644 --- a/flat.h +++ b/flat.h @@ -33,7 +33,8 @@ struct flat_hdr { 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 */ diff --git a/flthdr.c b/flthdr.c index 6c005aa..12db066 100644 --- a/flthdr.c +++ b/flthdr.c @@ -2,13 +2,14 @@ /* * 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 /* Userland pieces of the ANSI C standard I/O package */ #include /* Userland prototypes of the Unix std system calls */ +#include /* macros for conversion between host and (internet) network byte order */ #include /* Consts and structs defined by the internet system */ @@ -102,9 +103,13 @@ process_file(char *ifile, char *ofile) 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)); diff --git a/ld-elf2flt b/ld-elf2flt index b2e410e..600f4c4 100755 --- a/ld-elf2flt +++ b/ld-elf2flt @@ -9,13 +9,15 @@ # 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 +# 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 @@ -41,6 +43,9 @@ then -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\(.*\)'`";; @@ -69,6 +74,8 @@ then 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 $? @@ -77,13 +84,41 @@ then 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 @@ -92,6 +127,7 @@ 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 -- 2.39.5