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
Text File  |  1994-02-05  |  90KB  |  3,363 lines

  1. diff -rc --new-file binutils-1.8.x-fsf/Makefile binutils-1.8.x-amiga/Makefile
  2. *** binutils-1.8.x-fsf/Makefile    Wed Nov 27 22:48:58 1991
  3. --- binutils-1.8.x-amiga/Makefile    Sat Feb  5 12:33:24 1994
  4. ***************
  5. *** 19,50 ****
  6.   # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  7.   
  8.   
  9. ! GNUCC = gcc -O
  10. ! #CC = gcc -O
  11.   bindir=/usr/local/bin
  12.   
  13.   # for BSD systems
  14.   #CFLAGS = -g
  15.   # Don't add robotussin; it won't compile on BSD or GNU systems.
  16.   # objdump is not here because it (at least used to) not compile
  17.   # on most systems (trouble with N_DATADDR).  I've fixed some of
  18.   # those problems, though.
  19. ! PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
  20. !         $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  21.   
  22.   # for USG systems using COFF_ENCAPSULATE
  23.   # also, you will want to make the target libc.a (but it takes a long time)
  24.   # Note that you should leave a copy of `ar' in this directory
  25.   # after you install it, since `ranlib' will try to run it from here.
  26. ! CFLAGS = -DWYSE -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
  27. ! PROGS = ld size nm strip ar robotussin objdump ranlib gprof
  28. ! SIGNAME = signame.o
  29.   # On ALTOS systems, add -DALTOS to CFLAGS.
  30.   
  31.   #it's better to move a copy of alloca into your libc than to risk getting some
  32.   #incompatiable functions from -lPW (like index()), but if you
  33.   #want to be lazy, uncomment this line
  34. ! ALLOCALIBS = -lPW
  35.   
  36.   # For HP-UX systems
  37.   # Don't add robotussin; use hpxt instead.
  38. --- 19,57 ----
  39.   # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  40.   
  41.   
  42. ! GNUCC = gcc -O2
  43.   bindir=/usr/local/bin
  44.   
  45. + # for AmigaDOS systems
  46. + CFLAGS = -resident
  47. + # Don't include gprof.
  48. + PROGS = $(archpfx)ld $(archpfx)size \
  49. +         $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  50. + CC = gcc -O2
  51. + bindir=/gnu/bin
  52.   # for BSD systems
  53.   #CFLAGS = -g
  54.   # Don't add robotussin; it won't compile on BSD or GNU systems.
  55.   # objdump is not here because it (at least used to) not compile
  56.   # on most systems (trouble with N_DATADDR).  I've fixed some of
  57.   # those problems, though.
  58. ! #PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
  59. ! #        $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  60.   
  61.   # for USG systems using COFF_ENCAPSULATE
  62.   # also, you will want to make the target libc.a (but it takes a long time)
  63.   # Note that you should leave a copy of `ar' in this directory
  64.   # after you install it, since `ranlib' will try to run it from here.
  65. ! #CFLAGS = -g -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
  66. ! #PROGS = ld size nm strip ar robotussin objdump ranlib gprof
  67. ! #SIGNAME = signame.o
  68.   # On ALTOS systems, add -DALTOS to CFLAGS.
  69.   
  70.   #it's better to move a copy of alloca into your libc than to risk getting some
  71.   #incompatiable functions from -lPW (like index()), but if you
  72.   #want to be lazy, uncomment this line
  73. ! #ALLOCALIBS = -lPW
  74.   
  75.   # For HP-UX systems
  76.   # Don't add robotussin; use hpxt instead.
  77. ***************
  78. *** 83,89 ****
  79.   # C++ demangler
  80.   CPLUS_DEM = $(archpfx)cplus-dem.o
  81.   
  82. ! LIBS=$(MALLOC) $(ALLOCALIBS) $(SIGNAME)
  83.   
  84.   all: $(PROGS)
  85.   
  86. --- 90,96 ----
  87.   # C++ demangler
  88.   CPLUS_DEM = $(archpfx)cplus-dem.o
  89.   
  90. ! LIBS=$(ALLOCALIBS) $(SIGNAME)
  91.   
  92.   all: $(PROGS)
  93.   
  94. ***************
  95. *** 114,120 ****
  96.   $(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
  97.       $(CC) $(CFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
  98.   $(archpfx)ranlib.o: ranlib.c
  99. !     $(CC) -c $(CFLAGS) -DAR_PROG=\"/usr/local/gnu/binutils/ar\" ranlib.c $(OUTPUT_OPTION)
  100.   
  101.   $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
  102.       $(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  103. --- 121,127 ----
  104.   $(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
  105.       $(CC) $(CFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
  106.   $(archpfx)ranlib.o: ranlib.c
  107. !     $(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)
  108.   
  109.   $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
  110.       $(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  111. ***************
  112. *** 145,150 ****
  113.   .PHONY: install
  114.   install: $(PROGS)
  115.       for file in $(PROGS); do \
  116. !     cp $$file $(bindir)/$${file}.new; \
  117. !     mv $(bindir)/$${file}.new $(bindir)/$$file; \
  118.       done
  119. --- 152,158 ----
  120.   .PHONY: install
  121.   install: $(PROGS)
  122.       for file in $(PROGS); do \
  123. !     cp $${file} $(bindir)/$${file}.new; \
  124. !     mv $(bindir)/$${file} $(bindir)/$${file}.bak; \
  125. !     mv $(bindir)/$${file}.new $(bindir)/$${file}; \
  126.       done
  127. diff -rc --new-file binutils-1.8.x-fsf/ar.c binutils-1.8.x-amiga/ar.c
  128. *** binutils-1.8.x-fsf/ar.c    Wed Jun 13 05:47:50 1990
  129. --- binutils-1.8.x-amiga/ar.c    Sat Feb  5 13:17:48 1994
  130. ***************
  131. *** 992,1002 ****
  132. --- 992,1012 ----
  133.   #endif
  134.     close (outdesc);
  135.   
  136. + #ifndef amigados
  137.     if (!appendflag)
  138.       if (rename (tempname, archive))
  139.         pfatal_with_name (tempname);
  140.   
  141.     close_archive ();
  142. + #else
  143. +   /* we *have* to close the file before we rename it, because otherwise
  144. +    * AmigaDOS will just abort with OBJECT_IN_USE_ERROR */
  145. +   close_archive ();
  146. +   if (!appendflag)
  147. +     if (rename (tempname, archive))
  148. +       pfatal_with_name (tempname);
  149. + #endif
  150.   }
  151.   
  152.   void
  153. ***************
  154. *** 1957,1962 ****
  155. --- 1967,1973 ----
  156.        unsigned int size;
  157.   {
  158.     extern char *malloc ();
  159.     char *result = malloc (size);
  160.     if (result == 0)
  161.       fatal ("virtual memory exhausted", 0);
  162. ***************
  163. *** 1969,1974 ****
  164. --- 1980,1986 ----
  165.        unsigned int size;
  166.   {
  167.     extern char *realloc ();
  168.     char *result = realloc (ptr, size);
  169.     if (result == 0)
  170.       fatal ("virtual memory exhausted");
  171. diff -rc --new-file binutils-1.8.x-fsf/cplus-dem.c binutils-1.8.x-amiga/cplus-dem.c
  172. *** binutils-1.8.x-fsf/cplus-dem.c    Wed Jun 13 05:42:34 1990
  173. --- binutils-1.8.x-amiga/cplus-dem.c    Wed Sep 22 12:45:32 1993
  174. ***************
  175. *** 48,54 ****
  176.   #include <ctype.h>
  177.   
  178.   #if !defined(sequent) && !defined(NeXT)
  179. ! #include <memory.h>
  180.   #else
  181.   #define memcpy(s1, s2, n) strncpy(s1, s2, n) 
  182.   #define memcmp(s1, s2, n) strncmp(s1, s2, n)
  183. --- 48,54 ----
  184.   #include <ctype.h>
  185.   
  186.   #if !defined(sequent) && !defined(NeXT)
  187. ! /* #include <memory.h> */
  188.   #else
  189.   #define memcpy(s1, s2, n) strncpy(s1, s2, n) 
  190.   #define memcmp(s1, s2, n) strncmp(s1, s2, n)
  191. diff -rc --new-file binutils-1.8.x-fsf/ld.c binutils-1.8.x-amiga/ld.c
  192. *** binutils-1.8.x-fsf/ld.c    Wed Nov 27 22:04:14 1991
  193. --- binutils-1.8.x-amiga/ld.c    Sat Feb  5 13:32:51 1994
  194. ***************
  195. *** 16,22 ****
  196.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  197.   
  198.   /* Written by Richard Stallman with some help from Eric Albert.
  199. !    Set, indirect, and warning symbol features added by Randy Smith.  */
  200.   
  201.   #include <ar.h>
  202.   #include <stdio.h>
  203. --- 16,29 ----
  204.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  205.   
  206.   /* Written by Richard Stallman with some help from Eric Albert.
  207. !    Set, indirect, and warning symbol features added by Randy Smith.
  208. !    Support for generation of Amiga load files added by Markus Wild. */
  209. ! #ifdef amigados
  210. ! #ifndef STANDARD_SEARCH_DIRS
  211. ! #define STANDARD_SEARCH_DIRS "local:lib","local:os-lib","gnu:lib","gnu:os-lib"
  212. ! #endif
  213. ! #endif
  214.   
  215.   #include <ar.h>
  216.   #include <stdio.h>
  217. ***************
  218. *** 30,35 ****
  219. --- 37,44 ----
  220.   #ifndef sony_news
  221.   #include <fcntl.h>
  222.   #endif
  223. + /* JPB, 7 Jun 1992: MAXNAMLEN required for long name hack. */
  224. + #include <dirent.h>
  225.   
  226.   #if !defined(A_OUT) && !defined(MACH_O)
  227.   #define A_OUT
  228. ***************
  229. *** 43,48 ****
  230. --- 52,84 ----
  231.   #endif
  232.   #endif
  233.   
  234. + #ifdef MCH_AMIGA
  235. + #define HUNK_INSTEAD_OF_A_OUT
  236. + int number_of_code_hunk,
  237. +     number_of_data_hunk,
  238. +     number_of_bss_hunk,
  239. +     number_of_debug_hunk,
  240. +     current_hunk = 0,
  241. +     offset_of_debug_hunk,
  242. +     amiga_symbols_only,
  243. +     databss_together = 0,
  244. +     numdatadata_relocs = 0,
  245. +     output_datadata_relocs = 0,
  246. +     datadata_relocs_offset = 0;
  247. + #define LONGSIZE(l) ((((l) + 3) & ~3) >> 2)
  248. + /* this is the private format of the debug-hunk: */
  249. +    struct debug_hunk {
  250. +      unsigned long  id;  /* Filesystem-imposed: HUNK_DEBUG (0x3f1) */
  251. +      unsigned long  len; /* "" : length in longs -> LONGSIZE(real_lenght) */
  252. +      /* the following part is somehow a truncated exec-struct: */
  253. +      unsigned long  magic; /* should be ZMAGIC (just for fun:-)), to be recognised
  254. +                 * by the other tools as this special frame */
  255. +      unsigned long  syms;  /* size of symbol-table */
  256. +      unsigned long  strs;  /* size of string table */
  257. +      /* here follows the actual data */
  258. +    } dh;
  259. + #endif
  260.   #ifdef MACH_O
  261.   #ifndef A_OUT
  262.   #include <nlist.h>
  263. ***************
  264. *** 104,110 ****
  265.   /* Name this program was invoked by.  */
  266.   
  267.   char *progname;
  268.   /* System dependencies */
  269.   
  270.   /* Define this if names etext, edata and end should not start with `_'.  */
  271. --- 140,146 ----
  272.   /* Name this program was invoked by.  */
  273.   
  274.   char *progname;
  275.   /* System dependencies */
  276.   
  277.   /* Define this if names etext, edata and end should not start with `_'.  */
  278. ***************
  279. *** 190,195 ****
  280. --- 226,247 ----
  281.   #endif /* mc68000.  */
  282.   #endif /* Sun.  */
  283.   
  284. + #ifdef amigados
  285. + /* same trick as with sun[23] */
  286. + /* Set the machine type according to the machine type of the .o files.
  287. +    If they are all sun2 (68010), then the type of the executable is sun2.
  288. +    If any is sun3 (68020), then the type of the executable is sun3.
  289. +    This is consistent with the Sun loader and more useful than having
  290. +    it depend on which machine you are on when you run ld.  */
  291. + static int amiga_machtype = MID_SUN010;
  292. + #define INITIALIZE_HEADER outheader.a_machtype = amiga_machtype
  293. + #define READ_HEADER_HOOK(machtype) \
  294. +   if (machtype == MID_SUN020)        \
  295. +     {                     \
  296. +       amiga_machtype = MID_SUN020;   \
  297. +     }
  298. + #endif
  299.   #ifdef ALTOS
  300.   #define INITIALIZE_HEADER N_SET_MACHTYPE (outheader, M_68020)
  301.   #endif
  302. ***************
  303. *** 368,373 ****
  304. --- 420,426 ----
  305.   #define RELOC_MEMORY_ADD_P(r)    1
  306.   #undef RELOC_ADD_EXTRA
  307.   #define RELOC_PCREL_P(r)        ((r)->r_pcrel)
  308. + #define RELOC_BASEREL_P(r)        ((r)->r_baserel)
  309.   #define RELOC_VALUE_RIGHTSHIFT(r)    0
  310.   #define RELOC_TARGET_SIZE(r)        ((r)->r_length)
  311.   #define RELOC_TARGET_BITPOS(r)    0
  312. ***************
  313. *** 384,390 ****
  314.   #define LPREFIX 'L'
  315.   #endif
  316.   
  317.   /* Special global symbol types understood by GNU LD.  */
  318.   
  319.   /* The following type indicates the definition of a symbol as being
  320. --- 437,443 ----
  321.   #define LPREFIX 'L'
  322.   #endif
  323.   
  324.   /* Special global symbol types understood by GNU LD.  */
  325.   
  326.   /* The following type indicates the definition of a symbol as being
  327. ***************
  328. *** 531,537 ****
  329.   #endif
  330.   
  331.   #endif /* not __GNU_STAB__ */
  332.   /* Symbol table */
  333.   
  334.   /* Global symbol data is recorded in these structures,
  335. --- 584,590 ----
  336.   #endif
  337.   
  338.   #endif /* not __GNU_STAB__ */
  339.   /* Symbol table */
  340.   
  341.   /* Global symbol data is recorded in these structures,
  342. ***************
  343. *** 684,690 ****
  344.   symbol *edata_symbol_alt;
  345.   symbol *etext_symbol_alt;
  346.   symbol *end_symbol_alt;
  347.   /* Kinds of files potentially understood by the linker. */
  348.   
  349.   enum file_type { IS_UNKNOWN, IS_ARCHIVE, IS_A_OUT, IS_MACH_O };
  350. --- 737,751 ----
  351.   symbol *edata_symbol_alt;
  352.   symbol *etext_symbol_alt;
  353.   symbol *end_symbol_alt;
  354. ! #ifdef amigados
  355. ! symbol *sdata_symbol;    /* the symbol __sdata */
  356. ! symbol *text_size_symbol;
  357. ! symbol *data_size_symbol;
  358. ! symbol *bss_size_symbol;
  359. ! symbol *datadata_reloc_symbol = 0;
  360. ! #endif
  361.   /* Kinds of files potentially understood by the linker. */
  362.   
  363.   enum file_type { IS_UNKNOWN, IS_ARCHIVE, IS_A_OUT, IS_MACH_O };
  364. ***************
  365. *** 820,826 ****
  366.   
  367.   /* Length of that vector.  */
  368.   int number_of_files;
  369.   /* When loading the text and data, we can avoid doing a close
  370.      and another open between members of the same library.
  371.   
  372. --- 881,887 ----
  373.   
  374.   /* Length of that vector.  */
  375.   int number_of_files;
  376.   /* When loading the text and data, we can avoid doing a close
  377.      and another open between members of the same library.
  378.   
  379. ***************
  380. *** 867,875 ****
  381. --- 928,941 ----
  382.   #define DEFAULT_OUTPUT_STYLE OUTPUT_DEMAND_PAGED
  383.   #endif
  384.   
  385. + #if 0
  386.   /* Descriptor for writing that file with `mywrite'.  */
  387.   
  388.   int outdesc;
  389. + #endif
  390. + /* use outstream instead of outdesc thru the whole file, it's MUCH faster.. */
  391. + FILE *outstream = (FILE *) 0;
  392.   
  393.   /* The following are computed by `digest_symbols'.  */
  394.   
  395. ***************
  396. *** 929,935 ****
  397.     int symbol_name_string_index;
  398.     int library_member_offset;
  399.   };
  400.   /* Record most of the command options.  */
  401.   
  402.   /* Address we assume the text section will be loaded at.
  403. --- 995,1001 ----
  404.     int symbol_name_string_index;
  405.     int library_member_offset;
  406.   };
  407.   /* Record most of the command options.  */
  408.   
  409.   /* Address we assume the text section will be loaded at.
  410. ***************
  411. *** 993,998 ****
  412. --- 1059,1068 ----
  413.   /* Length of the vector `search_dirs'.  */
  414.   int n_search_dirs;
  415.   
  416. + /* Vector of flavors to search for. */
  417. + char **flavors;
  418. + int n_flavors;
  419.   /* Non zero means to create the output executable.
  420.      Cleared by nonfatal errors.  */
  421.   int make_executable;
  422. ***************
  423. *** 1007,1017 ****
  424. --- 1077,1092 ----
  425.   struct glosym **cmdline_references;
  426.   int cl_refs_allocated;
  427.   
  428. + /* JPB, 7 Jun 1992: Global variable needed for long name hack. */
  429. + static int ar_hdr_size;
  430.   #ifndef bcopy
  431.   void bcopy (), bzero ();
  432.   #endif
  433. + #ifndef __STDC__
  434.   char *malloc (), *realloc ();
  435.   void free ();
  436. + #endif
  437.   
  438.   char *xmalloc ();
  439.   char *xrealloc ();
  440. ***************
  441. *** 1034,1039 ****
  442. --- 1109,1129 ----
  443.   void write_output ();
  444.   void write_header ();
  445.   void write_text ();
  446. + #ifdef HUNK_INSTEAD_OF_A_OUT
  447. + void write_datadata_relocs ();
  448. + void write_hunk_header ();
  449. + void conditionally_rewrite_headers ();
  450. + void write_bss ();
  451. + void init_reloc_hunk ();
  452. + void add_to_reloc_hunk ();
  453. + void write_reloc_hunk ();
  454. + void init_symbol_hunks ();
  455. + void add_to_symbol_hunk ();
  456. + void write_symbol_hunk ();
  457. + void look_for_symbols ();
  458. + void look_for_file_symbols ();
  459. + void relocate_set_vectors ();
  460. + #endif
  461.   void read_file_relocation ();
  462.   void write_data ();
  463.   void write_rel ();
  464. ***************
  465. *** 1045,1051 ****
  466.   char *concat ();
  467.   char *get_file_name ();
  468.   symbol *getsym (), *getsym_soft ();
  469.   int
  470.   main (argc, argv)
  471.        char **argv;
  472. --- 1135,1142 ----
  473.   char *concat ();
  474.   char *get_file_name ();
  475.   symbol *getsym (), *getsym_soft ();
  476. ! int compare_longs (), compare_strings ();
  477.   int
  478.   main (argc, argv)
  479.        char **argv;
  480. ***************
  481. *** 1090,1095 ****
  482. --- 1181,1189 ----
  483.     make_executable = 1;
  484.     force_executable = 0;
  485.     set_element_prefixes = 0;
  486. + #ifdef HUNK_INSTEAD_OF_A_OUT
  487. +   amiga_symbols_only = 1;
  488. + #endif
  489.   
  490.     /* Initialize the cumulative counts of symbols.  */
  491.   
  492. ***************
  493. *** 1148,1158 ****
  494.   
  495.     exit (!make_executable);
  496.   }
  497.   void add_cmdline_ref ();
  498.   
  499.   static struct option longopts[] =
  500.   {
  501.     {"d", 0, 0, 'd'},
  502.     {"dc", 0, 0, 'd'},        /* For Sun compatibility. */
  503.     {"dp", 0, 0, 'd'},        /* For Sun compatibility. */
  504. --- 1242,1259 ----
  505.   
  506.     exit (!make_executable);
  507.   }
  508.   void add_cmdline_ref ();
  509.   
  510.   static struct option longopts[] =
  511.   {
  512. + #ifdef HUNK_INSTEAD_OF_A_OUT
  513. +   {"amiga-debug-hunk", 0, 0, 'a'},
  514. +   {"databss-together", 0, 0, 'b'},
  515. +   {"datadata-reloc", 0, 0, 'c'},
  516. +   {"msmall-code", 0, 0, 129},        /* ignore.. */
  517. +   {"flavor", 1, 0, 'f'},
  518. + #endif
  519.     {"d", 0, 0, 'd'},
  520.     {"dc", 0, 0, 'd'},        /* For Sun compatibility. */
  521.     {"dp", 0, 0, 'd'},        /* For Sun compatibility. */
  522. ***************
  523. *** 1224,1229 ****
  524. --- 1325,1344 ----
  525.         number_of_files++;
  526.         break;
  527.   
  528. + #ifdef HUNK_INSTEAD_OF_A_OUT
  529. +     case 'a':
  530. +       amiga_symbols_only = 0;
  531. +       break;
  532. +     case 'b':
  533. +       databss_together = 1;
  534. +       break;
  535. +     case 'c':
  536. +       output_datadata_relocs = 1;
  537. +       break;
  538. + #endif
  539.       case 'd':
  540.         force_common_definition = 1;
  541.         break;
  542. ***************
  543. *** 1236,1241 ****
  544. --- 1351,1362 ----
  545.         add_cmdline_ref (entry_symbol);
  546.         break;
  547.   
  548. +     case 'f':
  549. +       n_flavors++;
  550. +       flavors = (char **) xrealloc (flavors, n_flavors * sizeof (char *));
  551. +       flavors[n_flavors - 1] = optarg;
  552. +       break;
  553.       case 'l':
  554.         number_of_files++;
  555.         break;
  556. ***************
  557. *** 1363,1368 ****
  558. --- 1484,1494 ----
  559.       }
  560.       }
  561.   
  562. +   if (n_flavors > 1)
  563. +     {
  564. +       qsort (flavors, n_flavors, sizeof (char *), compare_strings);
  565. +     }
  566.     if (!number_of_files)
  567.       usage ("no input files", 0);
  568.   
  569. ***************
  570. *** 1433,1439 ****
  571.            n * sizeof (char *));
  572.       }
  573.   }
  574.   
  575.   void
  576.   add_cmdline_ref (sp)
  577. --- 1559,1565 ----
  578.            n * sizeof (char *));
  579.       }
  580.   }
  581.   
  582.   void
  583.   add_cmdline_ref (sp)
  584. ***************
  585. *** 1478,1484 ****
  586.       }
  587.     return 0;
  588.   }
  589.   /* Convenient functions for operating on one or all files being
  590.      loaded.  */
  591.   void print_file_name ();
  592. --- 1604,1610 ----
  593.       }
  594.     return 0;
  595.   }
  596.   /* Convenient functions for operating on one or all files being
  597.      loaded.  */
  598.   void print_file_name ();
  599. ***************
  600. *** 1602,1609 ****
  601.   
  602.         for (i = 0; i < n_search_dirs; i++)
  603.       {
  604. !       register char *string
  605. !         = concat (search_dirs[i], "/", entry->filename);
  606.         desc = open (string, O_RDONLY, 0);
  607.         if (desc > 0)
  608.           {
  609. --- 1728,1746 ----
  610.   
  611.         for (i = 0; i < n_search_dirs; i++)
  612.       {
  613. !       register char *string;
  614. !       string = search_dirs[i];
  615. !       if (n_flavors > 0)
  616. !         {
  617. !           int count;
  618. !           for (count = 0; count < n_flavors; count++)
  619. !         {
  620. !           string = concat (string, "/", flavors[count]);
  621. !         }
  622. !         }
  623. !       string = concat (string, "/", entry->filename);
  624. !       if (trace_files) fprintf (stderr, "Look for %s\n", string);
  625.         desc = open (string, O_RDONLY, 0);
  626.         if (desc > 0)
  627.           {
  628. ***************
  629. *** 1678,1684 ****
  630.       }
  631.     return result;
  632.   }
  633.   /* Medium-level input routines for rel files.  */
  634.   
  635.   /* Determine whether the given ENTRY is an archive, a BSD a.out file,
  636. --- 1815,1821 ----
  637.       }
  638.     return result;
  639.   }
  640.   /* Medium-level input routines for rel files.  */
  641.   
  642.   /* Determine whether the given ENTRY is an archive, a BSD a.out file,
  643. ***************
  644. *** 2044,2050 ****
  645.     if (entry->strs_size != read (desc, entry->strings, entry->strs_size))
  646.       fatal_with_file ("premature end of file in strings of ", entry);
  647.   }
  648.   /* Read in the symbols of all input files.  */
  649.   
  650.   void read_file_symbols (), read_entry_symbols (), read_entry_strings ();
  651. --- 2181,2187 ----
  652.     if (entry->strs_size != read (desc, entry->strings, entry->strs_size))
  653.       fatal_with_file ("premature end of file in strings of ", entry);
  654.   }
  655.   /* Read in the symbols of all input files.  */
  656.   
  657.   void read_file_symbols (), read_entry_symbols (), read_entry_strings ();
  658. ***************
  659. *** 2097,2103 ****
  660.   
  661.     file_close ();
  662.   }
  663.   /* Enter the external symbol defs and refs of ENTRY in the hash table.  */
  664.   
  665.   void
  666. --- 2234,2240 ----
  667.   
  668.     file_close ();
  669.   }
  670.   /* Enter the external symbol defs and refs of ENTRY in the hash table.  */
  671.   
  672.   void
  673. ***************
  674. *** 2375,2381 ****
  675.     return 0;
  676.   }
  677.   
  678.   /* Searching libraries */
  679.   
  680.   struct file_entry *decode_library_subfile ();
  681. --- 2512,2518 ----
  682.     return 0;
  683.   }
  684.   
  685.   /* Searching libraries */
  686.   
  687.   struct file_entry *decode_library_subfile ();
  688. ***************
  689. *** 2452,2459 ****
  690. --- 2589,2621 ----
  691.          && hdr1.ar_name[namelen] != '/';
  692.          namelen++);
  693.   
  694. + /* JPB, 7 Jun 1992: Support for long file names. Set the global variable
  695. +                     ar_hdr_size to the real length of the header.
  696. +                     The code for extracting the long name is pretty much stolen
  697. +                     from the BSD ar (archive.c, version 5.7).
  698. +                     This is a *really* ugly hack!
  699. + */
  700. + #if 1
  701. +   ar_hdr_size = sizeof(struct ar_hdr);
  702. +   if (!bcmp(hdr1.ar_name,AR_EFMT1,sizeof(AR_EFMT1) -1))
  703. +   {
  704. +     namelen = atoi(hdr1.ar_name + sizeof(AR_EFMT1) -1);
  705. +     if (namelen <= 0 || namelen > MAXNAMLEN)
  706. +       fatal_with_file("malformatted long name of archive member in ",library_entry);
  707. +     ar_hdr_size += namelen;
  708. +     name = (char *) xmalloc (namelen+1);
  709. +     if (read(desc,name,namelen) != namelen)
  710. +       fatal_with_file("malformatted long name of archive member in ",library_entry);
  711. +   }
  712. +   else
  713. +   {
  714. +     name = (char *) xmalloc (namelen+1);
  715. +     strncpy (name, hdr1.ar_name, namelen);
  716. +   }
  717. + #else
  718.     name = (char *) xmalloc (namelen+1);
  719.     strncpy (name, hdr1.ar_name, namelen);
  720. + #endif
  721.     name[namelen] = 0;
  722.   
  723.     subentry->filename = name;
  724. ***************
  725. *** 2461,2467 ****
  726. --- 2623,2633 ----
  727.     subentry->symbols = 0;
  728.     subentry->strings = 0;
  729.     subentry->subfiles = 0;
  730. + #if 1
  731. +   subentry->starting_offset = subfile_offset + ar_hdr_size;
  732. + #else
  733.     subentry->starting_offset = subfile_offset + sizeof hdr1;
  734. + #endif
  735.     subentry->superfile = library_entry;
  736.     subentry->library_flag = 0;
  737.     subentry->header_read_flag = 0;
  738. ***************
  739. *** 2473,2479 ****
  740.   
  741.     return subentry;
  742.   }
  743.   int subfile_wanted_p ();
  744.   
  745.   /* Search a library that has a __.SYMDEF member.
  746. --- 2639,2645 ----
  747.   
  748.     return subentry;
  749.   }
  750.   int subfile_wanted_p ();
  751.   
  752.   /* Search a library that has a __.SYMDEF member.
  753. ***************
  754. *** 2622,2628 ****
  755.   
  756.     free (symdef_data);
  757.   }
  758.   
  759.   /* Handle a subentry for a file with no __.SYMDEF. */
  760.   
  761. --- 2788,2794 ----
  762.   
  763.     free (symdef_data);
  764.   }
  765.   
  766.   /* Handle a subentry for a file with no __.SYMDEF. */
  767.   
  768. ***************
  769. *** 2675,2685 ****
  770.         if (!subentry) return;
  771.   
  772.         process_subentry (desc, subentry, entry, &prev);
  773.         this_subfile_offset += member_length + sizeof (struct ar_hdr);
  774.         if (this_subfile_offset & 1) this_subfile_offset++;
  775.       }
  776.   }
  777.   /* ENTRY is an entry for a library member.
  778.      Its symbols have been read into core, but not entered.
  779.      Return nonzero if we ought to load this member.  */
  780. --- 2841,2859 ----
  781.         if (!subentry) return;
  782.   
  783.         process_subentry (desc, subentry, entry, &prev);
  784. + #if 1
  785. + /* JPB, 7 Jun 1992: Can't count on sizeof(ar_hdr) to be the size of the entire
  786. +                     header: Long names extends the header. This is a *really*
  787. +                     ugly hack, using a global variable! */
  788. +       this_subfile_offset += member_length + ar_hdr_size;
  789. + #else
  790.         this_subfile_offset += member_length + sizeof (struct ar_hdr);
  791. + #endif
  792.         if (this_subfile_offset & 1) this_subfile_offset++;
  793.       }
  794.   }
  795.   /* ENTRY is an entry for a library member.
  796.      Its symbols have been read into core, but not entered.
  797.      Return nonzero if we ought to load this member.  */
  798. ***************
  799. *** 2777,2783 ****
  800.   
  801.     return 0;
  802.   }
  803.   void consider_file_section_lengths (), relocate_file_addresses ();
  804.   
  805.   /* Having entered all the global symbols and found the sizes of sections
  806. --- 2951,2957 ----
  807.   
  808.     return 0;
  809.   }
  810.   void consider_file_section_lengths (), relocate_file_addresses ();
  811.   
  812.   /* Having entered all the global symbols and found the sizes of sections
  813. ***************
  814. *** 2800,2806 ****
  815. --- 2974,2984 ----
  816.   
  817.     initialize_text_start ();
  818.   
  819. + #ifdef HUNK_INSTEAD_OF_A_OUT
  820. +   text_size = 0;
  821. + #else
  822.     text_size = text_header_size;
  823. + #endif
  824.   
  825.     /* Compute total size of sections */
  826.   
  827. ***************
  828. *** 2809,2825 ****
  829. --- 2987,3023 ----
  830.     /* If necessary, pad text section to full page in the file.
  831.        Include the padding in the text segment size.  */
  832.   
  833. + #ifndef HUNK_INSTEAD_OF_A_OUT
  834.     if (output_style == OUTPUT_READONLY_TEXT || output_style == OUTPUT_DEMAND_PAGED)
  835.       {
  836.         text_pad = ((text_size + page_size - 1) & (- page_size)) - text_size;
  837.         text_size += text_pad;
  838.       }
  839. + #endif
  840. + #ifdef HUNK_INSTEAD_OF_A_OUT
  841. +   /* they go into text if they are required */
  842. +   if (output_datadata_relocs && numdatadata_relocs)
  843. +     {
  844. +       if (datadata_reloc_symbol)
  845. +         datadata_reloc_symbol->value = text_size;
  846. +       
  847. +       /* 1 long for the size, then the vector */
  848. +       text_size += (1 + numdatadata_relocs) * 4;
  849. +     }
  850. + #endif
  851.   
  852.     /* Now that the text_size is known, initialize the data start address;
  853.        this depends on text_size as well as the output file format.  */
  854.   
  855.     initialize_data_start ();
  856.   
  857. + #ifdef HUNK_INSTEAD_OF_A_OUT
  858. +   data_pad = 0;
  859. + #endif
  860. + #ifndef HUNK_INSTEAD_OF_A_OUT
  861.     /* Make sure bss starts out aligned as much as anyone can want.  */
  862.     {
  863.       int new_data_size = (data_size + sizeof(double) - 1) & ~(sizeof(double)-1);
  864. ***************
  865. *** 2827,2832 ****
  866. --- 3025,3031 ----
  867.       data_pad += new_data_size - data_size;
  868.       data_size = new_data_size;
  869.     }
  870. + #endif
  871.   
  872.     /* Set up the set element vector */
  873.   
  874. ***************
  875. *** 2836,2843 ****
  876. --- 3035,3049 ----
  877.            for each symbol for the length word at the beginning of the
  878.        vector, plus a word for each symbol for a zero at the end of
  879.        the vector (for incremental linking).  */
  880. + #if 0
  881. +       /* I think this is the other way round !? ### mw */
  882.         set_sect_size
  883.       = (2 * set_symbol_count + set_vector_count) * sizeof (unsigned long);
  884. + #else
  885. +       set_sect_size
  886. +     = (2 * set_vector_count + set_symbol_count) * sizeof (unsigned long);
  887. + #endif
  888.         set_sect_start = data_start + data_size;
  889.         data_size += set_sect_size;
  890.         set_vectors = (unsigned long *) xmalloc (set_sect_size);
  891. ***************
  892. *** 2931,2937 ****
  893. --- 3137,3149 ----
  894.                     + (align - 1)) & (- align))
  895.                     - data_size - data_start);
  896.   
  897. + #ifdef HUNK_INSTEAD_OF_A_OUT
  898. +           sp->value = bss_size;
  899. +           if (databss_together)
  900. +             sp->value += data_start + data_size;
  901. + #else
  902.             sp->value = data_start + data_size + bss_size;
  903. + #endif
  904.             sp->defined = N_BSS | N_EXT;
  905.             bss_size += com;
  906.             if (write_map)
  907. ***************
  908. *** 2994,2999 ****
  909. --- 3206,3224 ----
  910.         etext_symbol_alt->value = etext_value;
  911.     }
  912.   
  913. + #ifdef amigados
  914. +   {
  915. +     if (sdata_symbol)
  916. +       sdata_symbol->value = data_start;
  917. +     if (text_size_symbol)
  918. +       text_size_symbol->value = text_size;
  919. +     if (data_size_symbol)
  920. +       data_size_symbol->value = data_size;
  921. +     if (bss_size_symbol)
  922. +       bss_size_symbol->value  = bss_size;
  923. +   }
  924. + #endif
  925.     {
  926.       int edata_value = data_start + data_size;
  927.       if (edata_symbol)
  928. ***************
  929. *** 3013,3021 ****
  930. --- 3238,3248 ----
  931.       if (specified_data_size && specified_data_size > data_size)
  932.         data_pad_additional = specified_data_size - data_size;
  933.   
  934. + #ifndef HUNK_INSTEAD_OF_A_OUT
  935.       if (output_style == OUTPUT_DEMAND_PAGED)
  936.         data_pad_additional =
  937.       ((data_pad_additional + data_size + page_size - 1) & (- page_size)) - data_size;
  938. + #endif
  939.   
  940.       bss_size -= data_pad_additional;
  941.       if (bss_size < 0) bss_size = 0;
  942. ***************
  943. *** 3024,3031 ****
  944.   
  945.       data_pad += data_pad_additional;
  946.     }
  947.   }
  948.   /* Accumulate the section sizes of input file ENTRY
  949.      into the section sizes of the output file.  */
  950.   
  951. --- 3251,3290 ----
  952.   
  953.       data_pad += data_pad_additional;
  954.     }
  955. + #ifdef HUNK_INSTEAD_OF_A_OUT
  956. +   /* if there is some code, assign it next hunk_number */
  957. +   if (text_size)
  958. +      number_of_code_hunk = current_hunk++;
  959. +   else
  960. +      number_of_code_hunk = -1;
  961. +   if (data_size)
  962. +      number_of_data_hunk = current_hunk++;
  963. +   else
  964. +      number_of_data_hunk = -1;
  965. +   if (bss_size)
  966. +      number_of_bss_hunk  = current_hunk++;
  967. +   else
  968. +      number_of_bss_hunk  = -1;
  969. +   if (databss_together)
  970. +     {
  971. +       if (data_size && bss_size)
  972. +     {
  973. +       current_hunk --;
  974. +       number_of_bss_hunk = number_of_data_hunk;
  975. +     }
  976. +     }
  977. +   if (strip_symbols != STRIP_ALL && !amiga_symbols_only)
  978. +      number_of_debug_hunk = current_hunk++;
  979. +   else
  980. +      number_of_debug_hunk = -1;
  981. + #endif
  982.   }
  983.   /* Accumulate the section sizes of input file ENTRY
  984.      into the section sizes of the output file.  */
  985.   
  986. ***************
  987. *** 3046,3051 ****
  988. --- 3305,3334 ----
  989.   
  990.     text_reloc_size += entry->text_reloc_size;
  991.     data_reloc_size += entry->data_reloc_size;
  992. + #ifdef HUNK_INSTEAD_OF_A_OUT
  993. +   if (! output_datadata_relocs)
  994. +     return;
  995. +   /* have to guess at how many datadata-relocs we might have. This number
  996. +      is larger than the real thing, because I have to include the references
  997. +      to UNDF symbols as well. */
  998. +   {
  999. +     struct relocation_info *r, *re, *reloc;
  1000. +     int desc = file_open (entry);
  1001. +     reloc = (struct relocation_info *) alloca (entry->data_reloc_size);
  1002. +     lseek (desc, entry->starting_offset + entry->data_reloc_offset, L_SET);
  1003. +     if (entry->data_reloc_size != read (desc, reloc, entry->data_reloc_size))
  1004. +       fatal_with_file ("premature eof in data relocation of ", entry);
  1005. +     
  1006. +     for (r = reloc, re = reloc + entry->data_reloc_size/sizeof(*re); r < re; r++)
  1007. +       if (RELOC_EXTERN_P (r) || ((RELOC_TYPE (r) & N_TYPE) != N_TEXT))
  1008. +     numdatadata_relocs ++;
  1009. +     file_close ();
  1010. +   }
  1011. + #endif
  1012.   }
  1013.   
  1014.   /* Determine where the sections of ENTRY go into the output file,
  1015. ***************
  1016. *** 3062,3068 ****
  1017.        for the portion of data_pad which overlaps with bss.  If they had
  1018.        been, we would get the wrong results here.  */
  1019.     entry->data_start_address += data_start;
  1020. !   entry->bss_start_address += data_start + data_size;
  1021.   
  1022.     {
  1023.       register struct nlist *p;
  1024. --- 3345,3356 ----
  1025.        for the portion of data_pad which overlaps with bss.  If they had
  1026.        been, we would get the wrong results here.  */
  1027.     entry->data_start_address += data_start;
  1028. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1029. !   if (databss_together)
  1030. ! #endif
  1031. !     entry->bss_start_address += data_start + data_size;
  1032.   
  1033.     {
  1034.       register struct nlist *p;
  1035. ***************
  1036. *** 3080,3087 ****
  1037.         case N_SETT:
  1038.           p->n_value += entry->text_start_address - entry->orig_text_address;
  1039.           break;
  1040. -       case N_DATA:
  1041.         case N_SETV:
  1042.         case N_SETD:
  1043.           /* Data segment symbol.  Subtract the address of the
  1044.              data segment in the input file, and add the address
  1045. --- 3368,3375 ----
  1046.         case N_SETT:
  1047.           p->n_value += entry->text_start_address - entry->orig_text_address;
  1048.           break;
  1049.         case N_SETV:
  1050. +       case N_DATA:
  1051.         case N_SETD:
  1052.           /* Data segment symbol.  Subtract the address of the
  1053.              data segment in the input file, and add the address
  1054. ***************
  1055. *** 3098,3104 ****
  1056.         }
  1057.     }
  1058.   }
  1059.   void describe_file_sections (), list_file_locals ();
  1060.   
  1061.   /* Print a complete or partial map of the output file.  */
  1062. --- 3386,3392 ----
  1063.         }
  1064.     }
  1065.   }
  1066.   void describe_file_sections (), list_file_locals ();
  1067.   
  1068.   /* Print a complete or partial map of the output file.  */
  1069. ***************
  1070. *** 3174,3180 ****
  1071.     entry->strings = 0;        /* All done with them.  */
  1072.   }
  1073.   
  1074.   /* Static vars for do_warnings and subroutines of it */
  1075.   int list_unresolved_refs;    /* List unresolved refs */
  1076.   int list_warning_symbols;    /* List warning syms */
  1077. --- 3462,3468 ----
  1078.     entry->strings = 0;        /* All done with them.  */
  1079.   }
  1080.   
  1081.   /* Static vars for do_warnings and subroutines of it */
  1082.   int list_unresolved_refs;    /* List unresolved refs */
  1083.   int list_warning_symbols;    /* List warning syms */
  1084. ***************
  1085. *** 3192,3198 ****
  1086.     struct nlist *sym;
  1087.   };
  1088.   
  1089. - void qsort ();
  1090.   /*
  1091.    * Helper routines for do_file_warnings.
  1092.    */
  1093. --- 3480,3485 ----
  1094. ***************
  1095. *** 3672,3678 ****
  1096.     free (data_scan);
  1097.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  1098.   }
  1099.   do_warnings (outfile)
  1100.        FILE *outfile;
  1101.   {
  1102. --- 3959,3965 ----
  1103.     free (data_scan);
  1104.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  1105.   }
  1106.   do_warnings (outfile)
  1107.        FILE *outfile;
  1108.   {
  1109. ***************
  1110. *** 3691,3697 ****
  1111.     if (list_unresolved_refs || list_multiple_defs)
  1112.       make_executable = 0;
  1113.   }
  1114.   #ifdef A_OUT
  1115.   
  1116.   /* Stuff pertaining to creating a.out files. */
  1117. --- 3978,3984 ----
  1118.     if (list_unresolved_refs || list_multiple_defs)
  1119.       make_executable = 0;
  1120.   }
  1121.   #ifdef A_OUT
  1122.   
  1123.   /* Stuff pertaining to creating a.out files. */
  1124. ***************
  1125. *** 3712,3717 ****
  1126. --- 3999,4009 ----
  1127.   {
  1128.     int magic;
  1129.   
  1130. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1131. +   text_start = 0;
  1132. +   return;
  1133. + #endif
  1134.     switch (output_style)
  1135.       {
  1136.       case OUTPUT_RELOCATABLE:
  1137. ***************
  1138. *** 3770,3775 ****
  1139. --- 4062,4072 ----
  1140.   void
  1141.   initialize_a_out_data_start ()
  1142.   {
  1143. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1144. +   data_start = 0;
  1145. +   return;
  1146. + #endif
  1147.     outheader.a_text = text_size;
  1148.   #ifdef sequent
  1149.     outheader.a_text += N_ADDRADJ (outheader);
  1150. ***************
  1151. *** 3923,3947 ****
  1152.   void
  1153.   write_a_out_header ()
  1154.   {
  1155. !   lseek (outdesc, 0L, 0);
  1156.   
  1157.   #ifdef COFF_ENCAPSULATE
  1158.     if (need_coff_header)
  1159. !     mywrite (&coffheader, sizeof coffheader, 1, outdesc);
  1160.   #endif
  1161.   
  1162. !   mywrite (&outheader, sizeof (struct exec), 1, outdesc);
  1163.   
  1164.     /* Output whatever padding is required in the executable file
  1165.        between the header and the start of the text.  */
  1166.   
  1167.   #ifndef COFF_ENCAPSULATE
  1168. !   padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
  1169.   #endif
  1170.   }
  1171.   
  1172.   #endif
  1173.   #ifdef MACH_O
  1174.   
  1175.   /* Stuff pertaining to creating Mach-O files. */
  1176. --- 4220,4244 ----
  1177.   void
  1178.   write_a_out_header ()
  1179.   {
  1180. !   fseek (outstream, 0L, 0);
  1181.   
  1182.   #ifdef COFF_ENCAPSULATE
  1183.     if (need_coff_header)
  1184. !     mywrite (&coffheader, sizeof coffheader, 1, outstream);
  1185.   #endif
  1186.   
  1187. !   mywrite (&outheader, sizeof (struct exec), 1, outstream);
  1188.   
  1189.     /* Output whatever padding is required in the executable file
  1190.        between the header and the start of the text.  */
  1191.   
  1192.   #ifndef COFF_ENCAPSULATE
  1193. !   padfile (N_TXTOFF (outheader) - sizeof outheader, outstream);
  1194.   #endif
  1195.   }
  1196.   
  1197.   #endif
  1198.   #ifdef MACH_O
  1199.   
  1200.   /* Stuff pertaining to creating Mach-O files. */
  1201. ***************
  1202. *** 4145,4151 ****
  1203.   #endif
  1204.     thread_state state;
  1205.   
  1206. !   lseek (outdesc, 0L, 0);
  1207.   
  1208.   
  1209.     header.magic = MH_MAGIC;
  1210. --- 4442,4448 ----
  1211.   #endif
  1212.     thread_state state;
  1213.   
  1214. !   fseek (outstream, 0L, 0);
  1215.   
  1216.   
  1217.     header.magic = MH_MAGIC;
  1218. ***************
  1219. *** 4251,4257 ****
  1220.   #ifdef LC_SYMSEG
  1221.         m_object.symseg = symseg;
  1222.   #endif
  1223. !       mywrite((char *) &m_object, 1, sizeof m_object, outdesc);
  1224.         break;
  1225.   
  1226.       default:
  1227. --- 4548,4554 ----
  1228.   #ifdef LC_SYMSEG
  1229.         m_object.symseg = symseg;
  1230.   #endif
  1231. !       mywrite((char *) &m_object, 1, sizeof m_object, outstream);
  1232.         break;
  1233.   
  1234.       default:
  1235. ***************
  1236. *** 4305,4311 ****
  1237.   #ifdef LC_SYMSEG
  1238.         m_exec.symseg = symseg;
  1239.   #endif
  1240. !       mywrite((char *) &m_exec, 1, sizeof m_exec, outdesc);
  1241.         break;
  1242.       }
  1243.   }
  1244. --- 4602,4608 ----
  1245.   #ifdef LC_SYMSEG
  1246.         m_exec.symseg = symseg;
  1247.   #endif
  1248. !       mywrite((char *) &m_exec, 1, sizeof m_exec, outstream);
  1249.         break;
  1250.       }
  1251.   }
  1252. ***************
  1253. *** 4386,4392 ****
  1254.   }
  1255.   
  1256.   #endif
  1257.   /* The following functions are simple switches according to the
  1258.      output style.  */
  1259.   
  1260. --- 4683,4689 ----
  1261.   }
  1262.   
  1263.   #endif
  1264.   /* The following functions are simple switches according to the
  1265.      output style.  */
  1266.   
  1267. ***************
  1268. *** 4484,4489 ****
  1269. --- 4781,4790 ----
  1270.   void
  1271.   write_header ()
  1272.   {
  1273. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1274. +   conditionally_rewrite_headers ();
  1275. +   return;
  1276. + #else
  1277.   #ifdef A_OUT
  1278.     if (output_file_type == IS_A_OUT)
  1279.       {
  1280. ***************
  1281. *** 4498,4506 ****
  1282.         return;
  1283.       }
  1284.   #endif
  1285.     fatal ("unknown output file type (enum file_type)", (char *) 0);
  1286.   }
  1287.   /* Write the output file */
  1288.   
  1289.   void
  1290. --- 4799,4808 ----
  1291.         return;
  1292.       }
  1293.   #endif
  1294. + #endif
  1295.     fatal ("unknown output file type (enum file_type)", (char *) 0);
  1296.   }
  1297.   /* Write the output file */
  1298.   
  1299.   void
  1300. ***************
  1301. *** 4519,4540 ****
  1302.        the way Unix ld works; I'm going to consider it a feature.  */
  1303.     (void) unlink (output_filename);
  1304.     
  1305. !   outdesc = open (output_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  1306. !   if (outdesc < 0) perror_name (output_filename);
  1307.   
  1308. !   if (fstat (outdesc, &statbuf) < 0)
  1309.       perror_name (output_filename);
  1310.   
  1311.     filemode = statbuf.st_mode;
  1312.   
  1313.     chmod (output_filename, filemode & ~0111);
  1314.   
  1315.     /* Calculate the offsets of the various pieces of the output file.  */
  1316.     compute_section_offsets ();
  1317.   
  1318.     /* Output the text and data segments, relocating as we go.  */
  1319.     write_text ();
  1320.     write_data ();
  1321.   
  1322.     /* Output the merged relocation info, if requested with `-r'.  */
  1323.     if (output_style == OUTPUT_RELOCATABLE)
  1324. --- 4821,4888 ----
  1325.        the way Unix ld works; I'm going to consider it a feature.  */
  1326.     (void) unlink (output_filename);
  1327.     
  1328. !   outstream = fopen (output_filename, "w");
  1329. !   if (outstream == 0) perror_name (output_filename);
  1330.   
  1331. ! #ifndef MCH_AMIGA
  1332. !   if (fstat (fileno (outstream), &statbuf) < 0)
  1333.       perror_name (output_filename);
  1334.   
  1335.     filemode = statbuf.st_mode;
  1336.   
  1337. +   /* this wouldn't work anyway, "file in use, error"... */
  1338.     chmod (output_filename, filemode & ~0111);
  1339. + #endif
  1340. +   /* on the Amiga, the following call DOES set the symbol offset, but
  1341. +    * it does it wrong, we'll be able to do it right, as soon as all the
  1342. +    * other data has been written.. */
  1343.   
  1344.     /* Calculate the offsets of the various pieces of the output file.  */
  1345.     compute_section_offsets ();
  1346.   
  1347. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1348. +   /* get ready to collect information where all symbols
  1349. +    * go. Since this has to be done only once, we'll later be able to 
  1350. +    * output the right symbol-hunk after the right (code/data/bss-)hunk. */
  1351. +   init_symbol_hunks ();
  1352. +   look_for_symbols ();
  1353. + #endif
  1354.     /* Output the text and data segments, relocating as we go.  */
  1355.     write_text ();
  1356.     write_data ();
  1357. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1358. +   if (datadata_relocs_offset)
  1359. +     write_datadata_relocs ();
  1360. +   write_bss ();
  1361. +   if (number_of_debug_hunk != -1)
  1362. +     {
  1363. +       /* ok, lets output the start of the debug hunk */
  1364. +       fseek (outstream, 0L, SEEK_END);
  1365. +       offset_of_debug_hunk = ftell (outstream);
  1366. +       dh.id = 0x3f1;     /* HUNK_DEBUG */
  1367. +       dh.len = 0;        /* we'll fill this in later */
  1368. +       dh.magic = ZMAGIC; /* when wishes came true... */
  1369. +       dh.syms = outheader.a_syms;
  1370. +       mywrite(&dh, sizeof dh, 1, outstream);
  1371. +       output_syms_offset   = ftell (outstream);
  1372. +       output_strs_offset   = output_syms_offset + dh.syms;
  1373. +       /* since we later will seek forward and backward to fill in each files
  1374. +        * symbol- and string-table, we have to create the needed space, that
  1375. +        * will be seeked over, since on an empty file, lseek(fd, 10, 0) will 
  1376. +        * position to byte 10 on Unix, but will just generate an error under
  1377. +        * AmigaDOS and stay at position 0. */
  1378. +       /* this will just write garbage, but thats enough:-)) */
  1379. +       mywrite(&output_strs_offset, dh.syms+4, 1, outstream);
  1380. +       fseek (outstream, output_syms_offset, 0);
  1381. +     }
  1382. + #endif
  1383.   
  1384.     /* Output the merged relocation info, if requested with `-r'.  */
  1385.     if (output_style == OUTPUT_RELOCATABLE)
  1386. ***************
  1387. *** 4547,4568 ****
  1388.        are finalized.  */
  1389.     compute_more_section_offsets ();
  1390.   
  1391.     /* Copy any GDB symbol segments from input files.  */
  1392.     write_symsegs ();
  1393.   
  1394.     /* Now that everything is known about the output file, write its header.  */
  1395.     write_header ();
  1396.   
  1397. !   close (outdesc);
  1398.   
  1399.     mask = umask (0);
  1400.     umask (mask);
  1401.   
  1402.     if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
  1403.       perror_name (output_filename);
  1404.   }
  1405.   void modify_location (), perform_relocation (), copy_text (), copy_data ();
  1406.   
  1407.   /* Relocate the text segment of each input file
  1408.      and write to the output file.  */
  1409. --- 4895,4928 ----
  1410.        are finalized.  */
  1411.     compute_more_section_offsets ();
  1412.   
  1413. + #ifndef HUNK_INSTEAD_OF_A_OUT
  1414. +   /* I don't support GDB-symbol segments, they aren't used anymore by
  1415. +    * the newer versions of gdb, BUT of course, if somebody needs them..
  1416. +    * that's exactly why I introduced the "dh.strs" Parameter, so that
  1417. +    * you could - as in Unix - append these segments at the end of the file */
  1418.     /* Copy any GDB symbol segments from input files.  */
  1419.     write_symsegs ();
  1420. + #endif
  1421.   
  1422.     /* Now that everything is known about the output file, write its header.  */
  1423.     write_header ();
  1424.   
  1425. !   fclose (outstream);
  1426.   
  1427. + #ifndef HUNK_INSTEAD_OF_A_OUT
  1428.     mask = umask (0);
  1429.     umask (mask);
  1430.   
  1431.     if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
  1432.       perror_name (output_filename);
  1433. + #endif
  1434.   }
  1435.   void modify_location (), perform_relocation (), copy_text (), copy_data ();
  1436. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1437. + void write_hunk_header();
  1438. + #endif
  1439.   
  1440.   /* Relocate the text segment of each input file
  1441.      and write to the output file.  */
  1442. ***************
  1443. *** 4573,4587 ****
  1444.     if (trace_files)
  1445.       fprintf (stderr, "Copying and relocating text:\n\n");
  1446.   
  1447. !   lseek (outdesc, output_text_offset + text_header_size, 0);
  1448.   
  1449.     each_full_file (copy_text, 0);
  1450.     file_close ();
  1451.   
  1452.     if (trace_files)
  1453.       fprintf (stderr, "\n");
  1454.   
  1455. !   padfile (text_pad, outdesc);
  1456.   }
  1457.   
  1458.   /* Read in all of the relocation information */
  1459. --- 4933,4987 ----
  1460.     if (trace_files)
  1461.       fprintf (stderr, "Copying and relocating text:\n\n");
  1462.   
  1463. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1464. !   /* this is a definitive write, we don't need to rewrite this out, since
  1465. !    * the yet undefined sizes of the reloc-hunks don't go into the 
  1466. !    * header-hunk */
  1467. !   write_hunk_header(outstream);
  1468. !   init_reloc_hunk();
  1469. !   /* and if there's no code-hunk, we can return here.. no sense in
  1470. !    * complicately doing just nothing... */
  1471. !   if (number_of_code_hunk == -1) return;
  1472. !   /* else start the code-hunk */
  1473. !   {
  1474. !      long code_header[2];
  1475. !      code_header[0] = 0x3e9;
  1476. !      code_header[1] = LONGSIZE(text_size);
  1477. !      mywrite(code_header, 1, sizeof code_header, outstream);
  1478. !   }
  1479. ! #else
  1480. !   fseek (outstream, output_text_offset + text_header_size, 0);
  1481. ! #endif
  1482.   
  1483.     each_full_file (copy_text, 0);
  1484. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1485. +   if (output_datadata_relocs && numdatadata_relocs)
  1486. +     {
  1487. +       int i, zero = 0;
  1488. +       /* include the size-field, -> <= . The `real' values come later */
  1489. +       datadata_relocs_offset = ftell (outstream);
  1490. +       for (i = 0; i <= numdatadata_relocs; i ++)
  1491. +         mywrite (&zero, 1, sizeof (long), outstream);
  1492. +     }
  1493. + #endif
  1494.     file_close ();
  1495.   
  1496.     if (trace_files)
  1497.       fprintf (stderr, "\n");
  1498.   
  1499. !   padfile (text_pad, outstream);
  1500. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1501. !   write_reloc_hunk();
  1502. !   write_symbol_hunk(number_of_code_hunk);
  1503. !   {
  1504. !     long hunk_end = 0x3f2;
  1505. !     mywrite(&hunk_end, 1, sizeof(long), outstream);
  1506. !   }
  1507. ! #endif
  1508.   }
  1509.   
  1510.   /* Read in all of the relocation information */
  1511. ***************
  1512. *** 4686,4700 ****
  1513.       fatal_with_file ("premature eof in text section of ", entry);
  1514.   
  1515.     /* Relocate the text according to the text relocation.  */
  1516.     perform_relocation (bytes, entry->text_start_address - entry->orig_text_address,
  1517.                 entry->text_size, reloc, entry->text_reloc_size, entry);
  1518.   
  1519.     /* Write the relocated text to the output file.  */
  1520.   
  1521. !   mywrite (bytes, 1, entry->text_size, outdesc);
  1522.   }
  1523.   /* Relocate the data segment of each input file
  1524.      and write to the output file.  */
  1525.   
  1526. --- 5086,5099 ----
  1527.       fatal_with_file ("premature eof in text section of ", entry);
  1528.   
  1529.     /* Relocate the text according to the text relocation.  */
  1530.     perform_relocation (bytes, entry->text_start_address - entry->orig_text_address,
  1531.                 entry->text_size, reloc, entry->text_reloc_size, entry);
  1532.   
  1533.     /* Write the relocated text to the output file.  */
  1534.   
  1535. !   mywrite (bytes, 1, entry->text_size, outstream);
  1536.   }
  1537.   /* Relocate the data segment of each input file
  1538.      and write to the output file.  */
  1539.   
  1540. ***************
  1541. *** 4704,4710 ****
  1542.     if (trace_files)
  1543.       fprintf (stderr, "Copying and relocating data:\n\n");
  1544.   
  1545. !   lseek (outdesc, output_data_offset, 0);
  1546.   
  1547.     each_full_file (copy_data, 0);
  1548.     file_close ();
  1549. --- 5103,5126 ----
  1550.     if (trace_files)
  1551.       fprintf (stderr, "Copying and relocating data:\n\n");
  1552.   
  1553. ! #ifndef HUNK_INSTEAD_OF_A_OUT
  1554. !   fseek (outstream, output_data_offset, 0);
  1555. ! #else
  1556. !   /* just have to hope that the file is positioned correctly.. */
  1557. !   init_reloc_hunk();
  1558. !   /* start a data-hunk, if there is data to be output */
  1559. !   if (number_of_data_hunk == -1) return;
  1560. !   {
  1561. !     long data_header[2];
  1562. !     data_header[0] = 0x3ea;
  1563. !     if (databss_together)
  1564. !       data_header[1] = LONGSIZE(data_size + bss_size);
  1565. !     else
  1566. !       data_header[1] = LONGSIZE(data_size);
  1567. !     mywrite(data_header, 1, sizeof data_header, outstream);
  1568. !   }
  1569. ! #endif
  1570.   
  1571.     each_full_file (copy_data, 0);
  1572.     file_close ();
  1573. ***************
  1574. *** 4713,4725 ****
  1575.        description of length of the set vector section.  */
  1576.   
  1577.     if (set_vector_count)
  1578. !     mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
  1579. !          sizeof (unsigned long), outdesc);
  1580.   
  1581.     if (trace_files)
  1582.       fprintf (stderr, "\n");
  1583.   
  1584. !   padfile (data_pad, outdesc);
  1585.   }
  1586.   
  1587.   /* Read the data segment contents of ENTRY, relocate them,
  1588. --- 5129,5172 ----
  1589.        description of length of the set vector section.  */
  1590.   
  1591.     if (set_vector_count)
  1592. !     {
  1593. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1594. !      /* this and mywrite later: inverted set_symbol_count and 
  1595. !       * set_vector_count, guess they were mixed up before   ### mw */
  1596. !       relocate_set_vectors (set_vectors,
  1597. !                 2 * set_vector_count + set_symbol_count);
  1598. ! #endif
  1599. ! #if 0
  1600. !       mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
  1601. !            sizeof (unsigned long), outstream);
  1602. ! #else
  1603. !       mywrite (set_vectors, 2 * set_vector_count + set_symbol_count,
  1604. !            sizeof (unsigned long), outstream);
  1605. ! #endif
  1606. !     }
  1607.   
  1608.     if (trace_files)
  1609.       fprintf (stderr, "\n");
  1610.   
  1611. !   padfile (data_pad, outstream);
  1612. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1613. !   if (databss_together && bss_size)
  1614. !     {
  1615. !       /* dump zeros */
  1616. !       int i, zero = 0;
  1617. !       for (i = 0; i < LONGSIZE(bss_size); i++)
  1618. !     mywrite (&zero, 1, sizeof (long), outstream);
  1619. !     }
  1620. !   write_reloc_hunk();
  1621. !   write_symbol_hunk(number_of_data_hunk);
  1622. !   {
  1623. !     long hunk_end = 0x3f2;
  1624. !     mywrite(&hunk_end, 1, sizeof(long), outstream);
  1625. !   }
  1626. ! #endif
  1627.   }
  1628.   
  1629.   /* Read the data segment contents of ENTRY, relocate them,
  1630. ***************
  1631. *** 4765,4776 ****
  1632.     if (entry->data_size != read (desc, bytes, entry->data_size))
  1633.       fatal_with_file ("premature eof in data section of ", entry);
  1634.   
  1635. !   perform_relocation (bytes, entry->data_start_address - entry->orig_data_address,
  1636. !               entry->data_size, reloc, entry->data_reloc_size, entry);
  1637.   
  1638. !   mywrite (bytes, 1, entry->data_size, outdesc);
  1639.   }
  1640.   /* Relocate ENTRY's text or data section contents.
  1641.      DATA is the address of the contents, in core.
  1642.      DATA_SIZE is the length of the contents.
  1643. --- 5212,5227 ----
  1644.     if (entry->data_size != read (desc, bytes, entry->data_size))
  1645.       fatal_with_file ("premature eof in data section of ", entry);
  1646.   
  1647. !   perform_relocation (bytes, entry->data_start_address 
  1648. ! #ifndef HUNK_INSTEAD_OF_A_OUT
  1649. !                         - entry->orig_data_address
  1650. ! #endif
  1651. !                                     ,
  1652. !                 entry->data_size, reloc, entry->data_reloc_size, entry);
  1653.   
  1654. !   mywrite (bytes, 1, entry->data_size, outstream);
  1655.   }
  1656.   /* Relocate ENTRY's text or data section contents.
  1657.      DATA is the address of the contents, in core.
  1658.      DATA_SIZE is the length of the contents.
  1659. ***************
  1660. *** 4796,4806 ****
  1661. --- 5247,5266 ----
  1662.     int data_relocation = entry->data_start_address - entry->orig_data_address;
  1663.     int bss_relocation = entry->bss_start_address - entry->orig_bss_address;
  1664.   
  1665. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1666. +   int this_hunk;
  1667. + #endif
  1668.     for (; p < end; p++)
  1669.       {
  1670.         register int relocation = 0;
  1671.         register int addr = RELOC_ADDRESS(p);
  1672.         register unsigned int mask = 0;
  1673. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1674. +       int ext_abs;
  1675. +       
  1676. +       ext_abs = 0;
  1677. + #endif
  1678.   
  1679.         if (addr >= data_size)
  1680.       fatal_with_file ("relocation address out of range in ", entry);
  1681. ***************
  1682. *** 4827,4848 ****
  1683.           relocation = 0;
  1684.         else
  1685.           relocation = sp->value;
  1686.       }
  1687.         else switch (RELOC_TYPE(p))
  1688.       {
  1689.       case N_TEXT:
  1690.       case N_TEXT | N_EXT:
  1691. !       relocation = text_relocation;
  1692.         break;
  1693.   
  1694.       case N_DATA:
  1695.       case N_DATA | N_EXT:
  1696. !       relocation = data_relocation;
  1697.         break;
  1698.   
  1699.       case N_BSS:
  1700.       case N_BSS | N_EXT:
  1701. !       relocation = bss_relocation;
  1702.         break;
  1703.   
  1704.       case N_ABS:
  1705. --- 5287,5366 ----
  1706.           relocation = 0;
  1707.         else
  1708.           relocation = sp->value;
  1709. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1710. +       if ((sp->defined & ~N_EXT) == N_ABS)
  1711. +         /* sort of a kludge.. the only external symbol (not pcrelative)
  1712. +              * we can really resolve.. */
  1713. +         ext_abs = 1;
  1714. +       else if ((sp->defined & ~N_EXT) == N_TEXT ||
  1715. +           (sp->defined & ~N_EXT) == N_SETT)
  1716. +         {
  1717. +           this_hunk = number_of_code_hunk;
  1718. +           if (RELOC_BASEREL_P (p))
  1719. +             {
  1720. +               fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1721. +                          p->r_symbolnum, p->r_extern, p->r_address);
  1722. +           fatal_with_file ("base relative text relocation in ", entry);
  1723. +         }
  1724. +         }
  1725. +       else if ((sp->defined & ~N_EXT) == N_DATA ||
  1726. +                (sp->defined & ~N_EXT) == N_SETD ||
  1727. +            (sp->defined & ~N_EXT) == N_SETV)
  1728. +         {
  1729. +           this_hunk = number_of_data_hunk;
  1730. +         }
  1731. +       else if ((sp->defined & ~N_EXT) == N_BSS ||
  1732. +            (sp->defined & ~N_EXT) == N_UNDF ||
  1733. +                (sp->defined & ~N_EXT) == N_SETB)
  1734. +         {
  1735. +           this_hunk = number_of_bss_hunk;
  1736. +         }
  1737. +       else    
  1738. +         fatal_with_file ("external symbol with unknown type $%x in ", entry, sp->defined);
  1739. + #endif
  1740.       }
  1741.         else switch (RELOC_TYPE(p))
  1742.       {
  1743.       case N_TEXT:
  1744.       case N_TEXT | N_EXT:
  1745. !       if (RELOC_BASEREL_P (p))
  1746. !         {
  1747. !           fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1748. !                      p->r_symbolnum, p->r_extern, p->r_address);
  1749. !           fatal_with_file ("base relative text relocation in ", entry);
  1750. !         }
  1751. !       else
  1752. !         relocation = text_relocation;
  1753. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1754. !       this_hunk = number_of_code_hunk;
  1755. ! #endif
  1756.         break;
  1757.   
  1758.       case N_DATA:
  1759.       case N_DATA | N_EXT:
  1760. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1761. !       if (RELOC_BASEREL_P (p))
  1762. !         relocation = entry->data_start_address;
  1763. !       else
  1764. ! #endif
  1765. !         relocation = data_relocation;
  1766. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1767. !       this_hunk = number_of_data_hunk;
  1768. ! #endif
  1769.         break;
  1770.   
  1771.       case N_BSS:
  1772.       case N_BSS | N_EXT:
  1773. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1774. !       if (RELOC_BASEREL_P (p))
  1775. !         relocation = entry->bss_start_address - entry->data_size;
  1776. !       else
  1777. ! #endif
  1778. !         relocation = bss_relocation;
  1779. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1780. !       this_hunk = number_of_bss_hunk;
  1781. ! #endif
  1782.         break;
  1783.   
  1784.       case N_ABS:
  1785. ***************
  1786. *** 4854,4862 ****
  1787. --- 5372,5405 ----
  1788.         fatal_with_file ("nonexternal relocation code invalid in ", entry);
  1789.       }
  1790.   
  1791. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1792. +       /* in this case, ONLY relocate those pc-relative 32bit jumps, that
  1793. +        * gas generates, since they are position independent, this gives
  1794. +        * a HUGE.. 'if' inside of '#ifdef' oh well... */
  1795. +       if (RELOC_PCREL_P(p) || RELOC_BASEREL_P(p) || ext_abs) {
  1796. +       
  1797. +       /* VERY BIG KLUDGE AHEAD! Since this amiga hunk format is really
  1798. +        * limited, 8bit and 16bit references are always defined to be
  1799. +        * pc-relative (according to the AmigaDOS RM 2nd ed). BUT if such
  1800. +        * a symbol is resolved by an absolute symbol then it's not considered
  1801. +        * to be pc-relative any more. This is nowhere documented, but you
  1802. +        * couldn't get
  1803. +        *   jsr _LVOOpen(a6)
  1804. +        * to work if you wouldn't do it this way. */
  1805. +        if (ext_abs) RELOC_PCREL_P(p) = 0;
  1806. +       
  1807. + #endif
  1808.         if (RELOC_PCREL_P(p))
  1809.       relocation -= pc_relocation;
  1810.   
  1811. +       /* if base relative, subtract 64k/2, so we get a larger range */
  1812. +       if (RELOC_BASEREL_P(p))
  1813. +     {
  1814. +       if (! databss_together)
  1815. +         fatal_with_file ("Reloc is base relative. Specify -databss-together in ", entry);
  1816. +       relocation -= 0x7ffe;
  1817. +     }
  1818.   #ifdef RELOC_ADD_EXTRA
  1819.         relocation += RELOC_ADD_EXTRA(p);
  1820.         if (output_style == OUTPUT_RELOCATABLE)
  1821. ***************
  1822. *** 4895,4901 ****
  1823.         /* Shift everything up to where it's going to be used */
  1824.         relocation <<= RELOC_TARGET_BITPOS(p);
  1825.         mask <<= RELOC_TARGET_BITPOS(p);
  1826.         switch (RELOC_TARGET_SIZE(p))
  1827.       {
  1828.       case 0:
  1829. --- 5438,5443 ----
  1830. ***************
  1831. *** 4903,4920 ****
  1832. --- 5445,5483 ----
  1833.           relocation -= mask & *(char *) (data + addr);
  1834.         else if (RELOC_MEMORY_ADD_P(p))
  1835.           relocation += mask & *(char *) (data + addr);
  1836. +       if (relocation < -128 || relocation > 127)
  1837. +         fatal_with_file ("Byte reloc overflow in ", entry);
  1838.         *(char *) (data + addr) &= ~mask;
  1839.         *(char *) (data + addr) |= relocation;
  1840.         break;
  1841.   
  1842.       case 1:
  1843. +       {
  1844. +       int r=relocation;
  1845.         if (RELOC_MEMORY_SUB_P(p))
  1846.           relocation -= mask & *(short *) (data + addr);
  1847.         else if (RELOC_MEMORY_ADD_P(p))
  1848.           relocation += mask & *(short *) (data + addr);
  1849. +       if (relocation < -32768 || relocation > 32767)
  1850. +         {
  1851. +           fprintf (stderr, "relocation = $%lx, bsr = %d, pcr = %d, r= $%lx\n",
  1852. +                      relocation, RELOC_BASEREL_P(p), RELOC_PCREL_P (p), r);
  1853. +           fprintf (stderr, "textr = $%x, datar = $%x, bssr = $%x\n",
  1854. +                      text_relocation, data_relocation, bss_relocation);
  1855. +           fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1856. +                      p->r_symbolnum, p->r_extern, p->r_address);
  1857. +           fprintf (stderr, "data_size = %d, bss_size = %d.\n",
  1858. +                data_size, bss_size);
  1859. +           fatal_with_file ("Word reloc overflow in ", entry);
  1860. +         }
  1861.         *(short *) (data + addr) &= ~mask;
  1862.         *(short *) (data + addr) |= relocation;
  1863.         break;
  1864. +       }
  1865.   
  1866.       case 2:
  1867.   #ifdef CROSS_LINKER
  1868. ***************
  1869. *** 4937,4942 ****
  1870. --- 5500,5506 ----
  1871.           relocation -= mask & *(long *) (data + addr);
  1872.         else if (RELOC_MEMORY_ADD_P(p))
  1873.           relocation += mask & *(long *) (data + addr);
  1874.         *(long *) (data + addr) &= ~mask;
  1875.         *(long *) (data + addr) |= relocation;
  1876.   #endif /* not CROSS_LINKER */
  1877. ***************
  1878. *** 4945,4953 ****
  1879.       default:
  1880.         fatal_with_file ("Unimplemented relocation field length in ", entry);
  1881.       }
  1882.       }
  1883.   }
  1884.   /* For OUTPUT_RELOCATABLE only: write out the relocation,
  1885.      relocating the addresses-to-be-relocated.  */
  1886.   
  1887. --- 5509,5535 ----
  1888.       default:
  1889.         fatal_with_file ("Unimplemented relocation field length in ", entry);
  1890.       }
  1891. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1892. +     /* now finish this huge 'if' .. */
  1893. +     }
  1894. +     else
  1895. +       {
  1896. +         /* this only deals with 32bit relocs, the Amiga-loader
  1897. +          * doesn't support 1 or 2 byte relocs, they are only defined
  1898. +          * inside program-units (commonly known as object-files:-)) */
  1899. +         if (RELOC_TARGET_SIZE(p) != 2)
  1900. +           fatal_with_file ("unsupported reloc-size in ", entry);
  1901. +         *(long *) (data + addr) += relocation;
  1902. +         addr += pc_relocation;
  1903. +             add_to_reloc_hunk(this_hunk, addr);
  1904. +       }
  1905. + #endif
  1906.       }
  1907.   }
  1908.   /* For OUTPUT_RELOCATABLE only: write out the relocation,
  1909.      relocating the addresses-to-be-relocated.  */
  1910.   
  1911. ***************
  1912. *** 4995,5007 ****
  1913.   
  1914.     /* Write out the relocations of all files, remembered from copy_text.  */
  1915.   
  1916. !   lseek (outdesc, output_trel_offset, 0);
  1917.     each_full_file (coptxtrel, 0);
  1918.   
  1919.     if (trace_files)
  1920.       fprintf (stderr, "\nWriting data relocation:\n\n");
  1921.   
  1922. !   lseek (outdesc, output_drel_offset, 0);
  1923.     each_full_file (copdatrel, 0);
  1924.   
  1925.     if (trace_files)
  1926. --- 5577,5589 ----
  1927.   
  1928.     /* Write out the relocations of all files, remembered from copy_text.  */
  1929.   
  1930. !   fseek (outstream, output_trel_offset, 0);
  1931.     each_full_file (coptxtrel, 0);
  1932.   
  1933.     if (trace_files)
  1934.       fprintf (stderr, "\nWriting data relocation:\n\n");
  1935.   
  1936. !   fseek (outstream, output_drel_offset, 0);
  1937.     each_full_file (copdatrel, 0);
  1938.   
  1939.     if (trace_files)
  1940. ***************
  1941. *** 5076,5082 ****
  1942.                   entry->text_reloc_size / sizeof (struct relocation_info));
  1943.   #endif
  1944.   
  1945. !   mywrite (entry->textrel, 1, entry->text_reloc_size, outdesc);
  1946.   }
  1947.   
  1948.   void
  1949. --- 5658,5664 ----
  1950.                   entry->text_reloc_size / sizeof (struct relocation_info));
  1951.   #endif
  1952.   
  1953. !   mywrite (entry->textrel, 1, entry->text_reloc_size, outstream);
  1954.   }
  1955.   
  1956.   void
  1957. ***************
  1958. *** 5155,5163 ****
  1959.                   entry->data_reloc_size / sizeof (struct relocation_info));
  1960.   #endif
  1961.   
  1962. !   mywrite (entry->datarel, 1, entry->data_reloc_size, outdesc);
  1963.   }
  1964.   void write_file_syms ();
  1965.   void write_string_table ();
  1966.   
  1967. --- 5737,5745 ----
  1968.                   entry->data_reloc_size / sizeof (struct relocation_info));
  1969.   #endif
  1970.   
  1971. !   mywrite (entry->datarel, 1, entry->data_reloc_size, outstream);
  1972.   }
  1973.   void write_file_syms ();
  1974.   void write_string_table ();
  1975.   
  1976. ***************
  1977. *** 5192,5199 ****
  1978.     return index;
  1979.   }
  1980.   
  1981. - FILE *outstream = (FILE *) 0;
  1982.   /* Write the contents of `strtab_vector' into the string table.
  1983.      This is done once for each file's local&debugger symbols
  1984.      and once for the global symbols.  */
  1985. --- 5774,5779 ----
  1986. ***************
  1987. *** 5203,5212 ****
  1988.   {
  1989.     register int i;
  1990.   
  1991. !   lseek (outdesc, output_strs_offset + output_strs_size, 0);
  1992.   
  1993.     if (!outstream)
  1994.       outstream = fdopen (outdesc, "w");
  1995.   
  1996.     for (i = 0; i < strtab_index; i++)
  1997.       {
  1998. --- 5783,5794 ----
  1999.   {
  2000.     register int i;
  2001.   
  2002. !   fseek (outstream, output_strs_offset + output_strs_size, 0);
  2003.   
  2004. + #if 0
  2005.     if (!outstream)
  2006.       outstream = fdopen (outdesc, "w");
  2007. + #endif
  2008.   
  2009.     for (i = 0; i < strtab_index; i++)
  2010.       {
  2011. ***************
  2012. *** 5220,5226 ****
  2013.     if (ferror (outstream))
  2014.       perror_name (output_filename);
  2015.   }
  2016.   /* Write the symbol table and string table of the output file.  */
  2017.   
  2018.   void
  2019. --- 5802,5808 ----
  2020.     if (ferror (outstream))
  2021.       perror_name (output_filename);
  2022.   }
  2023.   /* Write the symbol table and string table of the output file.  */
  2024.   
  2025.   void
  2026. ***************
  2027. *** 5248,5253 ****
  2028. --- 5830,5841 ----
  2029.     /* Pointer for storing into BUF.  */
  2030.     register struct nlist *bufp = buf;
  2031.   
  2032. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2033. +   /* this enables us to output "regular" amiga symbols without
  2034. +    * the BSD-like debug-hunk */
  2035. +   if (number_of_debug_hunk == -1) return;
  2036. + #endif
  2037.     /* Size of string table includes the bytes that store the size.  */
  2038.     strtab_size = sizeof strtab_size;
  2039.   
  2040. ***************
  2041. *** 5370,5377 ****
  2042.   
  2043.     /* Output the buffer full of `struct nlist's.  */
  2044.   
  2045. !   lseek (outdesc, output_syms_offset + output_syms_size, 0);
  2046. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
  2047.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2048.   
  2049.     if (syms_written != nsyms)
  2050. --- 5958,5965 ----
  2051.   
  2052.     /* Output the buffer full of `struct nlist's.  */
  2053.   
  2054. !   fseek (outstream, output_syms_offset + output_syms_size, 0);
  2055. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
  2056.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2057.   
  2058.     if (syms_written != nsyms)
  2059. ***************
  2060. *** 5380,5393 ****
  2061.     /* Now the total string table size is known, so write it into the
  2062.        first word of the string table.  */
  2063.   
  2064. !   lseek (outdesc, output_strs_offset, 0);
  2065. !   mywrite (&strtab_size, sizeof (int), 1, outdesc);
  2066.   
  2067.     /* Write the strings for the global symbols.  */
  2068.   
  2069.     write_string_table ();
  2070.   }
  2071.   /* Write the local and debugger symbols of file ENTRY.
  2072.      Increment *SYMS_WRITTEN_ADDR for each symbol that is written.  */
  2073.   
  2074. --- 5968,5981 ----
  2075.     /* Now the total string table size is known, so write it into the
  2076.        first word of the string table.  */
  2077.   
  2078. !   fseek (outstream, output_strs_offset, 0);
  2079. !   mywrite (&strtab_size, sizeof (int), 1, outstream);
  2080.   
  2081.     /* Write the strings for the global symbols.  */
  2082.   
  2083.     write_string_table ();
  2084.   }
  2085.   /* Write the local and debugger symbols of file ENTRY.
  2086.      Increment *SYMS_WRITTEN_ADDR for each symbol that is written.  */
  2087.   
  2088. ***************
  2089. *** 5489,5496 ****
  2090.   
  2091.     /* All the symbols are now in BUF; write them.  */
  2092.   
  2093. !   lseek (outdesc, output_syms_offset + output_syms_size, 0);
  2094. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
  2095.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2096.   
  2097.     /* Write the string-table data for the symbols just written,
  2098. --- 6077,6084 ----
  2099.   
  2100.     /* All the symbols are now in BUF; write them.  */
  2101.   
  2102. !   fseek (outstream, output_syms_offset + output_syms_size, 0);
  2103. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
  2104.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2105.   
  2106.     /* Write the string-table data for the symbols just written,
  2107. ***************
  2108. *** 5499,5505 ****
  2109.     write_string_table ();
  2110.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  2111.   }
  2112.   /* Copy any GDB symbol segments from the input files to the output file.
  2113.      The contents of the symbol segment is copied without change
  2114.      except that we store some information into the beginning of it.  */
  2115. --- 6087,6093 ----
  2116.     write_string_table ();
  2117.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  2118.   }
  2119.   /* Copy any GDB symbol segments from the input files to the output file.
  2120.      The contents of the symbol segment is copied without change
  2121.      except that we store some information into the beginning of it.  */
  2122. ***************
  2123. *** 5509,5515 ****
  2124.   void
  2125.   write_symsegs ()
  2126.   {
  2127. !   lseek (outdesc, output_symseg_offset, 0);
  2128.     each_file (write_file_symseg, 0);
  2129.   }
  2130.   
  2131. --- 6097,6103 ----
  2132.   void
  2133.   write_symsegs ()
  2134.   {
  2135. !   fseek (outstream, output_symseg_offset, 0);
  2136.     each_file (write_file_symseg, 0);
  2137.   }
  2138.   
  2139. ***************
  2140. *** 5544,5550 ****
  2141.   
  2142.     /* Write the modified root into the output file.  */
  2143.   
  2144. !   mywrite (&root, sizeof root, 1, outdesc);
  2145.   
  2146.     /* Copy the rest of the symbol segment unchanged.  */
  2147.   
  2148. --- 6132,6138 ----
  2149.   
  2150.     /* Write the modified root into the output file.  */
  2151.   
  2152. !   mywrite (&root, sizeof root, 1, outstream);
  2153.   
  2154.     /* Copy the rest of the symbol segment unchanged.  */
  2155.   
  2156. ***************
  2157. *** 5557,5568 ****
  2158.         if (len != min (sizeof buffer, total))
  2159.       fatal_with_file ("premature end of file in symbol segment of ", entry);
  2160.         total -= len;
  2161. !       mywrite (buffer, len, 1, outdesc);
  2162.       }
  2163.   
  2164.     file_close ();
  2165.   }
  2166.   /* Define a special symbol (etext, edata, or end).  NAME is the
  2167.      name of the symbol, with a leading underscore (whether or not this
  2168.      system uses such underscores).  TYPE is its type (e.g. N_DATA | N_EXT).
  2169. --- 6145,6156 ----
  2170.         if (len != min (sizeof buffer, total))
  2171.       fatal_with_file ("premature end of file in symbol segment of ", entry);
  2172.         total -= len;
  2173. !       mywrite (buffer, len, 1, outstream);
  2174.       }
  2175.   
  2176.     file_close ();
  2177.   }
  2178.   /* Define a special symbol (etext, edata, or end).  NAME is the
  2179.      name of the symbol, with a leading underscore (whether or not this
  2180.      system uses such underscores).  TYPE is its type (e.g. N_DATA | N_EXT).
  2181. ***************
  2182. *** 5616,5621 ****
  2183. --- 6204,6235 ----
  2184.     symbol_define ("__etext", N_TEXT | N_EXT, &etext_symbol_alt);
  2185.     symbol_define ("__end", N_BSS | N_EXT, &end_symbol_alt);
  2186.   
  2187. + #ifdef amigados
  2188. +   if (output_datadata_relocs)
  2189. +     symbol_define ("___datadata_relocs", N_TEXT | N_EXT, &datadata_reloc_symbol);
  2190. +   symbol_define ("__sdata", N_DATA | N_EXT, &sdata_symbol);
  2191. +   symbol_define ("___text_size", N_ABS | N_EXT, &text_size_symbol);
  2192. +   symbol_define ("___data_size", N_ABS | N_EXT, &data_size_symbol);
  2193. +   symbol_define ("___bss_size", N_ABS | N_EXT, &bss_size_symbol);
  2194. +   {
  2195. +     symbol *a_symbol;
  2196. +     symbol_define ("___machtype", N_ABS | N_EXT, &a_symbol);
  2197. +     if (a_symbol)
  2198. +       a_symbol->value = amiga_machtype;
  2199. +       
  2200. +     symbol_define ("___databss_together", N_ABS | N_EXT, &a_symbol);
  2201. +     if (a_symbol)
  2202. +       a_symbol->value = databss_together;
  2203. +       
  2204. +     if (databss_together)
  2205. +       {
  2206. +         symbol_define ("___a4_init", N_DATA | N_EXT, &a_symbol);
  2207. +         if (a_symbol)
  2208. +           a_symbol->value = data_start + 0x7ffe;
  2209. +       }
  2210. +   }
  2211. + #endif
  2212.   #ifdef sun
  2213.     {
  2214.       symbol *dynamic_symbol;
  2215. ***************
  2216. *** 5658,5664 ****
  2217.   
  2218.     return k;
  2219.   }
  2220.   /* Get the symbol table entry for the global symbol named KEY.
  2221.      Create one if there is none.  */
  2222.   
  2223. --- 6272,6278 ----
  2224.   
  2225.     return k;
  2226.   }
  2227.   /* Get the symbol table entry for the global symbol named KEY.
  2228.      Create one if there is none.  */
  2229.   
  2230. ***************
  2231. *** 5725,5731 ****
  2232.   
  2233.     return 0;
  2234.   }
  2235.   /* Report a usage error.
  2236.      Like fatal except prints a usage summary.  */
  2237.   
  2238. --- 6339,6345 ----
  2239.   
  2240.     return 0;
  2241.   }
  2242.   /* Report a usage error.
  2243.      Like fatal except prints a usage summary.  */
  2244.   
  2245. ***************
  2246. *** 5739,5750 ****
  2247. --- 6353,6374 ----
  2248.         fprintf (stderr, string, arg);
  2249.         fprintf (stderr, "\n");
  2250.       }
  2251. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2252. +   fprintf (stderr, "\
  2253. + Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
  2254. +        [-nostdlib] [-o file] [-r] [-s] [-t] [-u symbol] [-x] [-y symbol]\n\
  2255. +        [-z] [-A file] [-Bstatic] [-D size] [-L libdir] [-M] [-N]\n\
  2256. +        [-S] [-T[{text,data}] addr] [-V prefix] [-X] \n\
  2257. +        [{-a,-amiga-debug-hunk}] [{-f,-flavor} flavor] [file...]\n",
  2258. +        progname);
  2259. + #else
  2260.     fprintf (stderr, "\
  2261.   Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
  2262.          [-nostdlib] [-o file] [-r] [-s] [-t] [-u symbol] [-x] [-y symbol]\n\
  2263.          [-z] [-A file] [-Bstatic] [-D size] [-L libdir] [-M] [-N]\n\
  2264.          [-S] [-T[{text,data}] addr] [-V prefix] [-X] [file...]\n",
  2265.          progname);
  2266. + #endif
  2267.     exit (1);
  2268.   }
  2269.   
  2270. ***************
  2271. *** 5765,5776 ****
  2272.      followed by the filename of ENTRY.  */
  2273.   
  2274.   void
  2275. ! fatal_with_file (string, entry)
  2276.        char *string;
  2277.        struct file_entry *entry;
  2278.   {
  2279.     fprintf (stderr, "%s: ", progname);
  2280. !   fprintf (stderr, string);
  2281.     print_file_name (entry, stderr);
  2282.     fprintf (stderr, "\n");
  2283.     exit (1);
  2284. --- 6389,6400 ----
  2285.      followed by the filename of ENTRY.  */
  2286.   
  2287.   void
  2288. ! fatal_with_file (string, entry, arg)
  2289.        char *string;
  2290.        struct file_entry *entry;
  2291.   {
  2292.     fprintf (stderr, "%s: ", progname);
  2293. !   fprintf (stderr, string, arg);
  2294.     print_file_name (entry, stderr);
  2295.     fprintf (stderr, "\n");
  2296.     exit (1);
  2297. ***************
  2298. *** 5784,5794 ****
  2299.        char *name;
  2300.   {
  2301.     extern int errno, sys_nerr;
  2302. -   extern char *sys_errlist[];
  2303.     char *s;
  2304.   
  2305.     if (errno < sys_nerr)
  2306. !     s = concat ("", sys_errlist[errno], " for %s");
  2307.     else
  2308.       s = "cannot open %s";
  2309.     fatal (s, name);
  2310. --- 6408,6417 ----
  2311.        char *name;
  2312.   {
  2313.     extern int errno, sys_nerr;
  2314.     char *s;
  2315.   
  2316.     if (errno < sys_nerr)
  2317. !     s = concat ("", strerror (errno), " for %s");
  2318.     else
  2319.       s = "cannot open %s";
  2320.     fatal (s, name);
  2321. ***************
  2322. *** 5802,5812 ****
  2323.        struct file_entry *entry;
  2324.   {
  2325.     extern int errno, sys_nerr;
  2326. -   extern char *sys_errlist[];
  2327.     char *s;
  2328.   
  2329.     if (errno < sys_nerr)
  2330. !     s = concat ("", sys_errlist[errno], " for ");
  2331.     else
  2332.       s = "cannot open ";
  2333.     fatal_with_file (s, entry);
  2334. --- 6425,6434 ----
  2335.        struct file_entry *entry;
  2336.   {
  2337.     extern int errno, sys_nerr;
  2338.     char *s;
  2339.   
  2340.     if (errno < sys_nerr)
  2341. !     s = concat ("", strerror (errno), " for ");
  2342.     else
  2343.       s = "cannot open ";
  2344.     fatal_with_file (s, entry);
  2345. ***************
  2346. *** 5824,5840 ****
  2347.     fprintf (stderr, "\n");
  2348.   }
  2349.   
  2350.   /* Output COUNT*ELTSIZE bytes of data at BUF
  2351.      to the descriptor DESC.  */
  2352.   
  2353.   void
  2354. ! mywrite (buf, count, eltsize, desc)
  2355.        char *buf;
  2356.        int count;
  2357.        int eltsize;
  2358. !      int desc;
  2359.   {
  2360.     register int val;
  2361.     register int bytes = count * eltsize;
  2362.   
  2363. --- 6446,6463 ----
  2364.     fprintf (stderr, "\n");
  2365.   }
  2366.   
  2367.   /* Output COUNT*ELTSIZE bytes of data at BUF
  2368.      to the descriptor DESC.  */
  2369.   
  2370.   void
  2371. ! mywrite (buf, count, eltsize, stream)
  2372.        char *buf;
  2373.        int count;
  2374.        int eltsize;
  2375. !      FILE *stream;
  2376.   {
  2377. + #if 0
  2378.     register int val;
  2379.     register int bytes = count * eltsize;
  2380.   
  2381. ***************
  2382. *** 5846,5860 ****
  2383.         buf += val;
  2384.         bytes -= val;
  2385.       }
  2386.   }
  2387.   
  2388. ! /* Output PADDING zero-bytes to descriptor OUTDESC.
  2389.      PADDING may be negative; in that case, do nothing.  */
  2390.   
  2391.   void
  2392. ! padfile (padding, outdesc)
  2393.        int padding;
  2394. !      int outdesc;
  2395.   {
  2396.     register char *buf;
  2397.     if (padding <= 0)
  2398. --- 6469,6486 ----
  2399.         buf += val;
  2400.         bytes -= val;
  2401.       }
  2402. + #else
  2403. +   fwrite (buf, eltsize, count, stream);
  2404. + #endif
  2405.   }
  2406.   
  2407. ! /* Output PADDING zero-bytes to descriptor OUTSTREAM.
  2408.      PADDING may be negative; in that case, do nothing.  */
  2409.   
  2410.   void
  2411. ! padfile (padding, outstream)
  2412.        int padding;
  2413. !      FILE *outstream;
  2414.   {
  2415.     register char *buf;
  2416.     if (padding <= 0)
  2417. ***************
  2418. *** 5862,5868 ****
  2419.   
  2420.     buf = (char *) alloca (padding);
  2421.     bzero (buf, padding);
  2422. !   mywrite (buf, padding, 1, outdesc);
  2423.   }
  2424.   
  2425.   /* Return a newly-allocated string
  2426. --- 6488,6494 ----
  2427.   
  2428.     buf = (char *) alloca (padding);
  2429.     bzero (buf, padding);
  2430. !   mywrite (buf, padding, 1, outstream);
  2431.   }
  2432.   
  2433.   /* Return a newly-allocated string
  2434. ***************
  2435. *** 5903,5910 ****
  2436.   xmalloc (size)
  2437.        int size;
  2438.   {
  2439.     register char *result = malloc (size);
  2440. !   if (!result)
  2441.       fatal ("virtual memory exhausted", 0);
  2442.     return result;
  2443.   }
  2444. --- 6529,6537 ----
  2445.   xmalloc (size)
  2446.        int size;
  2447.   {
  2448. +   extern char *malloc();
  2449.     register char *result = malloc (size);
  2450. !   if (!result && size)
  2451.       fatal ("virtual memory exhausted", 0);
  2452.     return result;
  2453.   }
  2454. ***************
  2455. *** 5916,5927 ****
  2456.        char *ptr;
  2457.        int size;
  2458.   {
  2459. !   register char *result = realloc (ptr, size);
  2460.     if (!result)
  2461.       fatal ("virtual memory exhausted", 0);
  2462.     return result;
  2463.   }
  2464.   #ifdef USG
  2465.   
  2466.   void
  2467. --- 6543,6555 ----
  2468.        char *ptr;
  2469.        int size;
  2470.   {
  2471. !   extern char *malloc(), *realloc();
  2472. !   register char *result = ptr ? realloc (ptr, size) : malloc (size);
  2473.     if (!result)
  2474.       fatal ("virtual memory exhausted", 0);
  2475.     return result;
  2476.   }
  2477.   #ifdef USG
  2478.   
  2479.   void
  2480. ***************
  2481. *** 5952,5954 ****
  2482. --- 6580,7214 ----
  2483.     return 8192;
  2484.   }
  2485.   #endif
  2486. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2487. + /* the whole rest of the file is used for managment of hunks and subhunks.. */
  2488. + /* this is the amiga-equivalent of struct exec */
  2489. + struct simple_hunk_header {
  2490. +   long    id,    /* this will be 0x3f3 */
  2491. +     zero,
  2492. +     table_size,
  2493. +     first_hunk,
  2494. +     last_hunk,
  2495. +     sizes[4];   /* there can be at most a code,data,bss & debug hunk */
  2496. + };
  2497. + /* this writes out a hunk header, depending on the information collected
  2498. +  * so far, it will only create hunks, that really exist, so if your data-
  2499. +  * size is zero, you won't get a data-hunk at all. */
  2500. + void
  2501. + write_hunk_header(outfd)
  2502. +     int outfd;
  2503. + {
  2504. +   struct simple_hunk_header sh;
  2505. +   int this_hunk, header_size;
  2506. +   sh.id = 0x3f3;    /* HUNK_HEADER */
  2507. +   sh.zero = 0;
  2508. +   sh.table_size = current_hunk;
  2509. +   sh.first_hunk = 0;
  2510. +   sh.last_hunk  = current_hunk - 1;
  2511. +   this_hunk = 0;
  2512. +   if (number_of_code_hunk != -1)
  2513. +      sh.sizes[this_hunk++] = LONGSIZE(text_size);
  2514. +   if (number_of_data_hunk != -1)
  2515. +      sh.sizes[this_hunk++] = databss_together 
  2516. +                  ? LONGSIZE(data_size + bss_size) : LONGSIZE(data_size);
  2517. +   if (!databss_together && number_of_bss_hunk  != -1)
  2518. +      sh.sizes[this_hunk++] = LONGSIZE(bss_size);
  2519. +   if (number_of_debug_hunk != -1)
  2520. +      sh.sizes[this_hunk++] = 0;  /* to be filled in later */
  2521. +   header_size = sizeof(sh) - (4-this_hunk)*sizeof(long);
  2522. +   mywrite(&sh, 1, header_size, outfd);
  2523. + }
  2524. + /* if we really write out a debug hunk, this fills in the remaining
  2525. +  * spots, that are known only at the end of load-file output */
  2526. + void
  2527. + conditionally_rewrite_headers ()
  2528. + {
  2529. +   long size_of_debug_hunk,
  2530. +        end_hunk = 0x3f2,
  2531. +        eof;
  2532. +   /* if we don't want a debug hunk, just return */
  2533. +   if (number_of_debug_hunk == -1)  return;
  2534. +   /* while we're at it, since we started the debug-hunk, lets finish it
  2535. +    * now. */
  2536. +   fseek (outstream, 0L, 2);
  2537. +   eof = ftell (outstream);
  2538. +   dh.strs = eof - offset_of_debug_hunk - sizeof(dh) - dh.syms;
  2539. +   /* just to be sure, we HAVE to pad to a long-boundery */
  2540. +   if (eof & 3)
  2541. +     {
  2542. +       long zero = 0;
  2543. +       mywrite(&zero, 4 - (eof & 3), 1, outstream);
  2544. +       eof = (eof + 3) & ~3;
  2545. +     }
  2546. +   mywrite(&end_hunk, sizeof(long), 1, outstream);
  2547. +   /* ok, so calculate the size of the debug hunk. This is the 
  2548. +    * size of the debug_header plus the symbol and string tables,
  2549. +    * but it doesn't include the 2 longs, that identify the hunk and
  2550. +    * its length, whence the "- 2*sizeof(long)" */
  2551. +   size_of_debug_hunk = eof - offset_of_debug_hunk - 2*sizeof(long);
  2552. +   /* we actually need the size in longs.. */
  2553. +   size_of_debug_hunk = LONGSIZE(size_of_debug_hunk);
  2554. +   /* now first patch the debug-hunk itself, afterwards the load-file header */
  2555. +   fseek (outstream, offset_of_debug_hunk, 0);
  2556. +   dh.len = size_of_debug_hunk;
  2557. +   mywrite(&dh, sizeof dh, 1, outstream);
  2558. +   /* now the main header, this involves calculating, at which offset we
  2559. +    * find the index for the debug hunk */   
  2560. +   fseek (outstream, (5 + number_of_debug_hunk)*sizeof(long), 0);
  2561. +   mywrite(&size_of_debug_hunk, sizeof(long), 1, outstream);
  2562. +   fseek (outstream, 0L, 2);
  2563. +   /* that's it! */
  2564. + }
  2565. + /* this is the only information that we can store in a regular amiga
  2566. +  * symbol, just its value, nothing further, that's why I added the 
  2567. +  * debug-hunk-feature */
  2568. + typedef struct {
  2569. +   char *sym_name;
  2570. +   long  sym_offset;
  2571. + } simple_symbol;
  2572. + /* we'll only define symbols after at most 3 hunks, ie. the code, data
  2573. +  * and bss hunk, but not after the debug hunk, whence the index 3 */
  2574. + simple_symbol *hunk_sym_tab[3];
  2575. + int hunk_sym_tab_size[3], hunk_sym_tab_index[3];
  2576. + void
  2577. + init_symbol_hunks()
  2578. + {
  2579. +   int i;
  2580. +   if (trace_files) fprintf(stderr, "init_symbol_hunks()\n");
  2581. +   for (i = 0; i < 3; i++)
  2582. +     {
  2583. +        hunk_sym_tab[i] = 
  2584. +          (simple_symbol *) xmalloc((hunk_sym_tab_size[i] = 10) * 
  2585. +        sizeof(simple_symbol));
  2586. +        hunk_sym_tab_index[i] = 0;
  2587. +     }
  2588. + }
  2589. + /* this should go into libc, well, it wasn't there, so... */
  2590. + char *
  2591. + strsave(str)
  2592. +     char *str;
  2593. + {
  2594. +   char *cp;
  2595. +   int len = strlen(str);
  2596. +   if (len)
  2597. +     {
  2598. +       cp = xmalloc(len+1);
  2599. +       strcpy(cp, str);
  2600. +     }
  2601. +   else
  2602. +     cp = NULL;
  2603. +   return cp;
  2604. + }
  2605. + void
  2606. + add_to_symbol_hunk(hunk_num, name, offset)
  2607. +     int hunk_num;
  2608. +     char *name;
  2609. +     long offset;
  2610. + {
  2611. +    if (hunk_num == -1) return;
  2612. +    if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
  2613. +    /* no checks for duplicate symbols. Since it is legitimate to have
  2614. +     * symbols with the same name, we can't strip them.. just make 
  2615. +     * sure not to call this function multiple times with the same
  2616. +     * symbol, since it won't be detected, and you'll get several
  2617. +     * labels for the same offset...
  2618. +     */
  2619. +     
  2620. +    if (trace_files) fprintf(stderr, "add_to_symbol_hunk(%d, %s, %d)\n",
  2621. +                 hunk_num, name, offset);
  2622. +    hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]].sym_offset = offset;
  2623. +    hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]++].sym_name = 
  2624. +      strsave(name);
  2625. +    if (hunk_sym_tab_index[hunk_num] == hunk_sym_tab_size[hunk_num])
  2626. +     hunk_sym_tab[hunk_num] = (simple_symbol *)
  2627. +       xrealloc(hunk_sym_tab[hunk_num],
  2628. +             (hunk_sym_tab_size[hunk_num] <<= 1) * 
  2629. +               sizeof(simple_symbol));
  2630. + }
  2631. + int
  2632. + compare_simple_symbols(l1, l2)
  2633. +     simple_symbol *l1, *l2;
  2634. + {
  2635. +   return l1->sym_offset - l2->sym_offset;
  2636. + }
  2637. + /* this writes the symbol subhunk #hunk_num, you call this just after
  2638. +  * you created your {code,data,bss}-hunk */
  2639. + void
  2640. + write_symbol_hunk(hunk_num)
  2641. +     int hunk_num;
  2642. + {
  2643. +   int i, j;
  2644. +   simple_symbol *tab;
  2645. +   long size, index;
  2646. +   if (hunk_num == -1) return;
  2647. +   if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
  2648. +   
  2649. +   tab   = hunk_sym_tab[hunk_num];
  2650. +   size  = hunk_sym_tab_size[hunk_num];
  2651. +   index = hunk_sym_tab_index[hunk_num];
  2652. +    
  2653. +   /* kind of abused as general debug-flag:-) */
  2654. +   if (trace_files) fprintf(stderr, 
  2655. +                 "wsh: hnum=%d,size=%d,index=%d\n",
  2656. +                hunk_num,size,index);
  2657. +    
  2658. +   if (index > 0)
  2659. +     {
  2660. +       qsort(tab, index, sizeof(simple_symbol), compare_simple_symbols);
  2661. +       j = 0x3f0; /* HUNK_SYMBOL */
  2662. +       mywrite(&j, 1, sizeof(long), outstream);
  2663. +    
  2664. +       for (i = 0; i < index; i++)
  2665. +         {
  2666. +        register simple_symbol *ss = tab+i;
  2667. +        int len = strlen (ss->sym_name);
  2668. +        j = LONGSIZE (len);
  2669. +        mywrite(&j, 1, sizeof(long), outstream);
  2670. +        mywrite(ss->sym_name, 1, len, outstream);
  2671. +        if (len < 4*j)
  2672. +          padfile (4*j - len, outstream);
  2673. +        mywrite(&(ss->sym_offset), 1, sizeof(long), outstream);
  2674. +     }
  2675. +       j = 0;
  2676. +       mywrite(&j, 1, sizeof(long), outstream);
  2677. +     }
  2678. + }
  2679. + /* now follow the quite similar routines for dealing with
  2680. +  * reloc-subhunks, the difference to the symbol-subhunks is, that reloc
  2681. +  * subhunks can be output only after the {code,data}-Hunks, AND there
  2682. +  * can be more than one after each of them */
  2683. + long *hunk_rel_tab[3], hunk_rel_tab_size[3], hunk_rel_tab_index[3];
  2684. + void
  2685. + init_reloc_hunk()
  2686. + {
  2687. +   int i;
  2688. +   if (trace_files) fprintf(stderr, "init_reloc_hunk()\n");
  2689. +   for (i = 0; i < 3; i++)
  2690. +     {
  2691. +        hunk_rel_tab[i] = 
  2692. +          (long *) xmalloc((hunk_rel_tab_size[i] = 10) * sizeof(long));
  2693. +        hunk_rel_tab_index[i] = 0;
  2694. +     }
  2695. + }
  2696. + void
  2697. + add_to_reloc_hunk(hunk_num, offset)
  2698. +     int hunk_num;
  2699. +     long offset;
  2700. + {
  2701. +    /* no checks for duplicate symbols, they will show up when we sort
  2702. +     * the table, and we will strip them off before writing out the table */
  2703. +    if (trace_files) fprintf(stderr, "add_to_reloc_hunk(%d, %d)\n", hunk_num, offset);
  2704. +    hunk_rel_tab[hunk_num][hunk_rel_tab_index[hunk_num]++] = offset;
  2705. +    if (hunk_rel_tab_index[hunk_num] == hunk_rel_tab_size[hunk_num])
  2706. +     hunk_rel_tab[hunk_num] = (long *)
  2707. +       xrealloc(hunk_rel_tab[hunk_num],
  2708. +                    (hunk_rel_tab_size[hunk_num] <<= 1) * sizeof(long));
  2709. + }
  2710. + int
  2711. + compare_longs(l1, l2)
  2712. +     long *l1, *l2;
  2713. + {
  2714. +   return *l1 - *l2;
  2715. + }
  2716. + int
  2717. + compare_strings (s1p, s2p)
  2718. +     char **s1p;
  2719. +     char **s2p;
  2720. + {
  2721. +   return (strcmp (*s1p, *s2p));
  2722. + }
  2723. + void
  2724. + write_reloc_hunk()
  2725. + {
  2726. +    int i, j;
  2727. +    long *tab, size, index;
  2728. +    /* only write a hunk-header & -end, if we really output some relocs */
  2729. +    int did_start_hunk = 0;
  2730. +    for (i = 0; i < 3; i++)
  2731. +      {
  2732. +     tab   = hunk_rel_tab[i];
  2733. +     size  = hunk_rel_tab_size[i];
  2734. +     index = hunk_rel_tab_index[i];
  2735. +     /* kind of abused as general debug-flag:-) */
  2736. +         if (trace_files) fprintf(stderr, 
  2737. +                  "wrh: i=%d,size=%d,index=%d\n",
  2738. +                  i,size,index);
  2739. +         if (index > 0)
  2740. +       {
  2741. +         qsort(tab, index, sizeof(long), compare_longs);
  2742. +         /* kick out duplicate symbols.. I don't know, what
  2743. +          * the loader would do, if it had to relocate the same
  2744. +          * address twice.. BTW: can this happen or can't it???? */
  2745. +         for (j = 0; j < index-1; )
  2746. +           {
  2747. +         if (tab[j] == tab[j+1])
  2748. +           bcopy(tab+j+1, tab+j, ((index--)-j-1)*sizeof(long));
  2749. +         else
  2750. +           j++;
  2751. +           }
  2752. +         if (!did_start_hunk++)
  2753. +           {
  2754. +         j = 0x3ec; /* HUNK_RELOC32 */
  2755. +         mywrite(&j, 1, sizeof(long), outstream);
  2756. +           }
  2757. +         mywrite(&index, 1, sizeof(long), outstream);
  2758. +         mywrite(&i, 1, sizeof(long), outstream);
  2759. +         mywrite(tab, 1, index*sizeof(long), outstream);
  2760. +         hunk_rel_tab_index[i] = index;
  2761. +       }
  2762. +      }
  2763. +    if (did_start_hunk)
  2764. +      {
  2765. +     j = 0;
  2766. +        mywrite(&j, 1, sizeof(long), outstream);
  2767. +      }
  2768. + }
  2769. + void
  2770. + write_datadata_relocs ()
  2771. + {
  2772. +   int numdd, i, prev;
  2773. +   prev = ftell (outstream);
  2774. +   fseek (outstream, datadata_relocs_offset, L_SET);
  2775. +   
  2776. +   numdd = hunk_rel_tab_index[number_of_data_hunk];
  2777. +   if (numdd > numdatadata_relocs)
  2778. +     fatal ("found more data-data relocs than estimated!\n", 0);
  2779. +   
  2780. +   mywrite (&numdd, 1, sizeof (long), outstream);
  2781. +   if (numdd)
  2782. +     mywrite (hunk_rel_tab[number_of_data_hunk], numdd, sizeof (long), outstream);
  2783. +   fseek (outstream, prev, L_SET);
  2784. + }
  2785. + /* create the bss hunk if needed */
  2786. + void
  2787. + write_bss()
  2788. + {
  2789. +   long bss_hunk[2];
  2790. +   if (!databss_together && bss_size)
  2791. +    {
  2792. +      bss_hunk[0] = 0x3eb;
  2793. +      bss_hunk[1] = LONGSIZE(bss_size);
  2794. +      mywrite(bss_hunk, 1, sizeof bss_hunk, outstream);
  2795. +      write_symbol_hunk(number_of_bss_hunk);
  2796. +      bss_hunk[0] = 0x3f2; /* HUNK_END */
  2797. +      mywrite(bss_hunk, 1, sizeof(long), outstream);
  2798. +    }
  2799. + }
  2800. + /* this scans one object file for its symbols, and deposits them in 
  2801. +  * the symbol-hunk tables for later output */
  2802. + void
  2803. + look_for_file_syms (entry)
  2804. +      struct file_entry *entry;
  2805. + {
  2806. +   register struct nlist *p = entry->symbols;
  2807. +   register struct nlist *end = p + entry->syms_size / sizeof (struct nlist);
  2808. + #if 0
  2809. +   /* don't do this, it only confuses most amiga disassemblers.. */
  2810. +   /* Generate a local symbol for the start of this file's text.  */
  2811. +   if (discard_locals != DISCARD_ALL)
  2812. +     add_to_symbol_hunk(number_of_code_hunk, entry->local_sym_name, 
  2813. +        entry->text_start_address);
  2814. + #endif
  2815. +   /* Read the file's string table.  */
  2816. +   entry->strings = (char *) alloca (entry->strs_size);
  2817. +   read_entry_strings (file_open (entry), entry);
  2818. +   for (; p < end; p++)
  2819. +     {
  2820. +       register unsigned char type = p->n_type;
  2821. +       register int write = 0;
  2822. +       int this_hunk;
  2823. +       char *cp;
  2824. +       /* WRITE gets 1 for a non-global symbol that should be written.  */
  2825. +       if (SET_ELEMENT_P (type))    /* This occurs even if global.  These */
  2826. +                 /* types of symbols are never written */
  2827. +                 /* globally, though they are stored */
  2828. +                 /* globally.  */
  2829. +         write = output_style == OUTPUT_RELOCATABLE;
  2830. +       else if (!(type & (N_STAB | N_EXT)))
  2831. +           /* ordinary local symbol */
  2832. +       write = ((discard_locals != DISCARD_ALL)
  2833. +            && !(discard_locals == DISCARD_L &&
  2834. +                (p->n_un.n_strx + entry->strings)[0] == LPREFIX)
  2835. +            && type != N_WARNING);
  2836. +       else if (!(type & N_EXT))
  2837. +     /* debugger symbol */
  2838. +         write = (strip_symbols == STRIP_NONE);
  2839. +       /* skip STAB symbols if present */
  2840. +       write = write && !(type & N_STAB);
  2841. +       /* those weird types are NOT output in the normal symbols:-)) */
  2842. +       write = write && (type != N_ABS && type != (N_ABS|N_EXT));
  2843. +       /* don't know where those symbols come from, they're well suited to
  2844. +        * crash enforcer, and they're not `real' symbols anyway.. */
  2845. +       if (p->n_un.n_strx > entry->strs_size) continue;
  2846. +       /* symbols that end with a dot are only useful for gdb, 
  2847. +        * not for a normal amiga debugger (currently gcc_compiled. and
  2848. +        * gcc_compiled2.) so skip them in this section */
  2849. +       /* check to see, whether this string ends with a dot */
  2850. +       if (write && p->n_un.n_strx)
  2851. +         {
  2852. +           cp = rindex (p->n_un.n_strx + entry->strings, '.');
  2853. +       write = write && !(cp && !cp[1]);
  2854. +       
  2855. + #if 0
  2856. +       printf ("%s >%s<\n", write ? "adding" : "skipping", p->n_un.n_strx + entry->strings);
  2857. + #endif
  2858. +     }
  2859. +       if (write)
  2860. +     {
  2861. +       if (p->n_un.n_strx)
  2862. +         {
  2863. +           switch (type & ~N_EXT)
  2864. +             {
  2865. +           case N_TEXT:
  2866. +             this_hunk = number_of_code_hunk;
  2867. +             break;
  2868. +           case N_SETV:
  2869. +           case N_DATA:
  2870. +             this_hunk = number_of_data_hunk;
  2871. +             break;
  2872. +           case N_UNDF:
  2873. +           case N_BSS:
  2874. +             this_hunk = number_of_bss_hunk;
  2875. +             break;
  2876. +           default:
  2877. +             error ("unknown type %d while trying to build lsymhunk", type);
  2878. +             goto skip1;
  2879. +             }
  2880. +           add_to_symbol_hunk(this_hunk, p->n_un.n_strx + entry->strings,
  2881. +                  p->n_value);
  2882. + skip1:    ;
  2883. +             }
  2884. +     }
  2885. +     }
  2886. + }
  2887. + /* scan all input files for symbols and store them in the symbolhunk tables */
  2888. + void
  2889. + look_for_symbols()
  2890. + {
  2891. +   int this_hunk;
  2892. +   int i;
  2893. +   symbol *sp;
  2894. +   if (strip_symbols == STRIP_ALL)
  2895. +     return;
  2896. +   /* Write the local symbols defined by the various files.  */
  2897. +   each_file (look_for_file_syms, 0);
  2898. +   file_close ();
  2899. +   /* Scan the symbol hash table, bucket by bucket.  */
  2900. +   for (i = 0; i < TABSIZE; i++)
  2901. +     for (sp = symtab[i]; sp; sp = sp->link)
  2902. +       {
  2903. +     struct nlist nl;
  2904. +     /* Compute a `struct nlist' for the symbol.  */
  2905. +     nl.n_value = 0;
  2906. +     if (sp->defined || sp->referenced)
  2907. +       {
  2908. +         /* common condition needs to be before undefined condition */
  2909. +         /* because unallocated commons are set undefined in */
  2910. +         /* digest_symbols */
  2911. +         if (sp->defined > 1) /* defined with known type */
  2912. +           {
  2913. +         /* If the target of an indirect symbol has been
  2914. +            defined and we are outputting an executable,
  2915. +            resolve the indirection; it's no longer needed */
  2916. +         if (output_style != OUTPUT_RELOCATABLE
  2917. +             && ((sp->defined & ~N_EXT) == N_INDR)
  2918. +             && (((symbol *) sp->value)->defined > 1))
  2919. +           {
  2920. +             symbol *newsp = (symbol *) sp->value;
  2921. +             nl.n_type = newsp->defined;
  2922. +             nl.n_value = newsp->value;
  2923. +           }
  2924. +         else
  2925. +           {
  2926. +             nl.n_type = sp->defined;
  2927. +             if (sp->defined != (N_INDR | N_EXT))
  2928. +               nl.n_value = sp->value;
  2929. +             else
  2930. +               nl.n_value = 0;
  2931. +           }
  2932. +           }
  2933. +         else if (sp->max_common_size) /* defined as common but not allocated. */
  2934. +           {
  2935. +         /* happens only with -r and not -d */
  2936. +         /* write out a common definition */
  2937. +         nl.n_type = N_UNDF | N_EXT;
  2938. +         nl.n_value = sp->max_common_size;
  2939. +           }
  2940. +         else if (!sp->defined)          /* undefined -- legit only if -r */
  2941. +           {
  2942. +         nl.n_type = N_UNDF | N_EXT;
  2943. +         nl.n_value = 0;
  2944. +           }
  2945. +         else
  2946. +           fatal ("internal error: %s defined in mysterious way", sp->name);
  2947. +         switch (nl.n_type & ~N_EXT)
  2948. +           {
  2949. +         case N_TEXT:
  2950. +           this_hunk = number_of_code_hunk;
  2951. +           break;
  2952. +         case N_SETV:
  2953. +         case N_DATA:
  2954. +           this_hunk = number_of_data_hunk;
  2955. +           break;
  2956. +         case N_UNDF:
  2957. +         case N_BSS:
  2958. +           this_hunk = number_of_bss_hunk;
  2959. +           break;
  2960. +         case N_ABS:
  2961. +           break;
  2962. +         default:
  2963. +           error ("unknown type %d while trying to build symhunk", nl.n_type);
  2964. +           goto skip2;
  2965. +           }
  2966. +         /* sigh, there is no equivalent in the symbol section of a load
  2967. +          * file on the amiga, have to forget about those symbols */
  2968. +         if ((nl.n_type & ~N_EXT) == N_ABS)
  2969. +           continue;
  2970. +         add_to_symbol_hunk(this_hunk, sp->name, nl.n_value);
  2971. + skip2:    ;
  2972. +       }
  2973. +       }
  2974. + }
  2975. + void
  2976. + relocate_set_vectors (vectors, num_entries)
  2977. +     unsigned long *vectors;
  2978. +     int num_entries;
  2979. + {
  2980. +   unsigned long i;
  2981. +   unsigned long offset = set_sect_start;
  2982. +   int hunk_num;
  2983. +   while (num_entries-- > 0)
  2984. +     {
  2985. +       /* the number of entries for this symbol */
  2986. +       i = *vectors++; offset += 4;
  2987. +       while (num_entries --, i--)
  2988. +     {
  2989. +       hunk_num = number_of_code_hunk;
  2990. +       if (*vectors >= text_size)
  2991. +         {
  2992. +           if (*vectors >= text_size + data_size)
  2993. +               {
  2994. +           hunk_num = number_of_bss_hunk;
  2995. +           if (databss_together)
  2996. +             *vectors -= text_size;
  2997. +           else
  2998. +             *vectors -= text_size + data_size;
  2999. +         }
  3000. +           else
  3001. +         {
  3002. +           hunk_num = number_of_data_hunk;
  3003. +           *vectors -= text_size;
  3004. +         }
  3005. +         }
  3006. +       add_to_reloc_hunk (hunk_num, offset);
  3007. +       ++vectors;
  3008. +       offset += 4;
  3009. +     }
  3010. +       /* check.. HAS to be zero */
  3011. +       if (*vectors)
  3012. +     fatal ("set-vector corrupt, num_entries = %d", num_entries);
  3013. +       vectors++; offset += 4; --num_entries;
  3014. +     }
  3015. + }
  3016. + #endif
  3017. diff -rc --new-file binutils-1.8.x-fsf/objdump.c binutils-1.8.x-amiga/objdump.c
  3018. *** binutils-1.8.x-fsf/objdump.c    Sat Dec 30 00:16:07 1989
  3019. --- binutils-1.8.x-amiga/objdump.c    Wed Sep 22 12:45:33 1993
  3020. ***************
  3021. *** 24,31 ****
  3022.   #include <stdio.h>
  3023.   #include "getopt.h"
  3024.   
  3025.   #ifndef COFF_ENCAPSULATE
  3026. ! #include <a.out.h>
  3027.   /* Tell a.out.gnu.h not to try to redefine some things.  */
  3028.   #define __STRUCT_EXEC_OVERRIDE__
  3029.   #define N_NLIST_DECLARED
  3030. --- 24,35 ----
  3031.   #include <stdio.h>
  3032.   #include "getopt.h"
  3033.   
  3034. + #ifdef MCH_AMIGA
  3035. + #define getpagesize() 256
  3036. + #endif
  3037.   #ifndef COFF_ENCAPSULATE
  3038. ! #include <sun/a.out.h>
  3039.   /* Tell a.out.gnu.h not to try to redefine some things.  */
  3040.   #define __STRUCT_EXEC_OVERRIDE__
  3041.   #define N_NLIST_DECLARED
  3042. diff -rc --new-file binutils-1.8.x-fsf/ranlib.c binutils-1.8.x-amiga/ranlib.c
  3043. *** binutils-1.8.x-fsf/ranlib.c    Thu Mar  1 00:18:42 1990
  3044. --- binutils-1.8.x-amiga/ranlib.c    Sat Feb  5 12:31:20 1994
  3045. ***************
  3046. *** 54,60 ****
  3047.      as the location of the GNU AR program.  */
  3048.   
  3049.   char *prog = AR_PROG;
  3050. ! char *prog_pref = "/usr/local/gnubin/ar";
  3051.   
  3052.   int
  3053.   main (argc, argv)
  3054. --- 54,60 ----
  3055.      as the location of the GNU AR program.  */
  3056.   
  3057.   char *prog = AR_PROG;
  3058. ! char *prog_pref = "/gnu/bin/ar";
  3059.   
  3060.   int
  3061.   main (argc, argv)
  3062. diff -rc --new-file binutils-1.8.x-fsf/strip.c binutils-1.8.x-amiga/strip.c
  3063. *** binutils-1.8.x-fsf/strip.c    Mon Jun 11 21:40:01 1990
  3064. --- binutils-1.8.x-amiga/strip.c    Wed Sep 22 12:45:43 1993
  3065. ***************
  3066. *** 71,77 ****
  3067.   
  3068.   /* If BSD, we can use `ftruncate'.  */
  3069.   
  3070. ! #ifndef USG
  3071.   #define HAVE_FTRUNCATE
  3072.   #endif
  3073.   
  3074. --- 71,77 ----
  3075.   
  3076.   /* If BSD, we can use `ftruncate'.  */
  3077.   
  3078. ! #if !defined(USG) && !defined(MCH_AMIGA)
  3079.   #define HAVE_FTRUNCATE
  3080.   #endif
  3081.   
  3082. ***************
  3083. *** 287,294 ****
  3084. --- 287,296 ----
  3085.       signal (SIGTERM, SIG_DFL);
  3086.   
  3087.     /* Handle any signal that came in while they were deferred.  */
  3088. + #ifndef MCH_AMIGA
  3089.     if (delayed_signal)
  3090.       kill (getpid (), delayed_signal);
  3091. + #endif
  3092.   }
  3093.   
  3094.   /** Convenient functions for operating on one or all files being processed.  */
  3095. ***************
  3096. *** 928,933 ****
  3097. --- 930,936 ----
  3098.   }
  3099.   
  3100.   #ifdef USG
  3101. + #ifndef MCH_AMIGA
  3102.   
  3103.   rename (from, to)
  3104.        char *from, *to;
  3105. ***************
  3106. *** 940,945 ****
  3107. --- 943,949 ----
  3108.       return 0;
  3109.   }
  3110.   
  3111. + #endif
  3112.   #endif
  3113.   
  3114.   usage ()
  3115.