strip.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /* strip certain symbols from a rel file.
  2. Copyright (C) 1986 Richard M. Stallman
  3. NO WARRANTY
  4. BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  5. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
  6. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  7. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  8. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  9. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  10. FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
  11. AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
  12. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  13. CORRECTION.
  14. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  15. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  16. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  17. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  18. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  19. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  20. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  21. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  22. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  23. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  24. GENERAL PUBLIC LICENSE TO COPY
  25. 1. You may copy and distribute verbatim copies of this source file
  26. as you receive it, in any medium, provided that you conspicuously
  27. and appropriately publish on each copy a valid copyright notice
  28. "Copyright (C) 1986 Richard M. Stallman"; and include following the
  29. copyright notice a verbatim copy of the above disclaimer of warranty
  30. and of this License.
  31. 2. You may modify your copy or copies of this source file or
  32. any portion of it, and copy and distribute such modifications under
  33. the terms of Paragraph 1 above, provided that you also do the following:
  34. a) cause the modified files to carry prominent notices stating
  35. that you changed the files and the date of any change; and
  36. b) cause the whole of any work that you distribute or publish,
  37. that in whole or in part contains or is a derivative of this
  38. program or any part thereof, to be freely distributed
  39. and licensed to all third parties on terms identical to those
  40. contained in this License Agreement (except that you may choose
  41. to grant more extensive warranty protection to third parties,
  42. at your option).
  43. 3. You may copy and distribute this program or any portion of it in
  44. compiled, executable or object code form under the terms of Paragraphs
  45. 1 and 2 above provided that you do the following:
  46. a) cause each such copy to be accompanied by the
  47. corresponding machine-readable source code, which must
  48. be distributed under the terms of Paragraphs 1 and 2 above; or,
  49. b) cause each such copy to be accompanied by a
  50. written offer, with no time limit, to give any third party
  51. free (except for a nominal shipping charge) a machine readable
  52. copy of the corresponding source code, to be distributed
  53. under the terms of Paragraphs 1 and 2 above; or,
  54. c) in the case of a recipient of this program in compiled, executable
  55. or object code form (without the corresponding source code) you
  56. shall cause copies you distribute to be accompanied by a copy
  57. of the written offer of source code which you received along
  58. with the copy you received.
  59. 4. You may not copy, sublicense, distribute or transfer this program
  60. except as expressly provided under this License Agreement. Any attempt
  61. otherwise to copy, sublicense, distribute or transfer this program is void and
  62. your rights to use the program under this License agreement shall be
  63. automatically terminated. However, parties who have received computer
  64. software programs from you with this License Agreement will not have
  65. their licenses terminated so long as such parties remain in full compliance.
  66. In other words, you are welcome to use, share and improve this program.
  67. You are forbidden to forbid anyone else to use, share and improve
  68. what you give them. Help stamp out software-hoarding! */
  69. /* define this for a linker for the TI NU machine.
  70. Slightly different defaults. */
  71. /* #define numachine 1 */
  72. #ifdef numachine
  73. #define O_RDONLY 0
  74. #define O_RDWR 2
  75. #endif
  76. #include <a.out.h>
  77. #include <stdio.h>
  78. /* #include <sys/types.h> */
  79. #include <strings.h>
  80. /* #include <sys/stat.h> */
  81. #ifndef numachine
  82. #include <sys/file.h>
  83. #endif
  84. /* count the number of nlist entries that are for local symbols. */
  85. int local_sym_count;
  86. /* count number of nlist entries that are for local symbols whose names don't start with L. */
  87. int non_L_local_sym_count;
  88. /* count the number of nlist entries for debugger info. */
  89. int debugger_sym_count;
  90. /* count the number of global symbols referenced or defined. */
  91. int global_sym_count;
  92. /* Total number of symbols to be preserved in the current file. */
  93. int nsyms;
  94. /* Number of files specified in the command line. */
  95. int number_of_files;
  96. /* Each specified file has a file_entry structure for it.
  97. These are contained in the vector which file_table points to.
  98. */
  99. struct file_entry {
  100. char *filename;
  101. struct exec header; /* the file's header */
  102. int ss_size; /* size, in bytes, of symbols_and_strings data */
  103. struct nlist *symbols_and_strings;
  104. };
  105. struct file_entry *file_table;
  106. /* descriptor on which current file is open. */
  107. int input_desc;
  108. /* stream for writing that file using stdio. */
  109. FILE *outstream;
  110. /* 1 => strip all symbols; 2 => strip all but locals and globals */
  111. int strip_symbols;
  112. /* 1 => discard locals starting with L; 2 => discard all locals */
  113. int discard_locals;
  114. void decode_command (), strip_file ();
  115. void each_file ();
  116. int file_open ();
  117. void read_file_symbols (), rewrite_file_symbols(), file_close();
  118. void read_header(), read_file_symbols (), read_entry_symbols();
  119. void count_file_symbols ();
  120. char *concat ();
  121. main(argc, argv)
  122. char **argv;
  123. int argc;
  124. {
  125. strip_symbols = 1; /* default is to strip nothing. *//* JF default is to strip everything! */
  126. discard_locals = 0; /* JF new default was 0 */
  127. decode_command (argc, argv);
  128. each_file (strip_file);
  129. }
  130. /* process one input file */
  131. void
  132. strip_file (entry)
  133. struct file_entry *entry;
  134. {
  135. local_sym_count = 0;
  136. non_L_local_sym_count = 0;
  137. debugger_sym_count = 0;
  138. global_sym_count = 0;
  139. file_open (entry);
  140. if (strip_symbols != 1)
  141. /* read in the existing symbols unless we are discarding everything. */
  142. read_file_symbols (entry);
  143. rewrite_file_symbols (entry);
  144. if (strip_symbols != 1)
  145. free (entry->symbols_and_strings);
  146. file_close ();
  147. }
  148. void decode_switch ();
  149. /* analyze a command line argument.
  150. Returns 0 if the argument is a filename.
  151. Returns 1 if the argument is a switch complete in itself.
  152. Returns 2 if the argument is a switch which gobbles the following argument. */
  153. int
  154. decode_arg(arg)
  155. char *arg;
  156. {
  157. if (*arg != '-') return 0;
  158. return 1;
  159. }
  160. /* Process the command arguments, setting up file_table with an entry for
  161. each file, and setting variables according to the switches. */
  162. void
  163. decode_command(argc, argv)
  164. char **argv;
  165. int argc;
  166. {
  167. int i;
  168. struct file_entry *p;
  169. number_of_files = 0;
  170. /* First compute number_of_files so we know how long to make file_table */
  171. /* Also process most switches completely */
  172. for (i = 1; i < argc; i++)
  173. {
  174. int code = decode_arg (argv[i]);
  175. if (code)
  176. {
  177. i += code - 1;
  178. }
  179. else
  180. number_of_files++;
  181. }
  182. if (!number_of_files)
  183. fatal ("no files specified", 0);
  184. p = file_table
  185. = (struct file_entry *) xmalloc (number_of_files * sizeof (struct file_entry));
  186. /* Now scan again and fill in file_table */
  187. for (i = 1; i < argc; i++)
  188. {
  189. int code = decode_arg (argv[i]);
  190. if (code)
  191. {
  192. decode_switch (argv[i]);
  193. i += code - 1;
  194. }
  195. else
  196. {
  197. p->filename = argv[i];
  198. p->symbols_and_strings = 0;
  199. p++;
  200. }
  201. }
  202. }
  203. void
  204. decode_switch (swt)
  205. char *swt;
  206. {
  207. if (!strcmp (swt, "-S"))
  208. strip_symbols = 2;
  209. else if (!strcmp (swt, "-s"))
  210. strip_symbols = 1;
  211. else if (!strcmp (swt, "-X"))
  212. discard_locals = 1;
  213. else if (!strcmp (swt, "-x"))
  214. discard_locals = 2;
  215. else
  216. fatal ("invalid command switch %s", swt);
  217. }
  218. /** Convenient functions for operating on one or all files being processed. */
  219. /* Call 'function' on each file entry.
  220. 'function' receives two arguments: the entry, and 'arg'. */
  221. void
  222. each_file (function, arg)
  223. void (*function)();
  224. int arg;
  225. {
  226. int i;
  227. for (i = 0; i < number_of_files; i++)
  228. {
  229. struct file_entry *entry = &file_table[i];
  230. (*function) (entry, arg);
  231. }
  232. }
  233. /* Close the file that is now open. */
  234. void
  235. file_close ()
  236. {
  237. close (input_desc);
  238. input_desc = 0;
  239. }
  240. /* open the file specified by 'entry', and return a descriptor.
  241. The descriptor is also saved in input_desc. */
  242. /* JF this also makes sure the file is in rel format */
  243. int
  244. file_open (entry)
  245. struct file_entry *entry;
  246. {
  247. int desc;
  248. int len, magicnum;
  249. desc = open (entry->filename, O_RDWR, 0);
  250. if (desc > 0)
  251. {
  252. input_desc = desc;
  253. len = read (input_desc, (char *)&magicnum, sizeof magicnum);
  254. if (len != sizeof magicnum)
  255. fatal_with_file ("failure reading header of ", entry);
  256. if (N_BADMAG(*((struct exec *)&magicnum)))
  257. fatal_with_file ("malformed input file (not rel) ", entry);
  258. read_header (desc, &entry->header, entry);
  259. return desc;
  260. }
  261. perror_file (entry);
  262. }
  263. /* Print the filename of 'entry' on 'outfile' (a stdio stream), and then a newline. */
  264. prline_file_name (entry, outfile)
  265. struct file_entry *entry;
  266. FILE *outfile;
  267. {
  268. print_file_name (entry, outfile);
  269. fprintf (outfile, "\n");
  270. }
  271. /* Print the filename of 'entry' on 'outfile' (a stdio stream). */
  272. print_file_name (entry, outfile)
  273. struct file_entry *entry;
  274. FILE *outfile;
  275. {
  276. fprintf (outfile, "%s", entry->filename);
  277. }
  278. /* Validate file 'entry' and read its symbol and string sections into core. */
  279. void
  280. read_file_symbols (entry)
  281. struct file_entry *entry;
  282. {
  283. read_entry_symbols (input_desc, entry);
  284. count_file_symbols (entry);
  285. }
  286. /* read a file's header into the proper place in the file_entry. */
  287. void
  288. read_header (desc, loc, entry)
  289. int desc;
  290. struct exec *loc;
  291. struct file_entry *entry;
  292. {
  293. int len;
  294. lseek (desc,0, 0);
  295. len = read (desc, loc, sizeof (struct exec));
  296. if (len != sizeof (struct exec))
  297. fatal_with_file ("failure reading header of ", entry);
  298. if (N_BADMAG(*loc))
  299. fatal_with_file ("bad magic number in ", entry);
  300. }
  301. /* Read the symbols and strings of file 'entry' into core.
  302. Assume it is already open, on descriptor 'desc'. */
  303. void
  304. read_entry_symbols (desc, entry)
  305. struct file_entry *entry;
  306. int desc;
  307. {
  308. int string_size;
  309. lseek (desc, N_STROFF(entry->header), 0);
  310. if (sizeof string_size != read (desc, &string_size, sizeof string_size))
  311. fatal_with_file ("bad string table in ", entry);
  312. entry->ss_size = string_size + entry->header.a_syms;
  313. entry->symbols_and_strings = (struct nlist *) xmalloc (entry->ss_size);
  314. lseek (desc, N_SYMOFF(entry->header), 0);
  315. if (entry->ss_size != read (desc, entry->symbols_and_strings, entry->ss_size))
  316. fatal_with_file ("premature end of file in symbols/strings of ", entry);
  317. }
  318. /* count the number of symbols of various categories in the file of 'entry' */
  319. void
  320. count_file_symbols (entry)
  321. struct file_entry *entry;
  322. {
  323. struct nlist *p, *end = entry->symbols_and_strings + entry->header.a_syms / sizeof (struct nlist);
  324. char *name_base = entry->header.a_syms + (char *) entry->symbols_and_strings;
  325. for (p = entry->symbols_and_strings; p < end; p++)
  326. if (p->n_type & N_EXT)
  327. global_sym_count++;
  328. else if (p->n_un.n_strx && !(p->n_type & (N_STAB | N_EXT)))
  329. {
  330. if ((p->n_un.n_strx + name_base)[0] != 'L')
  331. non_L_local_sym_count++;
  332. local_sym_count++;
  333. }
  334. else debugger_sym_count++;
  335. }
  336. void write_file_syms(), modify_relocation ();
  337. /* total size of string table strings allocated so far */
  338. int strtab_size;
  339. /* Vector whose elements are the strings to go in the string table */
  340. char **strtab_vector;
  341. /* Index in strtab_vector at which the next string will be stored */
  342. int strtab_index;
  343. int sym_written_count;
  344. int
  345. assign_string_table_index (name)
  346. char *name;
  347. {
  348. int index = strtab_size;
  349. strtab_size += strlen (name) + 1;
  350. strtab_vector[strtab_index++] = name;
  351. return index;
  352. }
  353. void
  354. rewrite_file_symbols (entry)
  355. struct file_entry *entry;
  356. {
  357. int i;
  358. struct nlist *newsyms;
  359. /* Calculate number of symbols to be preserved. */
  360. if (strip_symbols == 1)
  361. nsyms = 0;
  362. else
  363. {
  364. nsyms = global_sym_count;
  365. if (discard_locals == 1)
  366. nsyms += non_L_local_sym_count;
  367. else if (discard_locals == 0)
  368. nsyms += local_sym_count;
  369. }
  370. if (strip_symbols == 0)
  371. nsyms += debugger_sym_count;
  372. strtab_vector = (char **) xmalloc (nsyms * sizeof (char *));
  373. strtab_index = 0;
  374. strtab_size = 4;
  375. /* Accumulate in 'newsyms' the symbol table to be written. */
  376. newsyms = (struct nlist *) xmalloc (nsyms * sizeof (struct nlist));
  377. sym_written_count = 0;
  378. if (strip_symbols != 1)
  379. /* Write into newsyms the symbols we want to keep. */
  380. write_file_syms (entry, newsyms);
  381. if (sym_written_count != nsyms)
  382. {
  383. fprintf (stderr, "written = %d, expected = %d\n", sym_written_count, nsyms);
  384. fatal_with_file ("internal error: wrong number of symbols written in ", entry);
  385. }
  386. /* modify the symbol-numbers in the relocation in the file, to preserve its meaning */
  387. modify_relocation (input_desc, entry);
  388. /* now write contents of 'newsyms' into the file. */
  389. lseek (input_desc, N_SYMOFF(entry->header), 0);
  390. write (input_desc, newsyms, nsyms * sizeof (struct nlist));
  391. free (newsyms);
  392. /* now write the string table. */
  393. {
  394. char *strvec = (char *) xmalloc (strtab_size);
  395. char *p;
  396. *((long *) strvec) = strtab_size;
  397. p = strvec + sizeof (long);
  398. for (i = 0; i < strtab_index; i++)
  399. {
  400. int len = strlen (strtab_vector[i]);
  401. strcpy (p, strtab_vector[i]);
  402. *(p+len) = 0;
  403. p += len + 1;
  404. }
  405. write (input_desc, strvec, strtab_size);
  406. free (strvec);
  407. }
  408. /* adjust file to be smaller */
  409. #ifndef numachine
  410. /* ftruncate (input_desc, ftell (outstream)); */
  411. if(ftruncate (input_desc, tell(input_desc)) < 0) /* JF make it work right */
  412. perror_file(entry);
  413. #endif
  414. /* write new symbol table size into file header. */
  415. entry->header.a_syms = nsyms * sizeof (struct nlist);
  416. lseek (input_desc, 0, 0);
  417. write (input_desc, &entry->header, sizeof (struct exec));
  418. free (strtab_vector);
  419. }
  420. /* Copy into 'newsyms' the symbol entries to be preserved.
  421. Count them in sym_written_count. */
  422. /* We record, for each symbol written, its symbol number in the resulting file.
  423. This is so that the relocation can be updated later.
  424. Since the symbol names will not be needed again,
  425. this index goes in the n_strx field.
  426. If a symbol is not written, -1 is stored there. */
  427. void
  428. write_file_syms (entry, newsyms)
  429. struct file_entry *entry;
  430. struct nlist *newsyms;
  431. {
  432. struct nlist *p = entry->symbols_and_strings;
  433. struct nlist *end = p + entry->header.a_syms / sizeof (struct nlist);
  434. char *string_base = (char *) end; /* address of start of file's string table */
  435. struct nlist *outp = newsyms;
  436. for (; p < end; p++)
  437. {
  438. int type = p->n_type;
  439. int write;
  440. if (p->n_type & N_EXT)
  441. write = 1;
  442. else if (p->n_un.n_strx && !(p->n_type & (N_STAB | N_EXT)))
  443. /* ordinary local symbol */
  444. write = (discard_locals != 2)
  445. && !(discard_locals == 1 &&
  446. (p->n_un.n_strx + string_base)[0] == 'L');
  447. else
  448. /* debugger symbol */
  449. write = (strip_symbols == 0);
  450. if (write)
  451. {
  452. if (p->n_un.n_strx)
  453. p->n_un.n_strx = assign_string_table_index (p->n_un.n_strx + string_base);
  454. *outp++ = *p;
  455. p->n_un.n_strx = sym_written_count++;
  456. }
  457. else p->n_un.n_strx = -1;
  458. }
  459. }
  460. /* read in 'entry's relocation, alter the symbolnum's in it, and write it out again. */
  461. void
  462. modify_relocation (desc, entry)
  463. int desc;
  464. struct file_entry *entry;
  465. {
  466. struct relocation_info *reloc, *p, *end;
  467. int size = entry->header.a_trsize + entry->header.a_drsize;
  468. struct nlist *sym_base = (struct nlist *) entry->symbols_and_strings;
  469. reloc = (struct relocation_info *) xmalloc (size);
  470. lseek (desc, N_TXTOFF(entry->header) + entry->header.a_text + entry->header.a_data, 0);
  471. read (desc, reloc, size);
  472. p = reloc;
  473. end = (struct relocation_info *) (size + (char *) reloc);
  474. while (p < end)
  475. {
  476. if (p->r_extern)
  477. {
  478. int newnum = (sym_base + p->r_symbolnum) -> n_un.n_strx;
  479. if (newnum < 0)
  480. fatal_with_file ("stripped symbol needed for relocation in ", entry);
  481. p->r_symbolnum = newnum;
  482. }
  483. p++;
  484. }
  485. lseek (desc, N_TXTOFF(entry->header) + entry->header.a_text + entry->header.a_data, 0);
  486. write (desc, reloc, size);
  487. }
  488. /* Report a fatal error. 'string' is a printf format string and 'arg' is one arg for it. */
  489. fatal (string, arg)
  490. char *string, *arg;
  491. {
  492. fprintf (stderr, "strip: ");
  493. fprintf (stderr, string, arg);
  494. fprintf (stderr, "\n");
  495. exit (1);
  496. }
  497. /* Report a fatal error. 'string' is printed, followed by the filename of 'entry'. */
  498. fatal_with_file (string, entry)
  499. char *string;
  500. struct file_entry *entry;
  501. {
  502. fprintf (stderr, "strip: ");
  503. fprintf (stderr, string);
  504. print_file_name (entry, stderr);
  505. fprintf (stderr, "\n");
  506. exit (1);
  507. }
  508. /* Report a fatal error using the message for the last failed system call,
  509. followed by the string 'name'. */
  510. perror_name (name)
  511. char *name;
  512. {
  513. extern int errno, sys_nerr;
  514. extern char *sys_errlist[];
  515. char *s;
  516. if (errno < sys_nerr)
  517. s = concat ("", sys_errlist[errno], " for %s");
  518. else
  519. s = "cannot open %s";
  520. fatal (s, name);
  521. }
  522. /* Report a fatal error using the message for the last failed system call,
  523. followed by the name of file 'entry'. */
  524. perror_file (entry)
  525. struct file_entry *entry;
  526. {
  527. extern int errno, sys_nerr;
  528. extern char *sys_errlist[];
  529. char *s;
  530. if (errno < sys_nerr)
  531. s = concat ("", sys_errlist[errno], " for ");
  532. else
  533. s = "cannot open ";
  534. fatal_with_file (s, entry);
  535. }
  536. /* Report a nonfatal error.
  537. 'string' is a format for printf, and 'arg1' ... 'arg3' are args for it. */
  538. error (string, arg1, arg2, arg3)
  539. char *string, *arg1, *arg2, *arg3;
  540. {
  541. fprintf (stderr, string, arg1, arg2, arg3);
  542. fprintf (stderr, "\n");
  543. }
  544. /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
  545. char *
  546. concat (s1, s2, s3)
  547. char *s1, *s2, *s3;
  548. {
  549. int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
  550. char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
  551. strcpy (result, s1);
  552. strcpy (result + len1, s2);
  553. strcpy (result + len1 + len2, s3);
  554. *(result + len1 + len2 + len3) = 0;
  555. return result;
  556. }
  557. /* Like malloc but get fatal error if memory is exhausted. */
  558. int
  559. xmalloc (size)
  560. int size;
  561. {
  562. int result = malloc (size);
  563. if (!result)
  564. fatal ("virtual memory exhausted", 0);
  565. return result;
  566. }