OSDN Git Service

cleanup a few things while adding support for the shared library flat file
authordavidm <davidm>
Thu, 11 Apr 2002 00:05:51 +0000 (00:05 +0000)
committerdavidm <davidm>
Thu, 11 Apr 2002 00:05:51 +0000 (00:05 +0000)
stuff.

Makefile.in
elf2flt.c
elf2flt.ld
elf2flt.movdat.ld [deleted file]
flat.h
flthdr.c
ld-elf2flt

index 89a7f7c..c7714d8 100644 (file)
@@ -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)
 
index 5acee44..7bc4e78 100644 (file)
--- a/elf2flt.c
+++ b/elf2flt.c
@@ -38,6 +38,7 @@
 #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 */
 
@@ -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<reloc_len; i++) reloc[i] = htonl(reloc[i]);
index 7835687..0f03900 100644 (file)
@@ -2,12 +2,12 @@
 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 = . ;
@@ -21,6 +21,10 @@ SECTIONS {
                *(.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
@@ -41,9 +45,9 @@ SECTIONS {
                *(.got.plt)
                *(.got)
                LONG(-1)
-               *(.rodata)
-               *(.rodata1)
-               *(.rodata.*)
+R_RODAT                *(.rodata)
+R_RODAT                *(.rodata1)
+R_RODAT                *(.rodata.*)
                *(.gnu.linkonce.r*)
                *(.data)
                *(.data1)
diff --git a/elf2flt.movdat.ld b/elf2flt.movdat.ld
deleted file mode 100644 (file)
index 6fbf8de..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-
-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
-}
diff --git a/flat.h b/flat.h
index ab0d53a..28fa5bd 100644 (file)
--- 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 */
index 6c005aa..12db066 100644 (file)
--- 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 <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 */
@@ -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));
index b2e410e..600f4c4 100755 (executable)
@@ -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 <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
@@ -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