Changeset 2275
- Timestamp:
- Jul 24, 2005, 11:26:11 AM (20 years ago)
- Location:
- trunk/src/emx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/ChangeLog.LIBC
-
Property cvs2svn:cvs-rev
changed from
1.112
to1.113
r2274 r2275 10 10 - ld: 11 11 o Fixed a case of memory access after free. 12 o Switched back to alloca and adding 23 MB of stack. 12 13 13 14 2005-07-21: knut st. osmundsen <bird-gccos2-spam@anduin.net> -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/ld/ld.c
-
Property cvs2svn:cvs-rev
changed from
1.20
to1.21
r2274 r2275 63 63 64 64 /* If compiled with GNU C, use the built-in alloca */ 65 #ifdef USE_ALLOCA 65 66 #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 66 73 #include "getopt.h" 67 74 … … 1953 1960 { 1954 1961 read_entry_symbols (desc, entry); 1955 entry->strings = (char *) malloc(entry->strs_size);1962 entry->strings = (char *) ALLOCA (entry->strs_size); 1956 1963 read_entry_strings (desc, entry); 1957 1964 enter_file_symbols (entry); 1958 free (entry->strings); 1959 entry->strings = NULL; 1965 FREEA (entry->strings); 1960 1966 } 1961 1967 … … 2172 2178 { 2173 2179 register char *reftype; 2180 int free_reftype = 0; 2174 2181 switch (realtype & ~N_EXT) 2175 2182 { … … 2217 2224 2218 2225 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)); 2220 2227 sprintf (reftype, "defined equivalent to %s", 2221 2228 ((symbol *) nlist_p->n_value)->name); 2229 free_reftype = 1; 2222 2230 break; 2223 2231 … … 2248 2256 fprintf (stderr, ": %3d %s %s\n", 2249 2257 nlist_p - entry->symbols, sp->name, reftype); 2258 if (free_reftype) 2259 FREEA (reftype); 2250 2260 } 2251 2261 } … … 2530 2540 { 2531 2541 read_entry_symbols (desc, subentry); 2532 subentry->strings = (char *) malloc(subentry->strs_size);2542 subentry->strings = (char *) ALLOCA (subentry->strs_size); 2533 2543 read_entry_strings (desc, subentry); 2534 2544 2535 2545 if (!subfile_wanted_p (subentry)) 2536 2546 { 2537 free (subentry->strings); 2538 subentry->strings = NULL; 2547 FREEA (subentry->strings); 2539 2548 free (subentry->symbols); 2540 2549 free (subentry); … … 2549 2558 entry->subfiles = subentry; 2550 2559 *prev_addr = subentry; 2551 free (subentry->strings); 2552 subentry->strings = NULL; 2560 FREEA (subentry->strings); 2553 2561 } 2554 2562 } … … 3062 3070 *end = entry->symbols + entry->syms_size / sizeof (struct nlist); 3063 3071 3064 entry->strings = (char *) malloc(entry->strs_size);3072 entry->strings = (char *) ALLOCA (entry->strs_size); 3065 3073 read_entry_strings (file_open (entry), entry); 3066 3074 … … 3080 3088 ((symbol *)p->n_un.n_name)->name, p->n_value); 3081 3089 3082 free (entry->strings); 3083 entry->strings = NULL; /* All done with them. */ 3090 FREEA (entry->strings); 3084 3091 } 3085 3092 … … 3452 3459 int number_of_syms = entry->syms_size / sizeof (struct nlist); 3453 3460 unsigned char *nlist_bitvector 3454 = (unsigned char *) malloc((number_of_syms >> 3) + 1);3461 = (unsigned char *) ALLOCA ((number_of_syms >> 3) + 1); 3455 3462 struct line_debug_entry *text_scan, *data_scan; 3456 3463 int i; … … 3466 3473 int desc; 3467 3474 3468 entry->strings = (char *) malloc(entry->strs_size);3475 entry->strings = (char *) ALLOCA (entry->strs_size); 3469 3476 desc = file_open (entry); 3470 3477 read_entry_strings (desc, entry); … … 3586 3593 free (text_scan); 3587 3594 free (data_scan); 3588 free (entry->strings); 3589 entry->strings = NULL; 3590 free (nlist_bitvector); 3595 FREEA (entry->strings); 3596 FREEA (nlist_bitvector); 3591 3597 } 3592 3598 … … 3975 3981 { 3976 3982 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; 3980 3987 nargv[i++] = "emxbind"; 3981 3988 nargv[i++] = "-bq"; … … 3986 3993 if (def_filename != NULL) 3987 3994 { 3988 nargv[i] = alloca(strlen (def_filename) + 3);3995 freeav[j++] = nargv[i] = ALLOCA (strlen (def_filename) + 3); 3989 3996 strcpy (nargv[i], "-d"); 3990 3997 strcat (nargv[i], def_filename); … … 3995 4002 if (stack_size != 0) 3996 4003 { 3997 nargv[i] = alloca(20);4004 freeav[j++] = nargv[i] = ALLOCA (20); 3998 4005 sprintf (nargv[i], "-k0x%x", stack_size); 3999 4006 i++; … … 4003 4010 if (map_filename == NULL) 4004 4011 { 4005 map_filename = alloca(strlen (output_filename) + 5);4012 freeav[j++] = map_filename = ALLOCA (strlen (output_filename) + 5); 4006 4013 strcpy (map_filename, exe_filename); 4007 4014 _remext (map_filename); 4008 4015 strcat (map_filename, ".map"); 4009 4016 } 4010 nargv[i] = alloca(strlen (map_filename) + 3);4017 freeav[j++] = nargv[i] = ALLOCA (strlen (map_filename) + 3); 4011 4018 strcpy (nargv[i], "-m"); 4012 4019 strcat (nargv[i], map_filename); … … 4015 4022 if (res_filename != NULL) 4016 4023 { 4017 nargv[i] = alloca(strlen (res_filename) + 3);4024 freeav[j++] = nargv[i] = ALLOCA (strlen (res_filename) + 3); 4018 4025 strcpy (nargv[i], "-r"); 4019 4026 strcat (nargv[i], res_filename); … … 4054 4061 perror_name (touch_filename); 4055 4062 } 4063 while (j-- > 0) 4064 FREEA (freeav[j]); 4056 4065 } 4057 4066 else if (exe_filename != NULL) /* RSXNT */ 4058 4067 { 4059 4068 char *nargv[10]; 4069 char *freea = NULL; 4060 4070 int i, saved_errno; 4061 4071 … … 4077 4087 { 4078 4088 nargv[i++] = "-d"; 4079 nargv[i] = alloca(strlen (def_filename) + 3);4089 freea = nargv[i] = ALLOCA (strlen (def_filename) + 3); 4080 4090 strcpy(nargv[i], def_filename); 4081 4091 i++; … … 4099 4109 close (i); 4100 4110 } 4111 FREEA (freea); 4101 4112 } 4102 4113 } … … 4190 4201 register int desc; 4191 4202 register struct relocation_info *reloc; 4203 int free_reloc = 0; 4192 4204 4193 4205 if (trace_files) … … 4198 4210 /* Allocate space for the file's text section */ 4199 4211 4200 bytes = (char *) malloc(entry->text_size);4212 bytes = (char *) ALLOCA (entry->text_size); 4201 4213 4202 4214 /* Deal with relocation information however is appropriate */ … … 4210 4222 else 4211 4223 { 4212 reloc = (struct relocation_info *) alloca (entry->text_reloc_size); 4224 free_reloc = 1; 4225 reloc = (struct relocation_info *) ALLOCA (entry->text_reloc_size); 4213 4226 lseek (desc, entry->starting_offset + entry->text_reloc_offset, L_SET); 4214 4227 if (entry->text_reloc_size != read (desc, reloc, entry->text_reloc_size)) … … 4231 4244 mywrite (bytes, 1, entry->text_size, outdesc); 4232 4245 4233 free (bytes); 4246 FREEA (bytes); 4247 if (free_reloc) 4248 FREEA (reloc); 4234 4249 } 4235 4250 … … 4322 4337 register char *bytes; 4323 4338 register int desc; 4339 int free_reloc = 0; 4324 4340 4325 4341 if (trace_files) … … 4328 4344 desc = file_open (entry); 4329 4345 4330 bytes = (char *) malloc(entry->data_size);4346 bytes = (char *) ALLOCA (entry->data_size); 4331 4347 4332 4348 if (entry->datarel) reloc = entry->datarel; … … 4338 4354 else 4339 4355 { 4340 reloc = (struct relocation_info *) alloca (entry->data_reloc_size); 4356 free_reloc = 1; 4357 reloc = (struct relocation_info *) ALLOCA (entry->data_reloc_size); 4341 4358 lseek (desc, entry->starting_offset + entry->data_reloc_offset, L_SET); 4342 4359 if (entry->data_reloc_size != read (desc, reloc, entry->data_reloc_size)) … … 4354 4371 padfile ((SECTION_ALIGN - entry->data_size) & SECTION_ALIGN_MASK, outdesc); 4355 4372 4356 free (bytes); 4373 FREEA (bytes); 4374 if (free_reloc) 4375 FREEA (reloc); 4357 4376 } 4358 4377 … … 4839 4858 extra struct for each indirect symbol to hold the extra reference 4840 4859 following. */ 4841 struct nlist *buf = (struct nlist *) malloc((defined_global_sym_count4860 struct nlist *buf = (struct nlist *) ALLOCA ((defined_global_sym_count 4842 4861 + undefined_global_sym_count 4843 4862 + global_indirect_count) … … 4866 4885 extra space for the references following indirect outputs. */ 4867 4886 4868 strtab_vector = (char **) malloc((num_hash_tab_syms4887 strtab_vector = (char **) ALLOCA ((num_hash_tab_syms 4869 4888 + global_indirect_count) * sizeof (char *)); 4870 strtab_lens = (int *) malloc((num_hash_tab_syms4889 strtab_lens = (int *) ALLOCA ((num_hash_tab_syms 4871 4890 + global_indirect_count) * sizeof (int)); 4872 4891 strtab_index = 0; … … 4980 4999 4981 5000 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); 4987 5004 } 4988 5005 … … 5005 5022 It has one extra slot for the local symbol we generate here. */ 5006 5023 struct nlist *buf 5007 = (struct nlist *) malloc(entry->syms_size + sizeof (struct nlist));5024 = (struct nlist *) ALLOCA (entry->syms_size + sizeof (struct nlist)); 5008 5025 register struct nlist *bufp = buf; 5009 5026 … … 5014 5031 The elements are filled in by `assign_string_table_index'. */ 5015 5032 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)); 5018 5035 strtab_index = 0; 5019 5036 … … 5054 5071 /* Read the file's string table. */ 5055 5072 5056 entry->strings = (char *) malloc(entry->strs_size);5073 entry->strings = (char *) ALLOCA (entry->strs_size); 5057 5074 read_entry_strings (file_open (entry), entry); 5058 5075 … … 5107 5124 5108 5125 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); 5116 5130 } 5117 5131 … … 5454 5468 return; 5455 5469 5456 buf = (char *) alloca(padding);5470 buf = (char *) ALLOCA (padding); 5457 5471 bzero (buf, padding); 5458 5472 mywrite (buf, padding, 1, outdesc); 5473 FREEA (buf); 5459 5474 } 5460 5475 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/ld/ld.smak
-
Property cvs2svn:cvs-rev
changed from
1.11
to1.12
r2274 r2275 8 8 .TKIND := $(TOOLFMT) 9 9 .TSRC := $(wildcard src/ld/*.c) 10 .TCF := -DEMX 11 .TLDF := -liberty 10 .TCF := -DEMX -DUSE_ALLOCA 11 .TLDF := -liberty -Zstack 24575 12 12 .TKEEP := 1 13 13 include mkexe.smak -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.