home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
gnu
/
binutils-1.8.x-src.lha
/
src
/
diffs
/
binutils-1.8.x.diffs
Wrap
Text File
|
1994-02-05
|
90KB
|
3,363 lines
diff -rc --new-file binutils-1.8.x-fsf/Makefile binutils-1.8.x-amiga/Makefile
*** binutils-1.8.x-fsf/Makefile Wed Nov 27 22:48:58 1991
--- binutils-1.8.x-amiga/Makefile Sat Feb 5 12:33:24 1994
***************
*** 19,50 ****
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
! GNUCC = gcc -O
! #CC = gcc -O
bindir=/usr/local/bin
# for BSD systems
#CFLAGS = -g
# Don't add robotussin; it won't compile on BSD or GNU systems.
# objdump is not here because it (at least used to) not compile
# on most systems (trouble with N_DATADDR). I've fixed some of
# those problems, though.
! PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
! $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
# for USG systems using COFF_ENCAPSULATE
# also, you will want to make the target libc.a (but it takes a long time)
# Note that you should leave a copy of `ar' in this directory
# after you install it, since `ranlib' will try to run it from here.
! CFLAGS = -DWYSE -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
! PROGS = ld size nm strip ar robotussin objdump ranlib gprof
! SIGNAME = signame.o
# On ALTOS systems, add -DALTOS to CFLAGS.
#it's better to move a copy of alloca into your libc than to risk getting some
#incompatiable functions from -lPW (like index()), but if you
#want to be lazy, uncomment this line
! ALLOCALIBS = -lPW
# For HP-UX systems
# Don't add robotussin; use hpxt instead.
--- 19,57 ----
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
! GNUCC = gcc -O2
bindir=/usr/local/bin
+ # for AmigaDOS systems
+ CFLAGS = -resident
+ # Don't include gprof.
+ PROGS = $(archpfx)ld $(archpfx)size \
+ $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
+ CC = gcc -O2
+ bindir=/gnu/bin
+
# for BSD systems
#CFLAGS = -g
# Don't add robotussin; it won't compile on BSD or GNU systems.
# objdump is not here because it (at least used to) not compile
# on most systems (trouble with N_DATADDR). I've fixed some of
# those problems, though.
! #PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
! # $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
# for USG systems using COFF_ENCAPSULATE
# also, you will want to make the target libc.a (but it takes a long time)
# Note that you should leave a copy of `ar' in this directory
# after you install it, since `ranlib' will try to run it from here.
! #CFLAGS = -g -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
! #PROGS = ld size nm strip ar robotussin objdump ranlib gprof
! #SIGNAME = signame.o
# On ALTOS systems, add -DALTOS to CFLAGS.
#it's better to move a copy of alloca into your libc than to risk getting some
#incompatiable functions from -lPW (like index()), but if you
#want to be lazy, uncomment this line
! #ALLOCALIBS = -lPW
# For HP-UX systems
# Don't add robotussin; use hpxt instead.
***************
*** 83,89 ****
# C++ demangler
CPLUS_DEM = $(archpfx)cplus-dem.o
! LIBS=$(MALLOC) $(ALLOCALIBS) $(SIGNAME)
all: $(PROGS)
--- 90,96 ----
# C++ demangler
CPLUS_DEM = $(archpfx)cplus-dem.o
! LIBS=$(ALLOCALIBS) $(SIGNAME)
all: $(PROGS)
***************
*** 114,120 ****
$(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
$(CC) $(CFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
$(archpfx)ranlib.o: ranlib.c
! $(CC) -c $(CFLAGS) -DAR_PROG=\"/usr/local/gnu/binutils/ar\" ranlib.c $(OUTPUT_OPTION)
$(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
$(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
--- 121,127 ----
$(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
$(CC) $(CFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
$(archpfx)ranlib.o: ranlib.c
! $(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)
$(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
$(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
***************
*** 145,150 ****
.PHONY: install
install: $(PROGS)
for file in $(PROGS); do \
! cp $$file $(bindir)/$${file}.new; \
! mv $(bindir)/$${file}.new $(bindir)/$$file; \
done
--- 152,158 ----
.PHONY: install
install: $(PROGS)
for file in $(PROGS); do \
! cp $${file} $(bindir)/$${file}.new; \
! mv $(bindir)/$${file} $(bindir)/$${file}.bak; \
! mv $(bindir)/$${file}.new $(bindir)/$${file}; \
done
diff -rc --new-file binutils-1.8.x-fsf/ar.c binutils-1.8.x-amiga/ar.c
*** binutils-1.8.x-fsf/ar.c Wed Jun 13 05:47:50 1990
--- binutils-1.8.x-amiga/ar.c Sat Feb 5 13:17:48 1994
***************
*** 992,1002 ****
--- 992,1012 ----
#endif
close (outdesc);
+ #ifndef amigados
if (!appendflag)
if (rename (tempname, archive))
pfatal_with_name (tempname);
close_archive ();
+ #else
+ /* we *have* to close the file before we rename it, because otherwise
+ * AmigaDOS will just abort with OBJECT_IN_USE_ERROR */
+ close_archive ();
+
+ if (!appendflag)
+ if (rename (tempname, archive))
+ pfatal_with_name (tempname);
+ #endif
}
void
***************
*** 1957,1962 ****
--- 1967,1973 ----
unsigned int size;
{
extern char *malloc ();
+
char *result = malloc (size);
if (result == 0)
fatal ("virtual memory exhausted", 0);
***************
*** 1969,1974 ****
--- 1980,1986 ----
unsigned int size;
{
extern char *realloc ();
+
char *result = realloc (ptr, size);
if (result == 0)
fatal ("virtual memory exhausted");
diff -rc --new-file binutils-1.8.x-fsf/cplus-dem.c binutils-1.8.x-amiga/cplus-dem.c
*** binutils-1.8.x-fsf/cplus-dem.c Wed Jun 13 05:42:34 1990
--- binutils-1.8.x-amiga/cplus-dem.c Wed Sep 22 12:45:32 1993
***************
*** 48,54 ****
#include <ctype.h>
#if !defined(sequent) && !defined(NeXT)
! #include <memory.h>
#else
#define memcpy(s1, s2, n) strncpy(s1, s2, n)
#define memcmp(s1, s2, n) strncmp(s1, s2, n)
--- 48,54 ----
#include <ctype.h>
#if !defined(sequent) && !defined(NeXT)
! /* #include <memory.h> */
#else
#define memcpy(s1, s2, n) strncpy(s1, s2, n)
#define memcmp(s1, s2, n) strncmp(s1, s2, n)
diff -rc --new-file binutils-1.8.x-fsf/ld.c binutils-1.8.x-amiga/ld.c
*** binutils-1.8.x-fsf/ld.c Wed Nov 27 22:04:14 1991
--- binutils-1.8.x-amiga/ld.c Sat Feb 5 13:32:51 1994
***************
*** 16,22 ****
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Written by Richard Stallman with some help from Eric Albert.
! Set, indirect, and warning symbol features added by Randy Smith. */
#include <ar.h>
#include <stdio.h>
--- 16,29 ----
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Written by Richard Stallman with some help from Eric Albert.
! Set, indirect, and warning symbol features added by Randy Smith.
! Support for generation of Amiga load files added by Markus Wild. */
!
! #ifdef amigados
! #ifndef STANDARD_SEARCH_DIRS
! #define STANDARD_SEARCH_DIRS "local:lib","local:os-lib","gnu:lib","gnu:os-lib"
! #endif
! #endif
#include <ar.h>
#include <stdio.h>
***************
*** 30,35 ****
--- 37,44 ----
#ifndef sony_news
#include <fcntl.h>
#endif
+ /* JPB, 7 Jun 1992: MAXNAMLEN required for long name hack. */
+ #include <dirent.h>
#if !defined(A_OUT) && !defined(MACH_O)
#define A_OUT
***************
*** 43,48 ****
--- 52,84 ----
#endif
#endif
+ #ifdef MCH_AMIGA
+ #define HUNK_INSTEAD_OF_A_OUT
+ int number_of_code_hunk,
+ number_of_data_hunk,
+ number_of_bss_hunk,
+ number_of_debug_hunk,
+ current_hunk = 0,
+ offset_of_debug_hunk,
+ amiga_symbols_only,
+ databss_together = 0,
+ numdatadata_relocs = 0,
+ output_datadata_relocs = 0,
+ datadata_relocs_offset = 0;
+ #define LONGSIZE(l) ((((l) + 3) & ~3) >> 2)
+ /* this is the private format of the debug-hunk: */
+ struct debug_hunk {
+ unsigned long id; /* Filesystem-imposed: HUNK_DEBUG (0x3f1) */
+ unsigned long len; /* "" : length in longs -> LONGSIZE(real_lenght) */
+ /* the following part is somehow a truncated exec-struct: */
+ unsigned long magic; /* should be ZMAGIC (just for fun:-)), to be recognised
+ * by the other tools as this special frame */
+ unsigned long syms; /* size of symbol-table */
+ unsigned long strs; /* size of string table */
+ /* here follows the actual data */
+ } dh;
+ #endif
+
#ifdef MACH_O
#ifndef A_OUT
#include <nlist.h>
***************
*** 104,110 ****
/* Name this program was invoked by. */
char *progname;
!
/* System dependencies */
/* Define this if names etext, edata and end should not start with `_'. */
--- 140,146 ----
/* Name this program was invoked by. */
char *progname;
!
/* System dependencies */
/* Define this if names etext, edata and end should not start with `_'. */
***************
*** 190,195 ****
--- 226,247 ----
#endif /* mc68000. */
#endif /* Sun. */
+ #ifdef amigados
+ /* same trick as with sun[23] */
+ /* Set the machine type according to the machine type of the .o files.
+ If they are all sun2 (68010), then the type of the executable is sun2.
+ If any is sun3 (68020), then the type of the executable is sun3.
+ This is consistent with the Sun loader and more useful than having
+ it depend on which machine you are on when you run ld. */
+ static int amiga_machtype = MID_SUN010;
+ #define INITIALIZE_HEADER outheader.a_machtype = amiga_machtype
+ #define READ_HEADER_HOOK(machtype) \
+ if (machtype == MID_SUN020) \
+ { \
+ amiga_machtype = MID_SUN020; \
+ }
+ #endif
+
#ifdef ALTOS
#define INITIALIZE_HEADER N_SET_MACHTYPE (outheader, M_68020)
#endif
***************
*** 368,373 ****
--- 420,426 ----
#define RELOC_MEMORY_ADD_P(r) 1
#undef RELOC_ADD_EXTRA
#define RELOC_PCREL_P(r) ((r)->r_pcrel)
+ #define RELOC_BASEREL_P(r) ((r)->r_baserel)
#define RELOC_VALUE_RIGHTSHIFT(r) 0
#define RELOC_TARGET_SIZE(r) ((r)->r_length)
#define RELOC_TARGET_BITPOS(r) 0
***************
*** 384,390 ****
#define LPREFIX 'L'
#endif
!
/* Special global symbol types understood by GNU LD. */
/* The following type indicates the definition of a symbol as being
--- 437,443 ----
#define LPREFIX 'L'
#endif
!
/* Special global symbol types understood by GNU LD. */
/* The following type indicates the definition of a symbol as being
***************
*** 531,537 ****
#endif
#endif /* not __GNU_STAB__ */
!
/* Symbol table */
/* Global symbol data is recorded in these structures,
--- 584,590 ----
#endif
#endif /* not __GNU_STAB__ */
!
/* Symbol table */
/* Global symbol data is recorded in these structures,
***************
*** 684,690 ****
symbol *edata_symbol_alt;
symbol *etext_symbol_alt;
symbol *end_symbol_alt;
!
/* Kinds of files potentially understood by the linker. */
enum file_type { IS_UNKNOWN, IS_ARCHIVE, IS_A_OUT, IS_MACH_O };
--- 737,751 ----
symbol *edata_symbol_alt;
symbol *etext_symbol_alt;
symbol *end_symbol_alt;
!
! #ifdef amigados
! symbol *sdata_symbol; /* the symbol __sdata */
! symbol *text_size_symbol;
! symbol *data_size_symbol;
! symbol *bss_size_symbol;
! symbol *datadata_reloc_symbol = 0;
! #endif
!
/* Kinds of files potentially understood by the linker. */
enum file_type { IS_UNKNOWN, IS_ARCHIVE, IS_A_OUT, IS_MACH_O };
***************
*** 820,826 ****
/* Length of that vector. */
int number_of_files;
!
/* When loading the text and data, we can avoid doing a close
and another open between members of the same library.
--- 881,887 ----
/* Length of that vector. */
int number_of_files;
!
/* When loading the text and data, we can avoid doing a close
and another open between members of the same library.
***************
*** 867,875 ****
--- 928,941 ----
#define DEFAULT_OUTPUT_STYLE OUTPUT_DEMAND_PAGED
#endif
+ #if 0
/* Descriptor for writing that file with `mywrite'. */
int outdesc;
+ #endif
+
+ /* use outstream instead of outdesc thru the whole file, it's MUCH faster.. */
+ FILE *outstream = (FILE *) 0;
/* The following are computed by `digest_symbols'. */
***************
*** 929,935 ****
int symbol_name_string_index;
int library_member_offset;
};
!
/* Record most of the command options. */
/* Address we assume the text section will be loaded at.
--- 995,1001 ----
int symbol_name_string_index;
int library_member_offset;
};
!
/* Record most of the command options. */
/* Address we assume the text section will be loaded at.
***************
*** 993,998 ****
--- 1059,1068 ----
/* Length of the vector `search_dirs'. */
int n_search_dirs;
+ /* Vector of flavors to search for. */
+ char **flavors;
+ int n_flavors;
+
/* Non zero means to create the output executable.
Cleared by nonfatal errors. */
int make_executable;
***************
*** 1007,1017 ****
--- 1077,1092 ----
struct glosym **cmdline_references;
int cl_refs_allocated;
+ /* JPB, 7 Jun 1992: Global variable needed for long name hack. */
+ static int ar_hdr_size;
+
#ifndef bcopy
void bcopy (), bzero ();
#endif
+ #ifndef __STDC__
char *malloc (), *realloc ();
void free ();
+ #endif
char *xmalloc ();
char *xrealloc ();
***************
*** 1034,1039 ****
--- 1109,1129 ----
void write_output ();
void write_header ();
void write_text ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ void write_datadata_relocs ();
+ void write_hunk_header ();
+ void conditionally_rewrite_headers ();
+ void write_bss ();
+ void init_reloc_hunk ();
+ void add_to_reloc_hunk ();
+ void write_reloc_hunk ();
+ void init_symbol_hunks ();
+ void add_to_symbol_hunk ();
+ void write_symbol_hunk ();
+ void look_for_symbols ();
+ void look_for_file_symbols ();
+ void relocate_set_vectors ();
+ #endif
void read_file_relocation ();
void write_data ();
void write_rel ();
***************
*** 1045,1051 ****
char *concat ();
char *get_file_name ();
symbol *getsym (), *getsym_soft ();
!
int
main (argc, argv)
char **argv;
--- 1135,1142 ----
char *concat ();
char *get_file_name ();
symbol *getsym (), *getsym_soft ();
! int compare_longs (), compare_strings ();
!
int
main (argc, argv)
char **argv;
***************
*** 1090,1095 ****
--- 1181,1189 ----
make_executable = 1;
force_executable = 0;
set_element_prefixes = 0;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ amiga_symbols_only = 1;
+ #endif
/* Initialize the cumulative counts of symbols. */
***************
*** 1148,1158 ****
exit (!make_executable);
}
!
void add_cmdline_ref ();
static struct option longopts[] =
{
{"d", 0, 0, 'd'},
{"dc", 0, 0, 'd'}, /* For Sun compatibility. */
{"dp", 0, 0, 'd'}, /* For Sun compatibility. */
--- 1242,1259 ----
exit (!make_executable);
}
!
void add_cmdline_ref ();
static struct option longopts[] =
{
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ {"amiga-debug-hunk", 0, 0, 'a'},
+ {"databss-together", 0, 0, 'b'},
+ {"datadata-reloc", 0, 0, 'c'},
+ {"msmall-code", 0, 0, 129}, /* ignore.. */
+ {"flavor", 1, 0, 'f'},
+ #endif
{"d", 0, 0, 'd'},
{"dc", 0, 0, 'd'}, /* For Sun compatibility. */
{"dp", 0, 0, 'd'}, /* For Sun compatibility. */
***************
*** 1224,1229 ****
--- 1325,1344 ----
number_of_files++;
break;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ case 'a':
+ amiga_symbols_only = 0;
+ break;
+
+ case 'b':
+ databss_together = 1;
+ break;
+
+ case 'c':
+ output_datadata_relocs = 1;
+ break;
+ #endif
+
case 'd':
force_common_definition = 1;
break;
***************
*** 1236,1241 ****
--- 1351,1362 ----
add_cmdline_ref (entry_symbol);
break;
+ case 'f':
+ n_flavors++;
+ flavors = (char **) xrealloc (flavors, n_flavors * sizeof (char *));
+ flavors[n_flavors - 1] = optarg;
+ break;
+
case 'l':
number_of_files++;
break;
***************
*** 1363,1368 ****
--- 1484,1494 ----
}
}
+ if (n_flavors > 1)
+ {
+ qsort (flavors, n_flavors, sizeof (char *), compare_strings);
+ }
+
if (!number_of_files)
usage ("no input files", 0);
***************
*** 1433,1439 ****
n * sizeof (char *));
}
}
!
void
add_cmdline_ref (sp)
--- 1559,1565 ----
n * sizeof (char *));
}
}
!
void
add_cmdline_ref (sp)
***************
*** 1478,1484 ****
}
return 0;
}
!
/* Convenient functions for operating on one or all files being
loaded. */
void print_file_name ();
--- 1604,1610 ----
}
return 0;
}
!
/* Convenient functions for operating on one or all files being
loaded. */
void print_file_name ();
***************
*** 1602,1609 ****
for (i = 0; i < n_search_dirs; i++)
{
! register char *string
! = concat (search_dirs[i], "/", entry->filename);
desc = open (string, O_RDONLY, 0);
if (desc > 0)
{
--- 1728,1746 ----
for (i = 0; i < n_search_dirs; i++)
{
! register char *string;
!
! string = search_dirs[i];
! if (n_flavors > 0)
! {
! int count;
! for (count = 0; count < n_flavors; count++)
! {
! string = concat (string, "/", flavors[count]);
! }
! }
! string = concat (string, "/", entry->filename);
! if (trace_files) fprintf (stderr, "Look for %s\n", string);
desc = open (string, O_RDONLY, 0);
if (desc > 0)
{
***************
*** 1678,1684 ****
}
return result;
}
!
/* Medium-level input routines for rel files. */
/* Determine whether the given ENTRY is an archive, a BSD a.out file,
--- 1815,1821 ----
}
return result;
}
!
/* Medium-level input routines for rel files. */
/* Determine whether the given ENTRY is an archive, a BSD a.out file,
***************
*** 2044,2050 ****
if (entry->strs_size != read (desc, entry->strings, entry->strs_size))
fatal_with_file ("premature end of file in strings of ", entry);
}
!
/* Read in the symbols of all input files. */
void read_file_symbols (), read_entry_symbols (), read_entry_strings ();
--- 2181,2187 ----
if (entry->strs_size != read (desc, entry->strings, entry->strs_size))
fatal_with_file ("premature end of file in strings of ", entry);
}
!
/* Read in the symbols of all input files. */
void read_file_symbols (), read_entry_symbols (), read_entry_strings ();
***************
*** 2097,2103 ****
file_close ();
}
!
/* Enter the external symbol defs and refs of ENTRY in the hash table. */
void
--- 2234,2240 ----
file_close ();
}
!
/* Enter the external symbol defs and refs of ENTRY in the hash table. */
void
***************
*** 2375,2381 ****
return 0;
}
!
/* Searching libraries */
struct file_entry *decode_library_subfile ();
--- 2512,2518 ----
return 0;
}
!
/* Searching libraries */
struct file_entry *decode_library_subfile ();
***************
*** 2452,2459 ****
--- 2589,2621 ----
&& hdr1.ar_name[namelen] != '/';
namelen++);
+ /* JPB, 7 Jun 1992: Support for long file names. Set the global variable
+ ar_hdr_size to the real length of the header.
+ The code for extracting the long name is pretty much stolen
+ from the BSD ar (archive.c, version 5.7).
+ This is a *really* ugly hack!
+ */
+ #if 1
+ ar_hdr_size = sizeof(struct ar_hdr);
+ if (!bcmp(hdr1.ar_name,AR_EFMT1,sizeof(AR_EFMT1) -1))
+ {
+ namelen = atoi(hdr1.ar_name + sizeof(AR_EFMT1) -1);
+ if (namelen <= 0 || namelen > MAXNAMLEN)
+ fatal_with_file("malformatted long name of archive member in ",library_entry);
+ ar_hdr_size += namelen;
+ name = (char *) xmalloc (namelen+1);
+ if (read(desc,name,namelen) != namelen)
+ fatal_with_file("malformatted long name of archive member in ",library_entry);
+ }
+ else
+ {
+ name = (char *) xmalloc (namelen+1);
+ strncpy (name, hdr1.ar_name, namelen);
+ }
+ #else
name = (char *) xmalloc (namelen+1);
strncpy (name, hdr1.ar_name, namelen);
+ #endif
name[namelen] = 0;
subentry->filename = name;
***************
*** 2461,2467 ****
--- 2623,2633 ----
subentry->symbols = 0;
subentry->strings = 0;
subentry->subfiles = 0;
+ #if 1
+ subentry->starting_offset = subfile_offset + ar_hdr_size;
+ #else
subentry->starting_offset = subfile_offset + sizeof hdr1;
+ #endif
subentry->superfile = library_entry;
subentry->library_flag = 0;
subentry->header_read_flag = 0;
***************
*** 2473,2479 ****
return subentry;
}
!
int subfile_wanted_p ();
/* Search a library that has a __.SYMDEF member.
--- 2639,2645 ----
return subentry;
}
!
int subfile_wanted_p ();
/* Search a library that has a __.SYMDEF member.
***************
*** 2622,2628 ****
free (symdef_data);
}
!
/* Handle a subentry for a file with no __.SYMDEF. */
--- 2788,2794 ----
free (symdef_data);
}
!
/* Handle a subentry for a file with no __.SYMDEF. */
***************
*** 2675,2685 ****
if (!subentry) return;
process_subentry (desc, subentry, entry, &prev);
this_subfile_offset += member_length + sizeof (struct ar_hdr);
if (this_subfile_offset & 1) this_subfile_offset++;
}
}
!
/* ENTRY is an entry for a library member.
Its symbols have been read into core, but not entered.
Return nonzero if we ought to load this member. */
--- 2841,2859 ----
if (!subentry) return;
process_subentry (desc, subentry, entry, &prev);
+ #if 1
+ /* JPB, 7 Jun 1992: Can't count on sizeof(ar_hdr) to be the size of the entire
+ header: Long names extends the header. This is a *really*
+ ugly hack, using a global variable! */
+
+ this_subfile_offset += member_length + ar_hdr_size;
+ #else
this_subfile_offset += member_length + sizeof (struct ar_hdr);
+ #endif
if (this_subfile_offset & 1) this_subfile_offset++;
}
}
!
/* ENTRY is an entry for a library member.
Its symbols have been read into core, but not entered.
Return nonzero if we ought to load this member. */
***************
*** 2777,2783 ****
return 0;
}
!
void consider_file_section_lengths (), relocate_file_addresses ();
/* Having entered all the global symbols and found the sizes of sections
--- 2951,2957 ----
return 0;
}
!
void consider_file_section_lengths (), relocate_file_addresses ();
/* Having entered all the global symbols and found the sizes of sections
***************
*** 2800,2806 ****
--- 2974,2984 ----
initialize_text_start ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ text_size = 0;
+ #else
text_size = text_header_size;
+ #endif
/* Compute total size of sections */
***************
*** 2809,2825 ****
--- 2987,3023 ----
/* If necessary, pad text section to full page in the file.
Include the padding in the text segment size. */
+ #ifndef HUNK_INSTEAD_OF_A_OUT
if (output_style == OUTPUT_READONLY_TEXT || output_style == OUTPUT_DEMAND_PAGED)
{
text_pad = ((text_size + page_size - 1) & (- page_size)) - text_size;
text_size += text_pad;
}
+ #endif
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* they go into text if they are required */
+ if (output_datadata_relocs && numdatadata_relocs)
+ {
+ if (datadata_reloc_symbol)
+ datadata_reloc_symbol->value = text_size;
+
+ /* 1 long for the size, then the vector */
+ text_size += (1 + numdatadata_relocs) * 4;
+ }
+ #endif
/* Now that the text_size is known, initialize the data start address;
this depends on text_size as well as the output file format. */
initialize_data_start ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ data_pad = 0;
+ #endif
+
+
+ #ifndef HUNK_INSTEAD_OF_A_OUT
/* Make sure bss starts out aligned as much as anyone can want. */
{
int new_data_size = (data_size + sizeof(double) - 1) & ~(sizeof(double)-1);
***************
*** 2827,2832 ****
--- 3025,3031 ----
data_pad += new_data_size - data_size;
data_size = new_data_size;
}
+ #endif
/* Set up the set element vector */
***************
*** 2836,2843 ****
--- 3035,3049 ----
for each symbol for the length word at the beginning of the
vector, plus a word for each symbol for a zero at the end of
the vector (for incremental linking). */
+ #if 0
+ /* I think this is the other way round !? ### mw */
+
set_sect_size
= (2 * set_symbol_count + set_vector_count) * sizeof (unsigned long);
+ #else
+ set_sect_size
+ = (2 * set_vector_count + set_symbol_count) * sizeof (unsigned long);
+ #endif
set_sect_start = data_start + data_size;
data_size += set_sect_size;
set_vectors = (unsigned long *) xmalloc (set_sect_size);
***************
*** 2931,2937 ****
--- 3137,3149 ----
+ (align - 1)) & (- align))
- data_size - data_start);
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ sp->value = bss_size;
+ if (databss_together)
+ sp->value += data_start + data_size;
+ #else
sp->value = data_start + data_size + bss_size;
+ #endif
sp->defined = N_BSS | N_EXT;
bss_size += com;
if (write_map)
***************
*** 2994,2999 ****
--- 3206,3224 ----
etext_symbol_alt->value = etext_value;
}
+ #ifdef amigados
+ {
+ if (sdata_symbol)
+ sdata_symbol->value = data_start;
+ if (text_size_symbol)
+ text_size_symbol->value = text_size;
+ if (data_size_symbol)
+ data_size_symbol->value = data_size;
+ if (bss_size_symbol)
+ bss_size_symbol->value = bss_size;
+ }
+ #endif
+
{
int edata_value = data_start + data_size;
if (edata_symbol)
***************
*** 3013,3021 ****
--- 3238,3248 ----
if (specified_data_size && specified_data_size > data_size)
data_pad_additional = specified_data_size - data_size;
+ #ifndef HUNK_INSTEAD_OF_A_OUT
if (output_style == OUTPUT_DEMAND_PAGED)
data_pad_additional =
((data_pad_additional + data_size + page_size - 1) & (- page_size)) - data_size;
+ #endif
bss_size -= data_pad_additional;
if (bss_size < 0) bss_size = 0;
***************
*** 3024,3031 ****
data_pad += data_pad_additional;
}
}
!
/* Accumulate the section sizes of input file ENTRY
into the section sizes of the output file. */
--- 3251,3290 ----
data_pad += data_pad_additional;
}
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* if there is some code, assign it next hunk_number */
+ if (text_size)
+ number_of_code_hunk = current_hunk++;
+ else
+ number_of_code_hunk = -1;
+
+ if (data_size)
+ number_of_data_hunk = current_hunk++;
+ else
+ number_of_data_hunk = -1;
+
+ if (bss_size)
+ number_of_bss_hunk = current_hunk++;
+ else
+ number_of_bss_hunk = -1;
+
+ if (databss_together)
+ {
+ if (data_size && bss_size)
+ {
+ current_hunk --;
+ number_of_bss_hunk = number_of_data_hunk;
+ }
+ }
+
+ if (strip_symbols != STRIP_ALL && !amiga_symbols_only)
+ number_of_debug_hunk = current_hunk++;
+ else
+ number_of_debug_hunk = -1;
+ #endif
}
!
/* Accumulate the section sizes of input file ENTRY
into the section sizes of the output file. */
***************
*** 3046,3051 ****
--- 3305,3334 ----
text_reloc_size += entry->text_reloc_size;
data_reloc_size += entry->data_reloc_size;
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ if (! output_datadata_relocs)
+ return;
+
+ /* have to guess at how many datadata-relocs we might have. This number
+ is larger than the real thing, because I have to include the references
+ to UNDF symbols as well. */
+ {
+ struct relocation_info *r, *re, *reloc;
+ int desc = file_open (entry);
+
+ reloc = (struct relocation_info *) alloca (entry->data_reloc_size);
+ lseek (desc, entry->starting_offset + entry->data_reloc_offset, L_SET);
+ if (entry->data_reloc_size != read (desc, reloc, entry->data_reloc_size))
+ fatal_with_file ("premature eof in data relocation of ", entry);
+
+ for (r = reloc, re = reloc + entry->data_reloc_size/sizeof(*re); r < re; r++)
+ if (RELOC_EXTERN_P (r) || ((RELOC_TYPE (r) & N_TYPE) != N_TEXT))
+ numdatadata_relocs ++;
+
+ file_close ();
+ }
+ #endif
}
/* Determine where the sections of ENTRY go into the output file,
***************
*** 3062,3068 ****
for the portion of data_pad which overlaps with bss. If they had
been, we would get the wrong results here. */
entry->data_start_address += data_start;
! entry->bss_start_address += data_start + data_size;
{
register struct nlist *p;
--- 3345,3356 ----
for the portion of data_pad which overlaps with bss. If they had
been, we would get the wrong results here. */
entry->data_start_address += data_start;
!
! #ifdef HUNK_INSTEAD_OF_A_OUT
! if (databss_together)
! #endif
! entry->bss_start_address += data_start + data_size;
!
{
register struct nlist *p;
***************
*** 3080,3087 ****
case N_SETT:
p->n_value += entry->text_start_address - entry->orig_text_address;
break;
- case N_DATA:
case N_SETV:
case N_SETD:
/* Data segment symbol. Subtract the address of the
data segment in the input file, and add the address
--- 3368,3375 ----
case N_SETT:
p->n_value += entry->text_start_address - entry->orig_text_address;
break;
case N_SETV:
+ case N_DATA:
case N_SETD:
/* Data segment symbol. Subtract the address of the
data segment in the input file, and add the address
***************
*** 3098,3104 ****
}
}
}
!
void describe_file_sections (), list_file_locals ();
/* Print a complete or partial map of the output file. */
--- 3386,3392 ----
}
}
}
!
void describe_file_sections (), list_file_locals ();
/* Print a complete or partial map of the output file. */
***************
*** 3174,3180 ****
entry->strings = 0; /* All done with them. */
}
!
/* Static vars for do_warnings and subroutines of it */
int list_unresolved_refs; /* List unresolved refs */
int list_warning_symbols; /* List warning syms */
--- 3462,3468 ----
entry->strings = 0; /* All done with them. */
}
!
/* Static vars for do_warnings and subroutines of it */
int list_unresolved_refs; /* List unresolved refs */
int list_warning_symbols; /* List warning syms */
***************
*** 3192,3198 ****
struct nlist *sym;
};
- void qsort ();
/*
* Helper routines for do_file_warnings.
*/
--- 3480,3485 ----
***************
*** 3672,3678 ****
free (data_scan);
entry->strings = 0; /* Since it will dissapear anyway. */
}
!
do_warnings (outfile)
FILE *outfile;
{
--- 3959,3965 ----
free (data_scan);
entry->strings = 0; /* Since it will dissapear anyway. */
}
!
do_warnings (outfile)
FILE *outfile;
{
***************
*** 3691,3697 ****
if (list_unresolved_refs || list_multiple_defs)
make_executable = 0;
}
!
#ifdef A_OUT
/* Stuff pertaining to creating a.out files. */
--- 3978,3984 ----
if (list_unresolved_refs || list_multiple_defs)
make_executable = 0;
}
!
#ifdef A_OUT
/* Stuff pertaining to creating a.out files. */
***************
*** 3712,3717 ****
--- 3999,4009 ----
{
int magic;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ text_start = 0;
+ return;
+ #endif
+
switch (output_style)
{
case OUTPUT_RELOCATABLE:
***************
*** 3770,3775 ****
--- 4062,4072 ----
void
initialize_a_out_data_start ()
{
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ data_start = 0;
+ return;
+ #endif
+
outheader.a_text = text_size;
#ifdef sequent
outheader.a_text += N_ADDRADJ (outheader);
***************
*** 3923,3947 ****
void
write_a_out_header ()
{
! lseek (outdesc, 0L, 0);
#ifdef COFF_ENCAPSULATE
if (need_coff_header)
! mywrite (&coffheader, sizeof coffheader, 1, outdesc);
#endif
! mywrite (&outheader, sizeof (struct exec), 1, outdesc);
/* Output whatever padding is required in the executable file
between the header and the start of the text. */
#ifndef COFF_ENCAPSULATE
! padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
#endif
}
#endif
!
#ifdef MACH_O
/* Stuff pertaining to creating Mach-O files. */
--- 4220,4244 ----
void
write_a_out_header ()
{
! fseek (outstream, 0L, 0);
#ifdef COFF_ENCAPSULATE
if (need_coff_header)
! mywrite (&coffheader, sizeof coffheader, 1, outstream);
#endif
! mywrite (&outheader, sizeof (struct exec), 1, outstream);
/* Output whatever padding is required in the executable file
between the header and the start of the text. */
#ifndef COFF_ENCAPSULATE
! padfile (N_TXTOFF (outheader) - sizeof outheader, outstream);
#endif
}
#endif
!
#ifdef MACH_O
/* Stuff pertaining to creating Mach-O files. */
***************
*** 4145,4151 ****
#endif
thread_state state;
! lseek (outdesc, 0L, 0);
header.magic = MH_MAGIC;
--- 4442,4448 ----
#endif
thread_state state;
! fseek (outstream, 0L, 0);
header.magic = MH_MAGIC;
***************
*** 4251,4257 ****
#ifdef LC_SYMSEG
m_object.symseg = symseg;
#endif
! mywrite((char *) &m_object, 1, sizeof m_object, outdesc);
break;
default:
--- 4548,4554 ----
#ifdef LC_SYMSEG
m_object.symseg = symseg;
#endif
! mywrite((char *) &m_object, 1, sizeof m_object, outstream);
break;
default:
***************
*** 4305,4311 ****
#ifdef LC_SYMSEG
m_exec.symseg = symseg;
#endif
! mywrite((char *) &m_exec, 1, sizeof m_exec, outdesc);
break;
}
}
--- 4602,4608 ----
#ifdef LC_SYMSEG
m_exec.symseg = symseg;
#endif
! mywrite((char *) &m_exec, 1, sizeof m_exec, outstream);
break;
}
}
***************
*** 4386,4392 ****
}
#endif
!
/* The following functions are simple switches according to the
output style. */
--- 4683,4689 ----
}
#endif
!
/* The following functions are simple switches according to the
output style. */
***************
*** 4484,4489 ****
--- 4781,4790 ----
void
write_header ()
{
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ conditionally_rewrite_headers ();
+ return;
+ #else
#ifdef A_OUT
if (output_file_type == IS_A_OUT)
{
***************
*** 4498,4506 ****
return;
}
#endif
fatal ("unknown output file type (enum file_type)", (char *) 0);
}
!
/* Write the output file */
void
--- 4799,4808 ----
return;
}
#endif
+ #endif
fatal ("unknown output file type (enum file_type)", (char *) 0);
}
!
/* Write the output file */
void
***************
*** 4519,4540 ****
the way Unix ld works; I'm going to consider it a feature. */
(void) unlink (output_filename);
! outdesc = open (output_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
! if (outdesc < 0) perror_name (output_filename);
! if (fstat (outdesc, &statbuf) < 0)
perror_name (output_filename);
filemode = statbuf.st_mode;
chmod (output_filename, filemode & ~0111);
/* Calculate the offsets of the various pieces of the output file. */
compute_section_offsets ();
/* Output the text and data segments, relocating as we go. */
write_text ();
write_data ();
/* Output the merged relocation info, if requested with `-r'. */
if (output_style == OUTPUT_RELOCATABLE)
--- 4821,4888 ----
the way Unix ld works; I'm going to consider it a feature. */
(void) unlink (output_filename);
! outstream = fopen (output_filename, "w");
! if (outstream == 0) perror_name (output_filename);
! #ifndef MCH_AMIGA
! if (fstat (fileno (outstream), &statbuf) < 0)
perror_name (output_filename);
filemode = statbuf.st_mode;
+ /* this wouldn't work anyway, "file in use, error"... */
chmod (output_filename, filemode & ~0111);
+ #endif
+
+ /* on the Amiga, the following call DOES set the symbol offset, but
+ * it does it wrong, we'll be able to do it right, as soon as all the
+ * other data has been written.. */
/* Calculate the offsets of the various pieces of the output file. */
compute_section_offsets ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* get ready to collect information where all symbols
+ * go. Since this has to be done only once, we'll later be able to
+ * output the right symbol-hunk after the right (code/data/bss-)hunk. */
+ init_symbol_hunks ();
+ look_for_symbols ();
+ #endif
+
/* Output the text and data segments, relocating as we go. */
write_text ();
write_data ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ if (datadata_relocs_offset)
+ write_datadata_relocs ();
+
+ write_bss ();
+ if (number_of_debug_hunk != -1)
+ {
+ /* ok, lets output the start of the debug hunk */
+ fseek (outstream, 0L, SEEK_END);
+ offset_of_debug_hunk = ftell (outstream);
+
+ dh.id = 0x3f1; /* HUNK_DEBUG */
+ dh.len = 0; /* we'll fill this in later */
+ dh.magic = ZMAGIC; /* when wishes came true... */
+ dh.syms = outheader.a_syms;
+ mywrite(&dh, sizeof dh, 1, outstream);
+
+ output_syms_offset = ftell (outstream);
+ output_strs_offset = output_syms_offset + dh.syms;
+
+ /* since we later will seek forward and backward to fill in each files
+ * symbol- and string-table, we have to create the needed space, that
+ * will be seeked over, since on an empty file, lseek(fd, 10, 0) will
+ * position to byte 10 on Unix, but will just generate an error under
+ * AmigaDOS and stay at position 0. */
+
+ /* this will just write garbage, but thats enough:-)) */
+ mywrite(&output_strs_offset, dh.syms+4, 1, outstream);
+ fseek (outstream, output_syms_offset, 0);
+ }
+ #endif
/* Output the merged relocation info, if requested with `-r'. */
if (output_style == OUTPUT_RELOCATABLE)
***************
*** 4547,4568 ****
are finalized. */
compute_more_section_offsets ();
/* Copy any GDB symbol segments from input files. */
write_symsegs ();
/* Now that everything is known about the output file, write its header. */
write_header ();
! close (outdesc);
mask = umask (0);
umask (mask);
if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
perror_name (output_filename);
}
!
void modify_location (), perform_relocation (), copy_text (), copy_data ();
/* Relocate the text segment of each input file
and write to the output file. */
--- 4895,4928 ----
are finalized. */
compute_more_section_offsets ();
+ #ifndef HUNK_INSTEAD_OF_A_OUT
+ /* I don't support GDB-symbol segments, they aren't used anymore by
+ * the newer versions of gdb, BUT of course, if somebody needs them..
+ * that's exactly why I introduced the "dh.strs" Parameter, so that
+ * you could - as in Unix - append these segments at the end of the file */
+
/* Copy any GDB symbol segments from input files. */
write_symsegs ();
+ #endif
/* Now that everything is known about the output file, write its header. */
write_header ();
! fclose (outstream);
+ #ifndef HUNK_INSTEAD_OF_A_OUT
mask = umask (0);
umask (mask);
if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
perror_name (output_filename);
+ #endif
}
!
void modify_location (), perform_relocation (), copy_text (), copy_data ();
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ void write_hunk_header();
+ #endif
/* Relocate the text segment of each input file
and write to the output file. */
***************
*** 4573,4587 ****
if (trace_files)
fprintf (stderr, "Copying and relocating text:\n\n");
! lseek (outdesc, output_text_offset + text_header_size, 0);
each_full_file (copy_text, 0);
file_close ();
if (trace_files)
fprintf (stderr, "\n");
! padfile (text_pad, outdesc);
}
/* Read in all of the relocation information */
--- 4933,4987 ----
if (trace_files)
fprintf (stderr, "Copying and relocating text:\n\n");
! #ifdef HUNK_INSTEAD_OF_A_OUT
! /* this is a definitive write, we don't need to rewrite this out, since
! * the yet undefined sizes of the reloc-hunks don't go into the
! * header-hunk */
! write_hunk_header(outstream);
! init_reloc_hunk();
!
! /* and if there's no code-hunk, we can return here.. no sense in
! * complicately doing just nothing... */
! if (number_of_code_hunk == -1) return;
!
! /* else start the code-hunk */
! {
! long code_header[2];
! code_header[0] = 0x3e9;
! code_header[1] = LONGSIZE(text_size);
! mywrite(code_header, 1, sizeof code_header, outstream);
! }
! #else
! fseek (outstream, output_text_offset + text_header_size, 0);
! #endif
each_full_file (copy_text, 0);
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ if (output_datadata_relocs && numdatadata_relocs)
+ {
+ int i, zero = 0;
+ /* include the size-field, -> <= . The `real' values come later */
+ datadata_relocs_offset = ftell (outstream);
+ for (i = 0; i <= numdatadata_relocs; i ++)
+ mywrite (&zero, 1, sizeof (long), outstream);
+ }
+ #endif
+
file_close ();
if (trace_files)
fprintf (stderr, "\n");
! padfile (text_pad, outstream);
!
! #ifdef HUNK_INSTEAD_OF_A_OUT
! write_reloc_hunk();
! write_symbol_hunk(number_of_code_hunk);
! {
! long hunk_end = 0x3f2;
! mywrite(&hunk_end, 1, sizeof(long), outstream);
! }
! #endif
}
/* Read in all of the relocation information */
***************
*** 4686,4700 ****
fatal_with_file ("premature eof in text section of ", entry);
/* Relocate the text according to the text relocation. */
-
perform_relocation (bytes, entry->text_start_address - entry->orig_text_address,
entry->text_size, reloc, entry->text_reloc_size, entry);
/* Write the relocated text to the output file. */
! mywrite (bytes, 1, entry->text_size, outdesc);
}
!
/* Relocate the data segment of each input file
and write to the output file. */
--- 5086,5099 ----
fatal_with_file ("premature eof in text section of ", entry);
/* Relocate the text according to the text relocation. */
perform_relocation (bytes, entry->text_start_address - entry->orig_text_address,
entry->text_size, reloc, entry->text_reloc_size, entry);
/* Write the relocated text to the output file. */
! mywrite (bytes, 1, entry->text_size, outstream);
}
!
/* Relocate the data segment of each input file
and write to the output file. */
***************
*** 4704,4710 ****
if (trace_files)
fprintf (stderr, "Copying and relocating data:\n\n");
! lseek (outdesc, output_data_offset, 0);
each_full_file (copy_data, 0);
file_close ();
--- 5103,5126 ----
if (trace_files)
fprintf (stderr, "Copying and relocating data:\n\n");
! #ifndef HUNK_INSTEAD_OF_A_OUT
! fseek (outstream, output_data_offset, 0);
! #else
! /* just have to hope that the file is positioned correctly.. */
! init_reloc_hunk();
! /* start a data-hunk, if there is data to be output */
! if (number_of_data_hunk == -1) return;
!
! {
! long data_header[2];
! data_header[0] = 0x3ea;
! if (databss_together)
! data_header[1] = LONGSIZE(data_size + bss_size);
! else
! data_header[1] = LONGSIZE(data_size);
! mywrite(data_header, 1, sizeof data_header, outstream);
! }
! #endif
each_full_file (copy_data, 0);
file_close ();
***************
*** 4713,4725 ****
description of length of the set vector section. */
if (set_vector_count)
! mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
! sizeof (unsigned long), outdesc);
if (trace_files)
fprintf (stderr, "\n");
! padfile (data_pad, outdesc);
}
/* Read the data segment contents of ENTRY, relocate them,
--- 5129,5172 ----
description of length of the set vector section. */
if (set_vector_count)
! {
! #ifdef HUNK_INSTEAD_OF_A_OUT
! /* this and mywrite later: inverted set_symbol_count and
! * set_vector_count, guess they were mixed up before ### mw */
!
! relocate_set_vectors (set_vectors,
! 2 * set_vector_count + set_symbol_count);
! #endif
! #if 0
! mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
! sizeof (unsigned long), outstream);
! #else
! mywrite (set_vectors, 2 * set_vector_count + set_symbol_count,
! sizeof (unsigned long), outstream);
! #endif
! }
if (trace_files)
fprintf (stderr, "\n");
! padfile (data_pad, outstream);
!
! #ifdef HUNK_INSTEAD_OF_A_OUT
! if (databss_together && bss_size)
! {
! /* dump zeros */
! int i, zero = 0;
! for (i = 0; i < LONGSIZE(bss_size); i++)
! mywrite (&zero, 1, sizeof (long), outstream);
! }
!
! write_reloc_hunk();
! write_symbol_hunk(number_of_data_hunk);
! {
! long hunk_end = 0x3f2;
! mywrite(&hunk_end, 1, sizeof(long), outstream);
! }
! #endif
}
/* Read the data segment contents of ENTRY, relocate them,
***************
*** 4765,4776 ****
if (entry->data_size != read (desc, bytes, entry->data_size))
fatal_with_file ("premature eof in data section of ", entry);
! perform_relocation (bytes, entry->data_start_address - entry->orig_data_address,
! entry->data_size, reloc, entry->data_reloc_size, entry);
! mywrite (bytes, 1, entry->data_size, outdesc);
}
!
/* Relocate ENTRY's text or data section contents.
DATA is the address of the contents, in core.
DATA_SIZE is the length of the contents.
--- 5212,5227 ----
if (entry->data_size != read (desc, bytes, entry->data_size))
fatal_with_file ("premature eof in data section of ", entry);
! perform_relocation (bytes, entry->data_start_address
! #ifndef HUNK_INSTEAD_OF_A_OUT
! - entry->orig_data_address
! #endif
! ,
! entry->data_size, reloc, entry->data_reloc_size, entry);
! mywrite (bytes, 1, entry->data_size, outstream);
}
!
/* Relocate ENTRY's text or data section contents.
DATA is the address of the contents, in core.
DATA_SIZE is the length of the contents.
***************
*** 4796,4806 ****
--- 5247,5266 ----
int data_relocation = entry->data_start_address - entry->orig_data_address;
int bss_relocation = entry->bss_start_address - entry->orig_bss_address;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ int this_hunk;
+ #endif
+
for (; p < end; p++)
{
register int relocation = 0;
register int addr = RELOC_ADDRESS(p);
register unsigned int mask = 0;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ int ext_abs;
+
+ ext_abs = 0;
+ #endif
if (addr >= data_size)
fatal_with_file ("relocation address out of range in ", entry);
***************
*** 4827,4848 ****
relocation = 0;
else
relocation = sp->value;
}
else switch (RELOC_TYPE(p))
{
case N_TEXT:
case N_TEXT | N_EXT:
! relocation = text_relocation;
break;
case N_DATA:
case N_DATA | N_EXT:
! relocation = data_relocation;
break;
case N_BSS:
case N_BSS | N_EXT:
! relocation = bss_relocation;
break;
case N_ABS:
--- 5287,5366 ----
relocation = 0;
else
relocation = sp->value;
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ if ((sp->defined & ~N_EXT) == N_ABS)
+ /* sort of a kludge.. the only external symbol (not pcrelative)
+ * we can really resolve.. */
+ ext_abs = 1;
+ else if ((sp->defined & ~N_EXT) == N_TEXT ||
+ (sp->defined & ~N_EXT) == N_SETT)
+ {
+ this_hunk = number_of_code_hunk;
+ if (RELOC_BASEREL_P (p))
+ {
+ fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
+ p->r_symbolnum, p->r_extern, p->r_address);
+ fatal_with_file ("base relative text relocation in ", entry);
+ }
+ }
+ else if ((sp->defined & ~N_EXT) == N_DATA ||
+ (sp->defined & ~N_EXT) == N_SETD ||
+ (sp->defined & ~N_EXT) == N_SETV)
+ {
+ this_hunk = number_of_data_hunk;
+ }
+ else if ((sp->defined & ~N_EXT) == N_BSS ||
+ (sp->defined & ~N_EXT) == N_UNDF ||
+ (sp->defined & ~N_EXT) == N_SETB)
+ {
+ this_hunk = number_of_bss_hunk;
+ }
+ else
+ fatal_with_file ("external symbol with unknown type $%x in ", entry, sp->defined);
+ #endif
}
else switch (RELOC_TYPE(p))
{
case N_TEXT:
case N_TEXT | N_EXT:
! if (RELOC_BASEREL_P (p))
! {
! fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
! p->r_symbolnum, p->r_extern, p->r_address);
! fatal_with_file ("base relative text relocation in ", entry);
! }
! else
! relocation = text_relocation;
! #ifdef HUNK_INSTEAD_OF_A_OUT
! this_hunk = number_of_code_hunk;
! #endif
break;
case N_DATA:
case N_DATA | N_EXT:
! #ifdef HUNK_INSTEAD_OF_A_OUT
! if (RELOC_BASEREL_P (p))
! relocation = entry->data_start_address;
! else
! #endif
! relocation = data_relocation;
! #ifdef HUNK_INSTEAD_OF_A_OUT
! this_hunk = number_of_data_hunk;
! #endif
break;
case N_BSS:
case N_BSS | N_EXT:
! #ifdef HUNK_INSTEAD_OF_A_OUT
! if (RELOC_BASEREL_P (p))
! relocation = entry->bss_start_address - entry->data_size;
! else
! #endif
! relocation = bss_relocation;
! #ifdef HUNK_INSTEAD_OF_A_OUT
! this_hunk = number_of_bss_hunk;
! #endif
break;
case N_ABS:
***************
*** 4854,4862 ****
--- 5372,5405 ----
fatal_with_file ("nonexternal relocation code invalid in ", entry);
}
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* in this case, ONLY relocate those pc-relative 32bit jumps, that
+ * gas generates, since they are position independent, this gives
+ * a HUGE.. 'if' inside of '#ifdef' oh well... */
+ if (RELOC_PCREL_P(p) || RELOC_BASEREL_P(p) || ext_abs) {
+
+ /* VERY BIG KLUDGE AHEAD! Since this amiga hunk format is really
+ * limited, 8bit and 16bit references are always defined to be
+ * pc-relative (according to the AmigaDOS RM 2nd ed). BUT if such
+ * a symbol is resolved by an absolute symbol then it's not considered
+ * to be pc-relative any more. This is nowhere documented, but you
+ * couldn't get
+ * jsr _LVOOpen(a6)
+ * to work if you wouldn't do it this way. */
+ if (ext_abs) RELOC_PCREL_P(p) = 0;
+
+ #endif
if (RELOC_PCREL_P(p))
relocation -= pc_relocation;
+ /* if base relative, subtract 64k/2, so we get a larger range */
+ if (RELOC_BASEREL_P(p))
+ {
+ if (! databss_together)
+ fatal_with_file ("Reloc is base relative. Specify -databss-together in ", entry);
+ relocation -= 0x7ffe;
+ }
+
#ifdef RELOC_ADD_EXTRA
relocation += RELOC_ADD_EXTRA(p);
if (output_style == OUTPUT_RELOCATABLE)
***************
*** 4895,4901 ****
/* Shift everything up to where it's going to be used */
relocation <<= RELOC_TARGET_BITPOS(p);
mask <<= RELOC_TARGET_BITPOS(p);
-
switch (RELOC_TARGET_SIZE(p))
{
case 0:
--- 5438,5443 ----
***************
*** 4903,4920 ****
--- 5445,5483 ----
relocation -= mask & *(char *) (data + addr);
else if (RELOC_MEMORY_ADD_P(p))
relocation += mask & *(char *) (data + addr);
+ if (relocation < -128 || relocation > 127)
+ fatal_with_file ("Byte reloc overflow in ", entry);
+
*(char *) (data + addr) &= ~mask;
*(char *) (data + addr) |= relocation;
break;
case 1:
+ {
+ int r=relocation;
+
if (RELOC_MEMORY_SUB_P(p))
relocation -= mask & *(short *) (data + addr);
else if (RELOC_MEMORY_ADD_P(p))
relocation += mask & *(short *) (data + addr);
+
+ if (relocation < -32768 || relocation > 32767)
+ {
+ fprintf (stderr, "relocation = $%lx, bsr = %d, pcr = %d, r= $%lx\n",
+ relocation, RELOC_BASEREL_P(p), RELOC_PCREL_P (p), r);
+ fprintf (stderr, "textr = $%x, datar = $%x, bssr = $%x\n",
+ text_relocation, data_relocation, bss_relocation);
+ fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
+ p->r_symbolnum, p->r_extern, p->r_address);
+ fprintf (stderr, "data_size = %d, bss_size = %d.\n",
+ data_size, bss_size);
+ fatal_with_file ("Word reloc overflow in ", entry);
+ }
+
*(short *) (data + addr) &= ~mask;
*(short *) (data + addr) |= relocation;
break;
+ }
case 2:
#ifdef CROSS_LINKER
***************
*** 4937,4942 ****
--- 5500,5506 ----
relocation -= mask & *(long *) (data + addr);
else if (RELOC_MEMORY_ADD_P(p))
relocation += mask & *(long *) (data + addr);
+
*(long *) (data + addr) &= ~mask;
*(long *) (data + addr) |= relocation;
#endif /* not CROSS_LINKER */
***************
*** 4945,4953 ****
default:
fatal_with_file ("Unimplemented relocation field length in ", entry);
}
}
}
!
/* For OUTPUT_RELOCATABLE only: write out the relocation,
relocating the addresses-to-be-relocated. */
--- 5509,5535 ----
default:
fatal_with_file ("Unimplemented relocation field length in ", entry);
}
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* now finish this huge 'if' .. */
+ }
+ else
+ {
+ /* this only deals with 32bit relocs, the Amiga-loader
+ * doesn't support 1 or 2 byte relocs, they are only defined
+ * inside program-units (commonly known as object-files:-)) */
+
+ if (RELOC_TARGET_SIZE(p) != 2)
+ fatal_with_file ("unsupported reloc-size in ", entry);
+
+ *(long *) (data + addr) += relocation;
+ addr += pc_relocation;
+ add_to_reloc_hunk(this_hunk, addr);
+ }
+ #endif
}
}
!
/* For OUTPUT_RELOCATABLE only: write out the relocation,
relocating the addresses-to-be-relocated. */
***************
*** 4995,5007 ****
/* Write out the relocations of all files, remembered from copy_text. */
! lseek (outdesc, output_trel_offset, 0);
each_full_file (coptxtrel, 0);
if (trace_files)
fprintf (stderr, "\nWriting data relocation:\n\n");
! lseek (outdesc, output_drel_offset, 0);
each_full_file (copdatrel, 0);
if (trace_files)
--- 5577,5589 ----
/* Write out the relocations of all files, remembered from copy_text. */
! fseek (outstream, output_trel_offset, 0);
each_full_file (coptxtrel, 0);
if (trace_files)
fprintf (stderr, "\nWriting data relocation:\n\n");
! fseek (outstream, output_drel_offset, 0);
each_full_file (copdatrel, 0);
if (trace_files)
***************
*** 5076,5082 ****
entry->text_reloc_size / sizeof (struct relocation_info));
#endif
! mywrite (entry->textrel, 1, entry->text_reloc_size, outdesc);
}
void
--- 5658,5664 ----
entry->text_reloc_size / sizeof (struct relocation_info));
#endif
! mywrite (entry->textrel, 1, entry->text_reloc_size, outstream);
}
void
***************
*** 5155,5163 ****
entry->data_reloc_size / sizeof (struct relocation_info));
#endif
! mywrite (entry->datarel, 1, entry->data_reloc_size, outdesc);
}
!
void write_file_syms ();
void write_string_table ();
--- 5737,5745 ----
entry->data_reloc_size / sizeof (struct relocation_info));
#endif
! mywrite (entry->datarel, 1, entry->data_reloc_size, outstream);
}
!
void write_file_syms ();
void write_string_table ();
***************
*** 5192,5199 ****
return index;
}
- FILE *outstream = (FILE *) 0;
-
/* Write the contents of `strtab_vector' into the string table.
This is done once for each file's local&debugger symbols
and once for the global symbols. */
--- 5774,5779 ----
***************
*** 5203,5212 ****
{
register int i;
! lseek (outdesc, output_strs_offset + output_strs_size, 0);
if (!outstream)
outstream = fdopen (outdesc, "w");
for (i = 0; i < strtab_index; i++)
{
--- 5783,5794 ----
{
register int i;
! fseek (outstream, output_strs_offset + output_strs_size, 0);
+ #if 0
if (!outstream)
outstream = fdopen (outdesc, "w");
+ #endif
for (i = 0; i < strtab_index; i++)
{
***************
*** 5220,5226 ****
if (ferror (outstream))
perror_name (output_filename);
}
!
/* Write the symbol table and string table of the output file. */
void
--- 5802,5808 ----
if (ferror (outstream))
perror_name (output_filename);
}
!
/* Write the symbol table and string table of the output file. */
void
***************
*** 5248,5253 ****
--- 5830,5841 ----
/* Pointer for storing into BUF. */
register struct nlist *bufp = buf;
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* this enables us to output "regular" amiga symbols without
+ * the BSD-like debug-hunk */
+ if (number_of_debug_hunk == -1) return;
+ #endif
+
/* Size of string table includes the bytes that store the size. */
strtab_size = sizeof strtab_size;
***************
*** 5370,5377 ****
/* Output the buffer full of `struct nlist's. */
! lseek (outdesc, output_syms_offset + output_syms_size, 0);
! mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
output_syms_size += sizeof (struct nlist) * (bufp - buf);
if (syms_written != nsyms)
--- 5958,5965 ----
/* Output the buffer full of `struct nlist's. */
! fseek (outstream, output_syms_offset + output_syms_size, 0);
! mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
output_syms_size += sizeof (struct nlist) * (bufp - buf);
if (syms_written != nsyms)
***************
*** 5380,5393 ****
/* Now the total string table size is known, so write it into the
first word of the string table. */
! lseek (outdesc, output_strs_offset, 0);
! mywrite (&strtab_size, sizeof (int), 1, outdesc);
/* Write the strings for the global symbols. */
write_string_table ();
}
!
/* Write the local and debugger symbols of file ENTRY.
Increment *SYMS_WRITTEN_ADDR for each symbol that is written. */
--- 5968,5981 ----
/* Now the total string table size is known, so write it into the
first word of the string table. */
! fseek (outstream, output_strs_offset, 0);
! mywrite (&strtab_size, sizeof (int), 1, outstream);
/* Write the strings for the global symbols. */
write_string_table ();
}
!
/* Write the local and debugger symbols of file ENTRY.
Increment *SYMS_WRITTEN_ADDR for each symbol that is written. */
***************
*** 5489,5496 ****
/* All the symbols are now in BUF; write them. */
! lseek (outdesc, output_syms_offset + output_syms_size, 0);
! mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
output_syms_size += sizeof (struct nlist) * (bufp - buf);
/* Write the string-table data for the symbols just written,
--- 6077,6084 ----
/* All the symbols are now in BUF; write them. */
! fseek (outstream, output_syms_offset + output_syms_size, 0);
! mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
output_syms_size += sizeof (struct nlist) * (bufp - buf);
/* Write the string-table data for the symbols just written,
***************
*** 5499,5505 ****
write_string_table ();
entry->strings = 0; /* Since it will dissapear anyway. */
}
!
/* Copy any GDB symbol segments from the input files to the output file.
The contents of the symbol segment is copied without change
except that we store some information into the beginning of it. */
--- 6087,6093 ----
write_string_table ();
entry->strings = 0; /* Since it will dissapear anyway. */
}
!
/* Copy any GDB symbol segments from the input files to the output file.
The contents of the symbol segment is copied without change
except that we store some information into the beginning of it. */
***************
*** 5509,5515 ****
void
write_symsegs ()
{
! lseek (outdesc, output_symseg_offset, 0);
each_file (write_file_symseg, 0);
}
--- 6097,6103 ----
void
write_symsegs ()
{
! fseek (outstream, output_symseg_offset, 0);
each_file (write_file_symseg, 0);
}
***************
*** 5544,5550 ****
/* Write the modified root into the output file. */
! mywrite (&root, sizeof root, 1, outdesc);
/* Copy the rest of the symbol segment unchanged. */
--- 6132,6138 ----
/* Write the modified root into the output file. */
! mywrite (&root, sizeof root, 1, outstream);
/* Copy the rest of the symbol segment unchanged. */
***************
*** 5557,5568 ****
if (len != min (sizeof buffer, total))
fatal_with_file ("premature end of file in symbol segment of ", entry);
total -= len;
! mywrite (buffer, len, 1, outdesc);
}
file_close ();
}
!
/* Define a special symbol (etext, edata, or end). NAME is the
name of the symbol, with a leading underscore (whether or not this
system uses such underscores). TYPE is its type (e.g. N_DATA | N_EXT).
--- 6145,6156 ----
if (len != min (sizeof buffer, total))
fatal_with_file ("premature end of file in symbol segment of ", entry);
total -= len;
! mywrite (buffer, len, 1, outstream);
}
file_close ();
}
!
/* Define a special symbol (etext, edata, or end). NAME is the
name of the symbol, with a leading underscore (whether or not this
system uses such underscores). TYPE is its type (e.g. N_DATA | N_EXT).
***************
*** 5616,5621 ****
--- 6204,6235 ----
symbol_define ("__etext", N_TEXT | N_EXT, &etext_symbol_alt);
symbol_define ("__end", N_BSS | N_EXT, &end_symbol_alt);
+ #ifdef amigados
+ if (output_datadata_relocs)
+ symbol_define ("___datadata_relocs", N_TEXT | N_EXT, &datadata_reloc_symbol);
+
+ symbol_define ("__sdata", N_DATA | N_EXT, &sdata_symbol);
+ symbol_define ("___text_size", N_ABS | N_EXT, &text_size_symbol);
+ symbol_define ("___data_size", N_ABS | N_EXT, &data_size_symbol);
+ symbol_define ("___bss_size", N_ABS | N_EXT, &bss_size_symbol);
+ {
+ symbol *a_symbol;
+ symbol_define ("___machtype", N_ABS | N_EXT, &a_symbol);
+ if (a_symbol)
+ a_symbol->value = amiga_machtype;
+
+ symbol_define ("___databss_together", N_ABS | N_EXT, &a_symbol);
+ if (a_symbol)
+ a_symbol->value = databss_together;
+
+ if (databss_together)
+ {
+ symbol_define ("___a4_init", N_DATA | N_EXT, &a_symbol);
+ if (a_symbol)
+ a_symbol->value = data_start + 0x7ffe;
+ }
+ }
+ #endif
#ifdef sun
{
symbol *dynamic_symbol;
***************
*** 5658,5664 ****
return k;
}
!
/* Get the symbol table entry for the global symbol named KEY.
Create one if there is none. */
--- 6272,6278 ----
return k;
}
!
/* Get the symbol table entry for the global symbol named KEY.
Create one if there is none. */
***************
*** 5725,5731 ****
return 0;
}
!
/* Report a usage error.
Like fatal except prints a usage summary. */
--- 6339,6345 ----
return 0;
}
!
/* Report a usage error.
Like fatal except prints a usage summary. */
***************
*** 5739,5750 ****
--- 6353,6374 ----
fprintf (stderr, string, arg);
fprintf (stderr, "\n");
}
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ fprintf (stderr, "\
+ Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
+ [-nostdlib] [-o file] [-r] [-s] [-t] [-u symbol] [-x] [-y symbol]\n\
+ [-z] [-A file] [-Bstatic] [-D size] [-L libdir] [-M] [-N]\n\
+ [-S] [-T[{text,data}] addr] [-V prefix] [-X] \n\
+ [{-a,-amiga-debug-hunk}] [{-f,-flavor} flavor] [file...]\n",
+ progname);
+ #else
fprintf (stderr, "\
Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
[-nostdlib] [-o file] [-r] [-s] [-t] [-u symbol] [-x] [-y symbol]\n\
[-z] [-A file] [-Bstatic] [-D size] [-L libdir] [-M] [-N]\n\
[-S] [-T[{text,data}] addr] [-V prefix] [-X] [file...]\n",
progname);
+ #endif
exit (1);
}
***************
*** 5765,5776 ****
followed by the filename of ENTRY. */
void
! fatal_with_file (string, entry)
char *string;
struct file_entry *entry;
{
fprintf (stderr, "%s: ", progname);
! fprintf (stderr, string);
print_file_name (entry, stderr);
fprintf (stderr, "\n");
exit (1);
--- 6389,6400 ----
followed by the filename of ENTRY. */
void
! fatal_with_file (string, entry, arg)
char *string;
struct file_entry *entry;
{
fprintf (stderr, "%s: ", progname);
! fprintf (stderr, string, arg);
print_file_name (entry, stderr);
fprintf (stderr, "\n");
exit (1);
***************
*** 5784,5794 ****
char *name;
{
extern int errno, sys_nerr;
- extern char *sys_errlist[];
char *s;
if (errno < sys_nerr)
! s = concat ("", sys_errlist[errno], " for %s");
else
s = "cannot open %s";
fatal (s, name);
--- 6408,6417 ----
char *name;
{
extern int errno, sys_nerr;
char *s;
if (errno < sys_nerr)
! s = concat ("", strerror (errno), " for %s");
else
s = "cannot open %s";
fatal (s, name);
***************
*** 5802,5812 ****
struct file_entry *entry;
{
extern int errno, sys_nerr;
- extern char *sys_errlist[];
char *s;
if (errno < sys_nerr)
! s = concat ("", sys_errlist[errno], " for ");
else
s = "cannot open ";
fatal_with_file (s, entry);
--- 6425,6434 ----
struct file_entry *entry;
{
extern int errno, sys_nerr;
char *s;
if (errno < sys_nerr)
! s = concat ("", strerror (errno), " for ");
else
s = "cannot open ";
fatal_with_file (s, entry);
***************
*** 5824,5840 ****
fprintf (stderr, "\n");
}
!
/* Output COUNT*ELTSIZE bytes of data at BUF
to the descriptor DESC. */
void
! mywrite (buf, count, eltsize, desc)
char *buf;
int count;
int eltsize;
! int desc;
{
register int val;
register int bytes = count * eltsize;
--- 6446,6463 ----
fprintf (stderr, "\n");
}
!
/* Output COUNT*ELTSIZE bytes of data at BUF
to the descriptor DESC. */
void
! mywrite (buf, count, eltsize, stream)
char *buf;
int count;
int eltsize;
! FILE *stream;
{
+ #if 0
register int val;
register int bytes = count * eltsize;
***************
*** 5846,5860 ****
buf += val;
bytes -= val;
}
}
! /* Output PADDING zero-bytes to descriptor OUTDESC.
PADDING may be negative; in that case, do nothing. */
void
! padfile (padding, outdesc)
int padding;
! int outdesc;
{
register char *buf;
if (padding <= 0)
--- 6469,6486 ----
buf += val;
bytes -= val;
}
+ #else
+ fwrite (buf, eltsize, count, stream);
+ #endif
}
! /* Output PADDING zero-bytes to descriptor OUTSTREAM.
PADDING may be negative; in that case, do nothing. */
void
! padfile (padding, outstream)
int padding;
! FILE *outstream;
{
register char *buf;
if (padding <= 0)
***************
*** 5862,5868 ****
buf = (char *) alloca (padding);
bzero (buf, padding);
! mywrite (buf, padding, 1, outdesc);
}
/* Return a newly-allocated string
--- 6488,6494 ----
buf = (char *) alloca (padding);
bzero (buf, padding);
! mywrite (buf, padding, 1, outstream);
}
/* Return a newly-allocated string
***************
*** 5903,5910 ****
xmalloc (size)
int size;
{
register char *result = malloc (size);
! if (!result)
fatal ("virtual memory exhausted", 0);
return result;
}
--- 6529,6537 ----
xmalloc (size)
int size;
{
+ extern char *malloc();
register char *result = malloc (size);
! if (!result && size)
fatal ("virtual memory exhausted", 0);
return result;
}
***************
*** 5916,5927 ****
char *ptr;
int size;
{
! register char *result = realloc (ptr, size);
if (!result)
fatal ("virtual memory exhausted", 0);
return result;
}
!
#ifdef USG
void
--- 6543,6555 ----
char *ptr;
int size;
{
! extern char *malloc(), *realloc();
! register char *result = ptr ? realloc (ptr, size) : malloc (size);
if (!result)
fatal ("virtual memory exhausted", 0);
return result;
}
!
#ifdef USG
void
***************
*** 5952,5954 ****
--- 6580,7214 ----
return 8192;
}
#endif
+
+ #ifdef HUNK_INSTEAD_OF_A_OUT
+ /* the whole rest of the file is used for managment of hunks and subhunks.. */
+
+ /* this is the amiga-equivalent of struct exec */
+ struct simple_hunk_header {
+ long id, /* this will be 0x3f3 */
+ zero,
+ table_size,
+ first_hunk,
+ last_hunk,
+ sizes[4]; /* there can be at most a code,data,bss & debug hunk */
+ };
+
+ /* this writes out a hunk header, depending on the information collected
+ * so far, it will only create hunks, that really exist, so if your data-
+ * size is zero, you won't get a data-hunk at all. */
+
+ void
+ write_hunk_header(outfd)
+ int outfd;
+ {
+ struct simple_hunk_header sh;
+ int this_hunk, header_size;
+
+ sh.id = 0x3f3; /* HUNK_HEADER */
+ sh.zero = 0;
+ sh.table_size = current_hunk;
+ sh.first_hunk = 0;
+ sh.last_hunk = current_hunk - 1;
+
+ this_hunk = 0;
+ if (number_of_code_hunk != -1)
+ sh.sizes[this_hunk++] = LONGSIZE(text_size);
+
+ if (number_of_data_hunk != -1)
+ sh.sizes[this_hunk++] = databss_together
+ ? LONGSIZE(data_size + bss_size) : LONGSIZE(data_size);
+
+ if (!databss_together && number_of_bss_hunk != -1)
+ sh.sizes[this_hunk++] = LONGSIZE(bss_size);
+
+ if (number_of_debug_hunk != -1)
+ sh.sizes[this_hunk++] = 0; /* to be filled in later */
+
+ header_size = sizeof(sh) - (4-this_hunk)*sizeof(long);
+ mywrite(&sh, 1, header_size, outfd);
+ }
+
+ /* if we really write out a debug hunk, this fills in the remaining
+ * spots, that are known only at the end of load-file output */
+
+ void
+ conditionally_rewrite_headers ()
+ {
+ long size_of_debug_hunk,
+ end_hunk = 0x3f2,
+ eof;
+
+ /* if we don't want a debug hunk, just return */
+ if (number_of_debug_hunk == -1) return;
+
+ /* while we're at it, since we started the debug-hunk, lets finish it
+ * now. */
+ fseek (outstream, 0L, 2);
+ eof = ftell (outstream);
+ dh.strs = eof - offset_of_debug_hunk - sizeof(dh) - dh.syms;
+ /* just to be sure, we HAVE to pad to a long-boundery */
+ if (eof & 3)
+ {
+ long zero = 0;
+
+ mywrite(&zero, 4 - (eof & 3), 1, outstream);
+ eof = (eof + 3) & ~3;
+ }
+
+ mywrite(&end_hunk, sizeof(long), 1, outstream);
+
+ /* ok, so calculate the size of the debug hunk. This is the
+ * size of the debug_header plus the symbol and string tables,
+ * but it doesn't include the 2 longs, that identify the hunk and
+ * its length, whence the "- 2*sizeof(long)" */
+ size_of_debug_hunk = eof - offset_of_debug_hunk - 2*sizeof(long);
+ /* we actually need the size in longs.. */
+ size_of_debug_hunk = LONGSIZE(size_of_debug_hunk);
+
+ /* now first patch the debug-hunk itself, afterwards the load-file header */
+ fseek (outstream, offset_of_debug_hunk, 0);
+ dh.len = size_of_debug_hunk;
+ mywrite(&dh, sizeof dh, 1, outstream);
+
+ /* now the main header, this involves calculating, at which offset we
+ * find the index for the debug hunk */
+ fseek (outstream, (5 + number_of_debug_hunk)*sizeof(long), 0);
+ mywrite(&size_of_debug_hunk, sizeof(long), 1, outstream);
+ fseek (outstream, 0L, 2);
+ /* that's it! */
+ }
+
+ /* this is the only information that we can store in a regular amiga
+ * symbol, just its value, nothing further, that's why I added the
+ * debug-hunk-feature */
+
+ typedef struct {
+ char *sym_name;
+ long sym_offset;
+ } simple_symbol;
+
+ /* we'll only define symbols after at most 3 hunks, ie. the code, data
+ * and bss hunk, but not after the debug hunk, whence the index 3 */
+
+ simple_symbol *hunk_sym_tab[3];
+ int hunk_sym_tab_size[3], hunk_sym_tab_index[3];
+
+ void
+ init_symbol_hunks()
+ {
+ int i;
+
+ if (trace_files) fprintf(stderr, "init_symbol_hunks()\n");
+
+ for (i = 0; i < 3; i++)
+ {
+ hunk_sym_tab[i] =
+ (simple_symbol *) xmalloc((hunk_sym_tab_size[i] = 10) *
+ sizeof(simple_symbol));
+ hunk_sym_tab_index[i] = 0;
+ }
+ }
+
+ /* this should go into libc, well, it wasn't there, so... */
+
+ char *
+ strsave(str)
+ char *str;
+ {
+ char *cp;
+ int len = strlen(str);
+ if (len)
+ {
+ cp = xmalloc(len+1);
+ strcpy(cp, str);
+ }
+ else
+ cp = NULL;
+ return cp;
+ }
+
+ void
+ add_to_symbol_hunk(hunk_num, name, offset)
+ int hunk_num;
+ char *name;
+ long offset;
+ {
+ if (hunk_num == -1) return;
+ if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
+
+ /* no checks for duplicate symbols. Since it is legitimate to have
+ * symbols with the same name, we can't strip them.. just make
+ * sure not to call this function multiple times with the same
+ * symbol, since it won't be detected, and you'll get several
+ * labels for the same offset...
+ */
+
+ if (trace_files) fprintf(stderr, "add_to_symbol_hunk(%d, %s, %d)\n",
+ hunk_num, name, offset);
+
+ hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]].sym_offset = offset;
+ hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]++].sym_name =
+ strsave(name);
+
+ if (hunk_sym_tab_index[hunk_num] == hunk_sym_tab_size[hunk_num])
+ hunk_sym_tab[hunk_num] = (simple_symbol *)
+ xrealloc(hunk_sym_tab[hunk_num],
+ (hunk_sym_tab_size[hunk_num] <<= 1) *
+ sizeof(simple_symbol));
+ }
+
+ int
+ compare_simple_symbols(l1, l2)
+ simple_symbol *l1, *l2;
+ {
+ return l1->sym_offset - l2->sym_offset;
+ }
+
+ /* this writes the symbol subhunk #hunk_num, you call this just after
+ * you created your {code,data,bss}-hunk */
+
+ void
+ write_symbol_hunk(hunk_num)
+ int hunk_num;
+ {
+ int i, j;
+ simple_symbol *tab;
+ long size, index;
+
+ if (hunk_num == -1) return;
+ if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
+
+ tab = hunk_sym_tab[hunk_num];
+ size = hunk_sym_tab_size[hunk_num];
+ index = hunk_sym_tab_index[hunk_num];
+
+ /* kind of abused as general debug-flag:-) */
+ if (trace_files) fprintf(stderr,
+ "wsh: hnum=%d,size=%d,index=%d\n",
+ hunk_num,size,index);
+
+ if (index > 0)
+ {
+ qsort(tab, index, sizeof(simple_symbol), compare_simple_symbols);
+
+ j = 0x3f0; /* HUNK_SYMBOL */
+ mywrite(&j, 1, sizeof(long), outstream);
+
+ for (i = 0; i < index; i++)
+ {
+ register simple_symbol *ss = tab+i;
+ int len = strlen (ss->sym_name);
+
+ j = LONGSIZE (len);
+ mywrite(&j, 1, sizeof(long), outstream);
+
+ mywrite(ss->sym_name, 1, len, outstream);
+ if (len < 4*j)
+ padfile (4*j - len, outstream);
+
+ mywrite(&(ss->sym_offset), 1, sizeof(long), outstream);
+ }
+
+ j = 0;
+ mywrite(&j, 1, sizeof(long), outstream);
+ }
+ }
+
+ /* now follow the quite similar routines for dealing with
+ * reloc-subhunks, the difference to the symbol-subhunks is, that reloc
+ * subhunks can be output only after the {code,data}-Hunks, AND there
+ * can be more than one after each of them */
+
+ long *hunk_rel_tab[3], hunk_rel_tab_size[3], hunk_rel_tab_index[3];
+
+ void
+ init_reloc_hunk()
+ {
+ int i;
+
+ if (trace_files) fprintf(stderr, "init_reloc_hunk()\n");
+
+ for (i = 0; i < 3; i++)
+ {
+ hunk_rel_tab[i] =
+ (long *) xmalloc((hunk_rel_tab_size[i] = 10) * sizeof(long));
+ hunk_rel_tab_index[i] = 0;
+ }
+ }
+
+ void
+ add_to_reloc_hunk(hunk_num, offset)
+ int hunk_num;
+ long offset;
+ {
+ /* no checks for duplicate symbols, they will show up when we sort
+ * the table, and we will strip them off before writing out the table */
+
+ if (trace_files) fprintf(stderr, "add_to_reloc_hunk(%d, %d)\n", hunk_num, offset);
+
+ hunk_rel_tab[hunk_num][hunk_rel_tab_index[hunk_num]++] = offset;
+
+ if (hunk_rel_tab_index[hunk_num] == hunk_rel_tab_size[hunk_num])
+ hunk_rel_tab[hunk_num] = (long *)
+ xrealloc(hunk_rel_tab[hunk_num],
+ (hunk_rel_tab_size[hunk_num] <<= 1) * sizeof(long));
+ }
+
+ int
+ compare_longs(l1, l2)
+ long *l1, *l2;
+ {
+ return *l1 - *l2;
+ }
+
+ int
+ compare_strings (s1p, s2p)
+ char **s1p;
+ char **s2p;
+ {
+ return (strcmp (*s1p, *s2p));
+ }
+
+ void
+ write_reloc_hunk()
+ {
+ int i, j;
+ long *tab, size, index;
+ /* only write a hunk-header & -end, if we really output some relocs */
+ int did_start_hunk = 0;
+
+ for (i = 0; i < 3; i++)
+ {
+ tab = hunk_rel_tab[i];
+ size = hunk_rel_tab_size[i];
+ index = hunk_rel_tab_index[i];
+
+ /* kind of abused as general debug-flag:-) */
+ if (trace_files) fprintf(stderr,
+ "wrh: i=%d,size=%d,index=%d\n",
+ i,size,index);
+
+ if (index > 0)
+ {
+ qsort(tab, index, sizeof(long), compare_longs);
+
+ /* kick out duplicate symbols.. I don't know, what
+ * the loader would do, if it had to relocate the same
+ * address twice.. BTW: can this happen or can't it???? */
+ for (j = 0; j < index-1; )
+ {
+ if (tab[j] == tab[j+1])
+ bcopy(tab+j+1, tab+j, ((index--)-j-1)*sizeof(long));
+ else
+ j++;
+ }
+
+ if (!did_start_hunk++)
+ {
+ j = 0x3ec; /* HUNK_RELOC32 */
+ mywrite(&j, 1, sizeof(long), outstream);
+ }
+
+ mywrite(&index, 1, sizeof(long), outstream);
+ mywrite(&i, 1, sizeof(long), outstream);
+ mywrite(tab, 1, index*sizeof(long), outstream);
+ hunk_rel_tab_index[i] = index;
+ }
+ }
+ if (did_start_hunk)
+ {
+ j = 0;
+ mywrite(&j, 1, sizeof(long), outstream);
+ }
+ }
+
+
+ void
+ write_datadata_relocs ()
+ {
+ int numdd, i, prev;
+
+ prev = ftell (outstream);
+ fseek (outstream, datadata_relocs_offset, L_SET);
+
+ numdd = hunk_rel_tab_index[number_of_data_hunk];
+ if (numdd > numdatadata_relocs)
+ fatal ("found more data-data relocs than estimated!\n", 0);
+
+ mywrite (&numdd, 1, sizeof (long), outstream);
+ if (numdd)
+ mywrite (hunk_rel_tab[number_of_data_hunk], numdd, sizeof (long), outstream);
+
+ fseek (outstream, prev, L_SET);
+ }
+
+
+ /* create the bss hunk if needed */
+
+ void
+ write_bss()
+ {
+ long bss_hunk[2];
+ if (!databss_together && bss_size)
+ {
+ bss_hunk[0] = 0x3eb;
+ bss_hunk[1] = LONGSIZE(bss_size);
+ mywrite(bss_hunk, 1, sizeof bss_hunk, outstream);
+ write_symbol_hunk(number_of_bss_hunk);
+ bss_hunk[0] = 0x3f2; /* HUNK_END */
+ mywrite(bss_hunk, 1, sizeof(long), outstream);
+ }
+ }
+
+ /* this scans one object file for its symbols, and deposits them in
+ * the symbol-hunk tables for later output */
+
+ void
+ look_for_file_syms (entry)
+ struct file_entry *entry;
+ {
+ register struct nlist *p = entry->symbols;
+ register struct nlist *end = p + entry->syms_size / sizeof (struct nlist);
+
+ #if 0
+ /* don't do this, it only confuses most amiga disassemblers.. */
+
+ /* Generate a local symbol for the start of this file's text. */
+
+ if (discard_locals != DISCARD_ALL)
+ add_to_symbol_hunk(number_of_code_hunk, entry->local_sym_name,
+ entry->text_start_address);
+ #endif
+
+ /* Read the file's string table. */
+
+ entry->strings = (char *) alloca (entry->strs_size);
+ read_entry_strings (file_open (entry), entry);
+
+ for (; p < end; p++)
+ {
+ register unsigned char type = p->n_type;
+ register int write = 0;
+ int this_hunk;
+ char *cp;
+
+ /* WRITE gets 1 for a non-global symbol that should be written. */
+
+ if (SET_ELEMENT_P (type)) /* This occurs even if global. These */
+ /* types of symbols are never written */
+ /* globally, though they are stored */
+ /* globally. */
+ write = output_style == OUTPUT_RELOCATABLE;
+ else if (!(type & (N_STAB | N_EXT)))
+ /* ordinary local symbol */
+ write = ((discard_locals != DISCARD_ALL)
+ && !(discard_locals == DISCARD_L &&
+ (p->n_un.n_strx + entry->strings)[0] == LPREFIX)
+ && type != N_WARNING);
+
+ else if (!(type & N_EXT))
+ /* debugger symbol */
+ write = (strip_symbols == STRIP_NONE);
+
+ /* skip STAB symbols if present */
+ write = write && !(type & N_STAB);
+
+ /* those weird types are NOT output in the normal symbols:-)) */
+ write = write && (type != N_ABS && type != (N_ABS|N_EXT));
+
+ /* don't know where those symbols come from, they're well suited to
+ * crash enforcer, and they're not `real' symbols anyway.. */
+ if (p->n_un.n_strx > entry->strs_size) continue;
+
+ /* symbols that end with a dot are only useful for gdb,
+ * not for a normal amiga debugger (currently gcc_compiled. and
+ * gcc_compiled2.) so skip them in this section */
+
+ /* check to see, whether this string ends with a dot */
+ if (write && p->n_un.n_strx)
+ {
+ cp = rindex (p->n_un.n_strx + entry->strings, '.');
+
+ write = write && !(cp && !cp[1]);
+
+ #if 0
+ printf ("%s >%s<\n", write ? "adding" : "skipping", p->n_un.n_strx + entry->strings);
+ #endif
+ }
+
+ if (write)
+ {
+ if (p->n_un.n_strx)
+ {
+ switch (type & ~N_EXT)
+ {
+ case N_TEXT:
+ this_hunk = number_of_code_hunk;
+ break;
+ case N_SETV:
+ case N_DATA:
+ this_hunk = number_of_data_hunk;
+ break;
+ case N_UNDF:
+ case N_BSS:
+ this_hunk = number_of_bss_hunk;
+ break;
+ default:
+ error ("unknown type %d while trying to build lsymhunk", type);
+ goto skip1;
+ }
+
+ add_to_symbol_hunk(this_hunk, p->n_un.n_strx + entry->strings,
+ p->n_value);
+ skip1: ;
+ }
+ }
+ }
+ }
+
+ /* scan all input files for symbols and store them in the symbolhunk tables */
+
+ void
+ look_for_symbols()
+ {
+ int this_hunk;
+ int i;
+ symbol *sp;
+
+ if (strip_symbols == STRIP_ALL)
+ return;
+
+ /* Write the local symbols defined by the various files. */
+
+ each_file (look_for_file_syms, 0);
+ file_close ();
+
+ /* Scan the symbol hash table, bucket by bucket. */
+
+ for (i = 0; i < TABSIZE; i++)
+ for (sp = symtab[i]; sp; sp = sp->link)
+ {
+ struct nlist nl;
+
+ /* Compute a `struct nlist' for the symbol. */
+
+ nl.n_value = 0;
+
+ if (sp->defined || sp->referenced)
+ {
+ /* common condition needs to be before undefined condition */
+ /* because unallocated commons are set undefined in */
+ /* digest_symbols */
+ if (sp->defined > 1) /* defined with known type */
+ {
+ /* If the target of an indirect symbol has been
+ defined and we are outputting an executable,
+ resolve the indirection; it's no longer needed */
+ if (output_style != OUTPUT_RELOCATABLE
+ && ((sp->defined & ~N_EXT) == N_INDR)
+ && (((symbol *) sp->value)->defined > 1))
+ {
+ symbol *newsp = (symbol *) sp->value;
+ nl.n_type = newsp->defined;
+ nl.n_value = newsp->value;
+ }
+ else
+ {
+ nl.n_type = sp->defined;
+ if (sp->defined != (N_INDR | N_EXT))
+ nl.n_value = sp->value;
+ else
+ nl.n_value = 0;
+ }
+ }
+ else if (sp->max_common_size) /* defined as common but not allocated. */
+ {
+ /* happens only with -r and not -d */
+ /* write out a common definition */
+ nl.n_type = N_UNDF | N_EXT;
+ nl.n_value = sp->max_common_size;
+ }
+ else if (!sp->defined) /* undefined -- legit only if -r */
+ {
+ nl.n_type = N_UNDF | N_EXT;
+ nl.n_value = 0;
+ }
+ else
+ fatal ("internal error: %s defined in mysterious way", sp->name);
+
+ switch (nl.n_type & ~N_EXT)
+ {
+ case N_TEXT:
+ this_hunk = number_of_code_hunk;
+ break;
+ case N_SETV:
+ case N_DATA:
+ this_hunk = number_of_data_hunk;
+ break;
+ case N_UNDF:
+ case N_BSS:
+ this_hunk = number_of_bss_hunk;
+ break;
+ case N_ABS:
+ break;
+ default:
+ error ("unknown type %d while trying to build symhunk", nl.n_type);
+ goto skip2;
+ }
+
+ /* sigh, there is no equivalent in the symbol section of a load
+ * file on the amiga, have to forget about those symbols */
+ if ((nl.n_type & ~N_EXT) == N_ABS)
+ continue;
+
+ add_to_symbol_hunk(this_hunk, sp->name, nl.n_value);
+ skip2: ;
+ }
+ }
+ }
+
+ void
+ relocate_set_vectors (vectors, num_entries)
+ unsigned long *vectors;
+ int num_entries;
+ {
+ unsigned long i;
+ unsigned long offset = set_sect_start;
+ int hunk_num;
+
+ while (num_entries-- > 0)
+ {
+ /* the number of entries for this symbol */
+ i = *vectors++; offset += 4;
+ while (num_entries --, i--)
+ {
+ hunk_num = number_of_code_hunk;
+ if (*vectors >= text_size)
+ {
+ if (*vectors >= text_size + data_size)
+ {
+ hunk_num = number_of_bss_hunk;
+ if (databss_together)
+ *vectors -= text_size;
+ else
+ *vectors -= text_size + data_size;
+ }
+ else
+ {
+ hunk_num = number_of_data_hunk;
+ *vectors -= text_size;
+ }
+ }
+ add_to_reloc_hunk (hunk_num, offset);
+ ++vectors;
+ offset += 4;
+ }
+ /* check.. HAS to be zero */
+ if (*vectors)
+ fatal ("set-vector corrupt, num_entries = %d", num_entries);
+ vectors++; offset += 4; --num_entries;
+ }
+ }
+ #endif
+
diff -rc --new-file binutils-1.8.x-fsf/objdump.c binutils-1.8.x-amiga/objdump.c
*** binutils-1.8.x-fsf/objdump.c Sat Dec 30 00:16:07 1989
--- binutils-1.8.x-amiga/objdump.c Wed Sep 22 12:45:33 1993
***************
*** 24,31 ****
#include <stdio.h>
#include "getopt.h"
#ifndef COFF_ENCAPSULATE
! #include <a.out.h>
/* Tell a.out.gnu.h not to try to redefine some things. */
#define __STRUCT_EXEC_OVERRIDE__
#define N_NLIST_DECLARED
--- 24,35 ----
#include <stdio.h>
#include "getopt.h"
+ #ifdef MCH_AMIGA
+ #define getpagesize() 256
+ #endif
+
#ifndef COFF_ENCAPSULATE
! #include <sun/a.out.h>
/* Tell a.out.gnu.h not to try to redefine some things. */
#define __STRUCT_EXEC_OVERRIDE__
#define N_NLIST_DECLARED
diff -rc --new-file binutils-1.8.x-fsf/ranlib.c binutils-1.8.x-amiga/ranlib.c
*** binutils-1.8.x-fsf/ranlib.c Thu Mar 1 00:18:42 1990
--- binutils-1.8.x-amiga/ranlib.c Sat Feb 5 12:31:20 1994
***************
*** 54,60 ****
as the location of the GNU AR program. */
char *prog = AR_PROG;
! char *prog_pref = "/usr/local/gnubin/ar";
int
main (argc, argv)
--- 54,60 ----
as the location of the GNU AR program. */
char *prog = AR_PROG;
! char *prog_pref = "/gnu/bin/ar";
int
main (argc, argv)
diff -rc --new-file binutils-1.8.x-fsf/strip.c binutils-1.8.x-amiga/strip.c
*** binutils-1.8.x-fsf/strip.c Mon Jun 11 21:40:01 1990
--- binutils-1.8.x-amiga/strip.c Wed Sep 22 12:45:43 1993
***************
*** 71,77 ****
/* If BSD, we can use `ftruncate'. */
! #ifndef USG
#define HAVE_FTRUNCATE
#endif
--- 71,77 ----
/* If BSD, we can use `ftruncate'. */
! #if !defined(USG) && !defined(MCH_AMIGA)
#define HAVE_FTRUNCATE
#endif
***************
*** 287,294 ****
--- 287,296 ----
signal (SIGTERM, SIG_DFL);
/* Handle any signal that came in while they were deferred. */
+ #ifndef MCH_AMIGA
if (delayed_signal)
kill (getpid (), delayed_signal);
+ #endif
}
/** Convenient functions for operating on one or all files being processed. */
***************
*** 928,933 ****
--- 930,936 ----
}
#ifdef USG
+ #ifndef MCH_AMIGA
rename (from, to)
char *from, *to;
***************
*** 940,945 ****
--- 943,949 ----
return 0;
}
+ #endif
#endif
usage ()