Changeset 2275 for trunk


Ignore:
Timestamp:
Jul 24, 2005, 11:26:11 AM (20 years ago)
Author:
bird
Message:

Switched back to alloca and adding 23 MB of stack.

Location:
trunk/src/emx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.112 to 1.113
    r2274 r2275  
    1010    - ld:
    1111        o Fixed a case of memory access after free.
     12        o Switched back to alloca and adding 23 MB of stack.
    1213
    13142005-07-21: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/src/ld/ld.c

    • Property cvs2svn:cvs-rev changed from 1.20 to 1.21
    r2274 r2275  
    6363
    6464/* If compiled with GNU C, use the built-in alloca */
     65#ifdef USE_ALLOCA
    6566#include "alloca.h"
     67#define ALLOCA(size)    alloca (size)
     68#define FREEA(ptr)      do { (ptr) = NULL; } while (0)
     69#else
     70#define ALLOCA(size)    malloc (size)
     71#define FREEA(ptr)      do { free(ptr); (ptr) = NULL; } while (0)
     72#endif
    6673#include "getopt.h"
    6774
     
    19531960    {
    19541961      read_entry_symbols (desc, entry);
    1955       entry->strings = (char *) malloc (entry->strs_size);
     1962      entry->strings = (char *) ALLOCA (entry->strs_size);
    19561963      read_entry_strings (desc, entry);
    19571964      enter_file_symbols (entry);
    1958       free (entry->strings);
    1959       entry->strings = NULL;
     1965      FREEA (entry->strings);
    19601966    }
    19611967
     
    21722178    {
    21732179      register char *reftype;
     2180      int free_reftype = 0;
    21742181      switch (realtype & ~N_EXT)
    21752182        {
     
    22172224
    22182225        case N_INDR:
    2219           reftype = (char *) alloca (23 + strlen (((symbol *) nlist_p->n_value)->name));
     2226          reftype = (char *) ALLOCA (23 + strlen (((symbol *) nlist_p->n_value)->name));
    22202227          sprintf (reftype, "defined equivalent to %s",
    22212228                   ((symbol *) nlist_p->n_value)->name);
     2229          free_reftype = 1;
    22222230          break;
    22232231
     
    22482256      fprintf (stderr, ": %3d %s %s\n",
    22492257               nlist_p - entry->symbols, sp->name, reftype);
     2258      if (free_reftype)
     2259        FREEA (reftype);
    22502260    }
    22512261}
     
    25302540{
    25312541  read_entry_symbols (desc, subentry);
    2532   subentry->strings = (char *) malloc (subentry->strs_size);
     2542  subentry->strings = (char *) ALLOCA (subentry->strs_size);
    25332543  read_entry_strings (desc, subentry);
    25342544
    25352545  if (!subfile_wanted_p (subentry))
    25362546    {
    2537       free (subentry->strings);
    2538       subentry->strings = NULL;
     2547      FREEA (subentry->strings);
    25392548      free (subentry->symbols);
    25402549      free (subentry);
     
    25492558        entry->subfiles = subentry;
    25502559      *prev_addr = subentry;
    2551       free (subentry->strings);
    2552       subentry->strings = NULL;
     2560      FREEA (subentry->strings);
    25532561    }
    25542562}
     
    30623070    *end = entry->symbols + entry->syms_size / sizeof (struct nlist);
    30633071
    3064   entry->strings = (char *) malloc (entry->strs_size);
     3072  entry->strings = (char *) ALLOCA (entry->strs_size);
    30653073  read_entry_strings (file_open (entry), entry);
    30663074
     
    30803088               ((symbol *)p->n_un.n_name)->name, p->n_value);
    30813089
    3082   free (entry->strings);
    3083   entry->strings = NULL;                /* All done with them.  */
     3090  FREEA (entry->strings);
    30843091}
    30853092
     
    34523459  int number_of_syms = entry->syms_size / sizeof (struct nlist);
    34533460  unsigned char *nlist_bitvector
    3454     = (unsigned char *) malloc ((number_of_syms >> 3) + 1);
     3461    = (unsigned char *) ALLOCA ((number_of_syms >> 3) + 1);
    34553462  struct line_debug_entry *text_scan, *data_scan;
    34563463  int i;
     
    34663473      int desc;
    34673474
    3468       entry->strings = (char *) malloc (entry->strs_size);
     3475      entry->strings = (char *) ALLOCA (entry->strs_size);
    34693476      desc = file_open (entry);
    34703477      read_entry_strings (desc, entry);
     
    35863593  free (text_scan);
    35873594  free (data_scan);
    3588   free (entry->strings);
    3589   entry->strings = NULL;
    3590   free (nlist_bitvector);
     3595  FREEA (entry->strings);
     3596  FREEA (nlist_bitvector);
    35913597}
    35923598
     
    39753981    {
    39763982      char *nargv[11];
    3977       int i, saved_errno;
    3978 
    3979       i = 0;
     3983      char *freeav[11];
     3984      int i, j, saved_errno;
     3985
     3986      i = j = 0;
    39803987      nargv[i++] = "emxbind";
    39813988      nargv[i++] = "-bq";
     
    39863993      if (def_filename != NULL)
    39873994        {
    3988           nargv[i] = alloca (strlen (def_filename) + 3);
     3995          freeav[j++] = nargv[i] = ALLOCA (strlen (def_filename) + 3);
    39893996          strcpy (nargv[i], "-d");
    39903997          strcat (nargv[i], def_filename);
     
    39954002      if (stack_size != 0)
    39964003        {
    3997           nargv[i] = alloca (20);
     4004          freeav[j++] = nargv[i] = ALLOCA (20);
    39984005          sprintf (nargv[i], "-k0x%x", stack_size);
    39994006          i++;
     
    40034010          if (map_filename == NULL)
    40044011            {
    4005               map_filename = alloca (strlen (output_filename) + 5);
     4012              freeav[j++] = map_filename = ALLOCA (strlen (output_filename) + 5);
    40064013              strcpy (map_filename, exe_filename);
    40074014              _remext (map_filename);
    40084015              strcat (map_filename, ".map");
    40094016            }
    4010           nargv[i] = alloca (strlen (map_filename) + 3);
     4017          freeav[j++] = nargv[i] = ALLOCA (strlen (map_filename) + 3);
    40114018          strcpy (nargv[i], "-m");
    40124019          strcat (nargv[i], map_filename);
     
    40154022      if (res_filename != NULL)
    40164023        {
    4017           nargv[i] = alloca (strlen (res_filename) + 3);
     4024          freeav[j++] = nargv[i] = ALLOCA (strlen (res_filename) + 3);
    40184025          strcpy (nargv[i], "-r");
    40194026          strcat (nargv[i], res_filename);
     
    40544061            perror_name (touch_filename);
    40554062        }
     4063      while (j-- > 0)
     4064        FREEA (freeav[j]);
    40564065    }
    40574066  else if (exe_filename != NULL) /* RSXNT */
    40584067    {
    40594068      char *nargv[10];
     4069      char *freea = NULL;
    40604070      int i, saved_errno;
    40614071
     
    40774087        {
    40784088          nargv[i++] = "-d";
    4079           nargv[i] = alloca (strlen (def_filename) + 3);
     4089          freea = nargv[i] = ALLOCA (strlen (def_filename) + 3);
    40804090          strcpy(nargv[i], def_filename);
    40814091          i++;
     
    40994109          close (i);
    41004110        }
     4111      FREEA (freea);
    41014112    }
    41024113}
     
    41904201  register int desc;
    41914202  register struct relocation_info *reloc;
     4203  int free_reloc = 0;
    41924204
    41934205  if (trace_files)
     
    41984210  /* Allocate space for the file's text section */
    41994211
    4200   bytes = (char *) malloc (entry->text_size);
     4212  bytes = (char *) ALLOCA (entry->text_size);
    42014213
    42024214  /* Deal with relocation information however is appropriate */
     
    42104222  else
    42114223    {
    4212       reloc = (struct relocation_info *) alloca (entry->text_reloc_size);
     4224      free_reloc = 1;
     4225      reloc = (struct relocation_info *) ALLOCA (entry->text_reloc_size);
    42134226      lseek (desc, entry->starting_offset + entry->text_reloc_offset, L_SET);
    42144227      if (entry->text_reloc_size != read (desc, reloc, entry->text_reloc_size))
     
    42314244  mywrite (bytes, 1, entry->text_size, outdesc);
    42324245
    4233   free (bytes);
     4246  FREEA (bytes);
     4247  if (free_reloc)
     4248    FREEA (reloc);
    42344249}
    42354250
     
    43224337  register char *bytes;
    43234338  register int desc;
     4339  int free_reloc = 0;
    43244340
    43254341  if (trace_files)
     
    43284344  desc = file_open (entry);
    43294345
    4330   bytes = (char *) malloc (entry->data_size);
     4346  bytes = (char *) ALLOCA (entry->data_size);
    43314347
    43324348  if (entry->datarel) reloc = entry->datarel;
     
    43384354  else
    43394355    {
    4340       reloc = (struct relocation_info *) alloca (entry->data_reloc_size);
     4356      free_reloc = 1;
     4357      reloc = (struct relocation_info *) ALLOCA (entry->data_reloc_size);
    43414358      lseek (desc, entry->starting_offset + entry->data_reloc_offset, L_SET);
    43424359      if (entry->data_reloc_size != read (desc, reloc, entry->data_reloc_size))
     
    43544371  padfile ((SECTION_ALIGN - entry->data_size) & SECTION_ALIGN_MASK, outdesc);
    43554372
    4356   free (bytes);
     4373  FREEA (bytes);
     4374  if (free_reloc)
     4375    FREEA (reloc);
    43574376}
    43584377
     
    48394858     extra struct for each indirect symbol to hold the extra reference
    48404859     following. */
    4841   struct nlist *buf = (struct nlist *) malloc ((defined_global_sym_count
     4860  struct nlist *buf = (struct nlist *) ALLOCA ((defined_global_sym_count
    48424861                                + undefined_global_sym_count
    48434862                                + global_indirect_count)
     
    48664885     extra space for the references following indirect outputs. */
    48674886
    4868   strtab_vector = (char **) malloc ((num_hash_tab_syms
     4887  strtab_vector = (char **) ALLOCA ((num_hash_tab_syms
    48694888                                     + global_indirect_count) * sizeof (char *));
    4870   strtab_lens = (int *) malloc ((num_hash_tab_syms
     4889  strtab_lens = (int *) ALLOCA ((num_hash_tab_syms
    48714890                                 + global_indirect_count) * sizeof (int));
    48724891  strtab_index = 0;
     
    49804999
    49815000  write_string_table ();
    4982   free (strtab_vector);
    4983   strtab_vector = NULL;
    4984   free (strtab_lens);
    4985   strtab_lens = NULL;
    4986   free (buf);
     5001  FREEA (strtab_vector);
     5002  FREEA (strtab_lens);
     5003  FREEA (buf);
    49875004}
    49885005
     
    50055022     It has one extra slot for the local symbol we generate here.  */
    50065023  struct nlist *buf
    5007     = (struct nlist *) malloc (entry->syms_size + sizeof (struct nlist));
     5024    = (struct nlist *) ALLOCA (entry->syms_size + sizeof (struct nlist));
    50085025  register struct nlist *bufp = buf;
    50095026
     
    50145031     The elements are filled in by `assign_string_table_index'.  */
    50155032
    5016   strtab_vector = (char **) malloc (max_syms * sizeof (char *));
    5017   strtab_lens = (int *) malloc (max_syms * sizeof (int));
     5033  strtab_vector = (char **) ALLOCA (max_syms * sizeof (char *));
     5034  strtab_lens = (int *) ALLOCA (max_syms * sizeof (int));
    50185035  strtab_index = 0;
    50195036
     
    50545071  /* Read the file's string table.  */
    50555072
    5056   entry->strings = (char *) malloc (entry->strs_size);
     5073  entry->strings = (char *) ALLOCA (entry->strs_size);
    50575074  read_entry_strings (file_open (entry), entry);
    50585075
     
    51075124
    51085125  write_string_table ();
    5109   free (entry->strings);
    5110   entry->strings = NULL;
    5111   free (strtab_vector);
    5112   strtab_vector = NULL;
    5113   free (strtab_lens);
    5114   strtab_lens = NULL;
    5115   free (buf);
     5126  FREEA (entry->strings);
     5127  FREEA (strtab_vector);
     5128  FREEA (strtab_lens);
     5129  FREEA (buf);
    51165130}
    51175131
     
    54545468    return;
    54555469
    5456   buf = (char *) alloca (padding);
     5470  buf = (char *) ALLOCA (padding);
    54575471  bzero (buf, padding);
    54585472  mywrite (buf, padding, 1, outdesc);
     5473  FREEA (buf);
    54595474}
    54605475
  • trunk/src/emx/src/ld/ld.smak

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r2274 r2275  
    88.TKIND  := $(TOOLFMT)
    99.TSRC   := $(wildcard src/ld/*.c)
    10 .TCF    := -DEMX
    11 .TLDF   := -liberty
     10.TCF    := -DEMX -DUSE_ALLOCA
     11.TLDF   := -liberty -Zstack 24575
    1212.TKEEP  := 1
    1313include mkexe.smak
Note: See TracChangeset for help on using the changeset viewer.