[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GNU DLD



Hello,

here are my patches for GNU dld 3.2.3. I just had a look at it
yesterday evening again (after not looking into it for nearly two
years).

My port supports dynamic linking for GCC w/o -mshort and/or
-mbaserel. Supported for -mshort could probably easily be added (but I
had no use for that), while support for -mbaserel definitely needs a
lot of work (and I suspect even changes in the GCC compiler :-( ).

The main issue of the port was to add support for a DRI (or better
GST) style symbol table on the executable.

The port works on the supplied tests, except of reload and
general. The reload test would require linking with the -r option
which is not supported by gcc-ld on the ST (at least as I remember)
and also relies crucially on the Unix sbrk semantics (so there is no
hope at all for getting this to run under MiNT).
The general test complains about some duplicate symbols when loading
libdld.a dynamically. I didn't track down the problem (the test does
not tell you about which symbols dld complains :-( ), as the other
features of dld did work and I could perfectly well live without
loading libdld.a dynamically.
(If anybody is interested, I used dld to support dynamic loading under
scm and it worked well for me; but don't ask for details, its nearly
two years ago that I worked with it :-)

Regards
Wolfgang

diff -u -r /tmp/dld-3.2.3/Makefile ./Makefile
--- /tmp/dld-3.2.3/Makefile	Thu May 30 09:13:48 1991
+++ ./Makefile	Wed Dec  8 18:34:28 1993
@@ -4,14 +4,13 @@
 	remove.o error.o
 INCLUDE = dld.h defs.h
 CC= gcc
-CFLAGS = -g -I.
+CFLAGS = -g -I. -O2
 
 all:	${ARCHIVE}
 
 libdld.a: ${LIBS} ${INCLUDES}
 	rm -f libdld.a
-	ar q libdld.a ${LIBS}
-	ranlib libdld.a
+	gcc-ar qs libdld.a ${LIBS}
 
 clean:
 	rm -f ${ARCHIVE} *.o
diff -u -r /tmp/dld-3.2.3/defs.h ./defs.h
--- /tmp/dld-3.2.3/defs.h	Thu May 30 09:13:50 1991
+++ ./defs.h	Fri Aug 13 10:31:54 1993
@@ -19,8 +19,13 @@
    later version. */
 
 
+#ifdef atarist
+#include <gnu-out.h>
+#include <gnu-ar.h>
+#else
 #include <a.out.h>
 #include <ar.h>
+#endif
 #include <stdio.h>
 #include <sys/types.h>
 #include <strings.h>
diff -u -r /tmp/dld-3.2.3/dld.c ./dld.c
--- /tmp/dld-3.2.3/dld.c	Thu May 30 09:13:30 1991
+++ ./dld.c	Fri Dec 10 11:21:50 1993
@@ -60,12 +60,7 @@
 
 #ifdef atarist
 #include <basepage.h>
-/* _initial_stack determines the amount of memory available as stack/heap,  */
-/* if it's negative this is the amount available to the system, 1L means    */
-/* use a ratio of 1:3 (stack:system), 2L means ratio 1:1, 3L stands for 3:1 */
-static char __patch_str[] = "{PatchVar}stack = %ld bytes";
-extern long _initial_stack = - 100 * 1024L;
-#endif /* atarist */
+#endif
 
 /* Ordinary 4.3 bsd lacks these macros in a.out.h */
     
@@ -426,15 +421,99 @@
 	fatal (DLD_ENOSTRINGS);
 
     bzero (loc, sizeof (struct exec));
-    loc->a_magic = NMAGIC;	/* flag different header size */
+    loc->a_info = NMAGIC;	/* flag different header size */
     loc->a_text = file_header.a_text;
     loc->a_data = file_header.a_data;
     loc->a_bss = file_header.a_bss;
-    loc->a_syms = file_header.a_syms - file_header.a_AZero2;
+    loc->a_syms = file_header.a_syms;
     entry->header_read_flag = 1;
 } /* st_read_header */
+
+/* Read the symbols of executable file ENTRY into core.
+   Assume it is already open, on descriptor DESC
+   Convert the symbol table into Un*x format symbol and string tables */
+
+static void
+st_read_symbols (desc, entry)
+struct file_entry *entry;
+int desc;
+{
+    long  i, n_syms;
+    struct asym *symbols, *sp;
+    struct nlist *sym;
+    char *cp;
+    int j, type;
+
+    if (!entry->header_read_flag)
+	st_read_header (desc, entry);
+
+    if (entry->header.a_syms <= 0)
+	fatal (DLD_ENOSYMBOLS);
+
+    symbols = (struct asym *) _dld_malloc (entry->header.a_syms);
+
+    lseek (desc, A_SYMOFF (entry->header) + entry->starting_offset, 0);
+    if (entry->header.a_syms !=
+	read (desc, symbols, entry->header.a_syms)) {
+	    free (symbols);
+	    fatal (DLD_ENOSYMBOLS);
+    }
+
+    /* the following allocations go for worst case assumption, i.e.,
+       assuming every symbol table entry is used for entry->symbols and
+       assuming every second symbol table entry is used with GST long format
+       names of 24 characters (plus final '\0') each for symbol->string.
+       Note that thed latter string table array will be discarded after
+       the file has been loaded. */
+    n_syms = entry->header.a_syms / sizeof(struct asym);
+    sym = entry->symbols = (struct nlist *) _dld_malloc (n_syms * sizeof(struct nlist));
+    cp = entry->strings = (char *) _dld_malloc (n_syms / 2 * 25);
+
+    for (i = 0, sp = symbols; i < n_syms; sp++)
+    {
+	if (sp->a_type & A_TEXT)
+	    sym->n_type = N_TEXT;
+	else if (sp->a_type & A_DATA)
+	    sym->n_type = N_DATA;
+	else if (sp->a_type & A_BSS)
+	    sym->n_type = N_BSS;
+	else if (sp->a_type & A_EXT)
+	    sym->n_type = N_UNDF;
+	else if (sp->a_type & A_EQU)
+	    sym->n_type = N_ABS;
+	else {
+	    n_syms--;
+	    if ((sp->a_type & A_LNAM) == A_LNAM && i < n_syms - 1)
+		n_syms--, sp++;
+	    continue;
+	}
+	if (sp->a_type & A_GLOBL)
+	    sym->n_type |= N_EXT;
+	sym->n_value = sp->a_value;
+	sym->n_un.n_strx = cp - entry->strings;
+	for (j = 0; j < 8; j++)
+	    if ((*cp++ = sp->a_name[j]) == '\0')
+		break;
+	if ((sp->a_type & A_LNAM) == A_LNAM && i < n_syms - 1) {
+	    n_syms--, sp++;
+	    if (j == 8)
+		for (j = 0; j < sizeof(struct asym); j++)
+		    if ((*cp++ = sp->a_name[j]) == '\0')
+			break;
+		if (j == sizeof(struct asym))
+		    *cp++ = '\0';
+	}
+	else if (j == 8)
+	    *cp++ = '\0';
+	i++, sym++;
+    }
+    free (symbols);
+    entry->header.a_syms = n_syms * sizeof(struct nlist);
+    entry->string_size = cp - entry->strings;
+} /* st_read_symbols */
 #endif /* atarist */
 
+
 /* Read the symbols of file ENTRY into core.
    Assume it is already open, on descriptor DESC.
    Also read the length of the string table, which follows the symbol table,
@@ -1559,11 +1638,17 @@
     
 #ifdef atarist
     if (!load_text || !N_BADMAG (*((struct exec *)&magicnum))) {
+	if (!load_text)
+	    st_read_symbols (desc, entry);
+	else {
+	    read_entry_symbols (desc, entry);
+	    read_entry_strings (desc, entry);
+	}
 #else
     if (!N_BADMAG (*((struct exec *)&magicnum))) {
-#endif
 	read_entry_symbols (desc, entry);
 	read_entry_strings (desc, entry);
+#endif
 	enter_file_symbols (entry);
 	free (entry->strings);
 	entry->strings = 0;
diff -u -r /tmp/dld-3.2.3/test/general/read-a.out.c ./test/general/read-a.out.c
--- /tmp/dld-3.2.3/test/general/read-a.out.c	Thu May 30 09:13:36 1991
+++ ./test/general/read-a.out.c	Fri Aug 13 12:44:42 1993
@@ -1,5 +1,10 @@
 #include <stdio.h>
+#ifdef atarist
+#include <gnu-out.h>
+#define a_magic a_info
+#else
 #include <a.out.h>
+#endif
 
 #if defined(sun) && defined(sparc)
 #define relocation_info reloc_info_sparc
diff -u -r /tmp/dld-3.2.3/test/general/test-define.c ./test/general/test-define.c
--- /tmp/dld-3.2.3/test/general/test-define.c	Thu May 30 09:13:40 1991
+++ ./test/general/test-define.c	Fri Aug 13 12:49:30 1993
@@ -1,5 +1,4 @@
-#include <dld.h>
-#include <a.out.h>    
+#include "dld.h"
 
 test_define ()
 {
diff -u -r /tmp/dld-3.2.3/test/overlay/overlay.c ./test/overlay/overlay.c
--- /tmp/dld-3.2.3/test/overlay/overlay.c	Thu May 30 09:13:40 1991
+++ ./test/overlay/overlay.c	Fri Dec 10 11:35:44 1993
@@ -26,7 +26,11 @@
        not overlayed, the max. RSS will increase. */
     
     getrusage (RUSAGE_SELF, &rusage);
+#ifdef atarist
+    printf ("MAX_RSS = %d bytes.\n", rusage.ru_maxrss);
+#else
     printf ("MAX_RSS = %d page.\n", rusage.ru_maxrss);
+#endif
 
     do {
 	register void (* func) ();
@@ -39,7 +43,11 @@
 	}
 
 	getrusage (RUSAGE_SELF, &rusage);
+#ifdef atarist
+	printf ("MAX_RSS = %d bytes.\n", rusage.ru_maxrss);
+#else
 	printf ("MAX_RSS = %d page.\n", rusage.ru_maxrss);
+#endif
 	if (dld_function_executable_p("chain")) {
 	    func = (void (*) ()) dld_get_func ("chain");
 	    (* func) ();
diff -u -r /tmp/dld-3.2.3/test/reload/Makefile ./test/reload/Makefile
--- /tmp/dld-3.2.3/test/reload/Makefile	Thu May 30 09:13:34 1991
+++ ./test/reload/Makefile	Fri Dec 10 11:50:38 1993
@@ -19,5 +19,5 @@
 	${CC} ${CFLAGS} reload.o $(LIB) -o reload
 
 reload-test: reload-test.o
-	ld -r reload-test.o /lib/libc.a -o reload-test
+	gcc-ld -r reload-test.o /usr/lib/gnu.olb -o reload-test
 

----
Wolfgang Lux
WZH Heidelberg, IBM Germany             Internet: lux@heidelbg.ibm.com
+49-6221-59-4546                        VNET:     LUX at HEIDELBG
+49-6221-59-3500 (fax)	                EARN:     LUX at DHDIBMIP