home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / useful / dist / gnu / binutils / binutils-1.8.x.diffs next >
Encoding:
Text File  |  1993-09-23  |  85.0 KB  |  3,245 lines

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