Changeset 1998


Ignore:
Timestamp:
Jun 5, 2005, 6:17:00 PM (20 years ago)
Author:
bird
Message:

Avoid alloc() since we might easily run out of stack for string tables and such like.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/ld/ld.c

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r1997 r1998  
    6363
    6464/* If compiled with GNU C, use the built-in alloca */
    65 #ifdef __GNUC__
    66 # define alloca __builtin_alloca
    67 #else
    68 # include "alloca.h"
    69 #endif
    70 
     65#include "alloca.h"
    7166#include "getopt.h"
    7267
     
    19571952    {
    19581953      read_entry_symbols (desc, entry);
    1959       entry->strings = (char *) alloca (entry->strs_size);
     1954      entry->strings = (char *) malloc (entry->strs_size);
    19601955      read_entry_strings (desc, entry);
    19611956      enter_file_symbols (entry);
    1962       entry->strings = 0;
     1957      free (entry->strings);
     1958      entry->strings = NULL;
    19631959    }
    19641960
     
    25332529{
    25342530  read_entry_symbols (desc, subentry);
    2535   subentry->strings = (char *) alloca (subentry->strs_size);
     2531  subentry->strings = (char *) malloc (subentry->strs_size);
    25362532  read_entry_strings (desc, subentry);
    25372533
     
    25502546        entry->subfiles = subentry;
    25512547      *prev_addr = subentry;
    2552       subentry->strings = 0; /* Since space will dissapear on return */
    2553     }
     2548    }
     2549  free (subentry->strings);
     2550  subentry->strings = NULL;
    25542551}
    25552552
     
    30623059    *end = entry->symbols + entry->syms_size / sizeof (struct nlist);
    30633060
    3064   entry->strings = (char *) alloca (entry->strs_size);
     3061  entry->strings = (char *) malloc (entry->strs_size);
    30653062  read_entry_strings (file_open (entry), entry);
    30663063
     
    30803077               ((symbol *)p->n_un.n_name)->name, p->n_value);
    30813078
    3082   entry->strings = 0;           /* All done with them.  */
     3079  free (entry->strings);
     3080  entry->strings = NULL;                /* All done with them.  */
    30833081}
    30843082
     
    34513449  int number_of_syms = entry->syms_size / sizeof (struct nlist);
    34523450  unsigned char *nlist_bitvector
    3453     = (unsigned char *) alloca ((number_of_syms >> 3) + 1);
     3451    = (unsigned char *) malloc ((number_of_syms >> 3) + 1);
    34543452  struct line_debug_entry *text_scan, *data_scan;
    34553453  int i;
     
    34653463      int desc;
    34663464
    3467       entry->strings = (char *) alloca (entry->strs_size);
     3465      entry->strings = (char *) malloc (entry->strs_size);
    34683466      desc = file_open (entry);
    34693467      read_entry_strings (desc, entry);
     
    35853583  free (text_scan);
    35863584  free (data_scan);
    3587   entry->strings = 0;           /* Since it will dissapear anyway.  */
     3585  free (entry->strings);
     3586  entry->strings = NULL;
     3587  free (nlist_bitvector);
    35883588}
    35893589
     
    41864186  /* Allocate space for the file's text section */
    41874187
    4188   bytes = (char *) alloca (entry->text_size);
     4188  bytes = (char *) malloc (entry->text_size);
    41894189
    41904190  /* Deal with relocation information however is appropriate */
     
    42184218
    42194219  mywrite (bytes, 1, entry->text_size, outdesc);
     4220
     4221  free (bytes);
    42204222}
    42214223
     
    43144316  desc = file_open (entry);
    43154317
    4316   bytes = (char *) alloca (entry->data_size);
     4318  bytes = (char *) malloc (entry->data_size);
    43174319
    43184320  if (entry->datarel) reloc = entry->datarel;
     
    43394341  mywrite (bytes, 1, entry->data_size, outdesc);
    43404342  padfile ((SECTION_ALIGN - entry->data_size) & SECTION_ALIGN_MASK, outdesc);
     4343
     4344  free (bytes);
    43414345}
    43424346
     
    48234827     extra struct for each indirect symbol to hold the extra reference
    48244828     following. */
    4825   struct nlist *buf = (struct nlist *) alloca ((defined_global_sym_count
     4829  struct nlist *buf = (struct nlist *) malloc ((defined_global_sym_count
    48264830                                + undefined_global_sym_count
    48274831                                + global_indirect_count)
     
    48504854     extra space for the references following indirect outputs. */
    48514855
    4852   strtab_vector = (char **) alloca ((num_hash_tab_syms
     4856  strtab_vector = (char **) malloc ((num_hash_tab_syms
    48534857                                     + global_indirect_count) * sizeof (char *));
    4854   strtab_lens = (int *) alloca ((num_hash_tab_syms
     4858  strtab_lens = (int *) malloc ((num_hash_tab_syms
    48554859                                 + global_indirect_count) * sizeof (int));
    48564860  strtab_index = 0;
     
    49644968
    49654969  write_string_table ();
     4970  free (strtab_vector);
     4971  strtab_vector = NULL;
     4972  free (strtab_lens);
     4973  strtab_lens = NULL;
     4974  free (buf);
    49664975}
    49674976
     
    49844993     It has one extra slot for the local symbol we generate here.  */
    49854994  struct nlist *buf
    4986     = (struct nlist *) alloca (entry->syms_size + sizeof (struct nlist));
     4995    = (struct nlist *) malloc (entry->syms_size + sizeof (struct nlist));
    49874996  register struct nlist *bufp = buf;
    49884997
     
    49935002     The elements are filled in by `assign_string_table_index'.  */
    49945003
    4995   strtab_vector = (char **) alloca (max_syms * sizeof (char *));
    4996   strtab_lens = (int *) alloca (max_syms * sizeof (int));
     5004  strtab_vector = (char **) malloc (max_syms * sizeof (char *));
     5005  strtab_lens = (int *) malloc (max_syms * sizeof (int));
    49975006  strtab_index = 0;
    49985007
     
    50335042  /* Read the file's string table.  */
    50345043
    5035   entry->strings = (char *) alloca (entry->strs_size);
     5044  entry->strings = (char *) malloc (entry->strs_size);
    50365045  read_entry_strings (file_open (entry), entry);
    50375046
     
    50865095
    50875096  write_string_table ();
    5088   entry->strings = 0;           /* Since it will dissapear anyway.  */
     5097  free (entry->strings);
     5098  entry->strings = NULL;
     5099  free (strtab_vector);
     5100  strtab_vector = NULL;
     5101  free (strtab_lens);
     5102  strtab_lens = NULL;
     5103  free (buf);
    50895104}
    50905105
Note: See TracChangeset for help on using the changeset viewer.