home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / useful / dist / gnu / binutils / binutils-1.8.x.diffs next >
Encoding:
Text File  |  1993-12-01  |  87.4 KB  |  3,351 lines

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