robotussin.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /* Convert COFF-format object file to BSD format.
  2. Used for converting the system libraries so GNU ld can link them.
  3. Copyright (C) 1988 Free Software Foundation, Inc.
  4. NO WARRANTY
  5. BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  6. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
  7. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  8. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  9. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  10. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  11. FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
  12. AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
  13. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  14. CORRECTION.
  15. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  16. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  17. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  18. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  19. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  20. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  21. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  22. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  23. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  24. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  25. GENERAL PUBLIC LICENSE TO COPY
  26. 1. You may copy and distribute verbatim copies of this source file
  27. as you receive it, in any medium, provided that you conspicuously
  28. and appropriately publish on each copy a valid copyright notice
  29. "Copyright (C) 1988 Free Software Foundation, Inc.", and include
  30. following the copyright notice a verbatim copy of the above disclaimer
  31. of warranty and of this License.
  32. 2. You may modify your copy or copies of this source file or
  33. any portion of it, and copy and distribute such modifications under
  34. the terms of Paragraph 1 above, provided that you also do the following:
  35. a) cause the modified files to carry prominent notices stating
  36. that you changed the files and the date of any change; and
  37. b) cause the whole of any work that you distribute or publish,
  38. that in whole or in part contains or is a derivative of this
  39. program or any part thereof, to be licensed at no charge to all
  40. third parties on terms identical to those contained in this
  41. License Agreement (except that you may choose to grant more extensive
  42. warranty protection to some or all third parties, at your option).
  43. c) You may charge a distribution fee for the physical act of
  44. transferring a copy, and you may at your option offer warranty
  45. protection in exchange for a fee.
  46. Mere aggregation of another unrelated program with this program (or its
  47. derivative) on a volume of a storage or distribution medium does not bring
  48. the other program under the scope of these terms.
  49. 3. You may copy and distribute this program (or a portion or derivative
  50. of it, under Paragraph 2) in object code or executable form under the terms
  51. of Paragraphs 1 and 2 above provided that you also do one of the following:
  52. a) accompany it with the complete corresponding machine-readable
  53. source code, which must be distributed under the terms of
  54. Paragraphs 1 and 2 above; or,
  55. b) accompany it with a written offer, valid for at least three
  56. years, to give any third party free (except for a nominal
  57. shipping charge) a complete machine-readable copy of the
  58. corresponding source code, to be distributed under the terms of
  59. Paragraphs 1 and 2 above; or,
  60. c) accompany it with the information you received as to where the
  61. corresponding source code may be obtained. (This alternative is
  62. allowed only for noncommercial distribution and only if you
  63. received the program in object code or executable form alone.)
  64. For an executable file, complete source code means all the source code for
  65. all modules it contains; but, as a special exception, it need not include
  66. source code for modules which are standard libraries that accompany the
  67. operating system on which the executable file runs.
  68. 4. You may not copy, sublicense, distribute or transfer this program
  69. except as expressly provided under this License Agreement. Any attempt
  70. otherwise to copy, sublicense, distribute or transfer this program is void and
  71. your rights to use the program under this License agreement shall be
  72. automatically terminated. However, parties who have received computer
  73. software programs from you with this License Agreement will not have
  74. their licenses terminated so long as such parties remain in full compliance.
  75. 5. If you wish to incorporate parts of this program into other free
  76. programs whose distribution conditions are different, write to the Free
  77. Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
  78. worked out a simple rule that can be stated here, but we will often permit
  79. this. We will be guided by the two goals of preserving the free status of
  80. all derivatives of our free software and of promoting the sharing and reuse of
  81. software.
  82. In other words, you are welcome to use, share and improve this program.
  83. You are forbidden to forbid anyone else to use, share and improve
  84. what you give them. Help stamp out software-hoarding! */
  85. /*
  86. ** Robotussin - convert COFF format object files to BSD format.
  87. **
  88. ** written by Jeff Lewis, donated to the Free Software Foundation.
  89. **
  90. ** BUGS:
  91. ** Should do more to verify that the input COFF file meets our
  92. ** expectations.
  93. ** On machines where the structure of the COFF data in the file does not
  94. ** match the structure of the COFF data declared (when, for example
  95. ** sizeof (struct filhdr) != FILHSZ), this program will fail. (Don't
  96. ** ask me why this is ever allowed to come about). Accessor functions/
  97. ** macros that painstakingly extract the data out of the file and stuff
  98. ** it in the memory struct should be written to fix this on such machines.
  99. **
  100. ** CAVEATS:
  101. ** This program cannot claim correctness, however, it does appear
  102. ** to work on my fairly vanilla Sys5r2 machine. Someone with the time
  103. ** and a fine tooth comb (not to mention some documentation on COFF)
  104. ** should correct this!
  105. */
  106. #ifndef COFF_ENCAPSULATE
  107. #define COFF_ENCAPSULATE
  108. #endif
  109. /* Customization for a particular machine. */
  110. #define INPUT_MAGIC I386MAGIC
  111. #define nounderscore
  112. #include <stdio.h>
  113. #include <varargs.h>
  114. #include <fcntl.h>
  115. #include "a.out.encap.h"
  116. #define N_ABSOLUTE N_ABS /* N_ABS will be redefined in syms.h */
  117. #undef N_ABS
  118. #include <filehdr.h>
  119. #include <aouthdr.h>
  120. #include <scnhdr.h>
  121. #include <syms.h>
  122. #include <reloc.h>
  123. /* Because of struct alignment on dwords sizeof (struct syment) is different
  124. than the syments stored in the file. Therefore, we must kludge: */
  125. #define sizeof_syment (SYMESZ)
  126. #define sizeof_reloc (RELSZ)
  127. #define sizeof_section (SCNHSZ)
  128. #define sizeof_coff_header (FILHSZ)
  129. extern long lseek ();
  130. extern void exit ();
  131. extern char *memcpy ();
  132. extern int errno;
  133. void error (), sys_error ();
  134. static void reloc_segment ();
  135. char *mem_alloc ();
  136. int fd_in, fd_out; /* input and output file descriptors */
  137. struct filehdr coff_header; /* file header from the input file */
  138. struct exec bsd_header; /* file header for the output file */
  139. struct syment *coff_sym_listp; /* list of symbols from the input */
  140. int *symbol_map; /* mapping of input symbol #'s to
  141. output symbol numbers */
  142. char *text_and_data; /* space for text & data section data */
  143. char *relocations; /* space for output reloc entries */
  144. int verbose_flag; /* flag for debugging */
  145. struct scnhdr coff_text_header; /* COFF text section header */
  146. struct scnhdr coff_data_header; /* COFF data section header */
  147. struct scnhdr coff_bss_header; /* COFF bss section header */
  148. int text_sect_num; /* COFF section # for text */
  149. int data_sect_num; /* COFF section # for data */
  150. int bss_sect_num; /* COFF section # for bss */
  151. int
  152. main (argc, argv)
  153. int argc;
  154. char **argv;
  155. {
  156. int i, j;
  157. char *coff_string_table, *bsd_string_table;
  158. register char *pc, *pc2;
  159. int string_table_len;
  160. int symbol_count;
  161. struct scnhdr section;
  162. struct nlist name;
  163. if (argc < 3)
  164. error ("usage: %s cofffile bsdfile", argv[0]);
  165. if (argc > 3)
  166. verbose_flag = 1;
  167. fd_in = open (argv[1], O_RDONLY);
  168. if (fd_in < 0)
  169. sys_error ("can't open %s", argv[1]);
  170. fd_out = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666);
  171. if (fd_out < 0)
  172. sys_error ("can't open %s", argv[2]);
  173. /*
  174. ** Read in the file header and all section headers searching
  175. ** for text, data and bss. We note the section #'s of these
  176. ** sections for use when examining symbols.
  177. */
  178. if (read (fd_in, &coff_header, sizeof_coff_header) != sizeof_coff_header)
  179. error ("can't read file header");
  180. if (coff_header.f_magic != INPUT_MAGIC)
  181. error ("bad magic number in coff file\n");
  182. lseek (fd_in, sizeof_coff_header + coff_header.f_opthdr, 0);
  183. for (i = 1; i <= coff_header.f_nscns; ++i)
  184. {
  185. if (read (fd_in, &section, sizeof_section) != sizeof_section)
  186. error ("can't read section header #%d", i);
  187. if (strcmp (section.s_name, _TEXT) == 0)
  188. {
  189. text_sect_num = i;
  190. memcpy (&coff_text_header, &section, sizeof section);
  191. }
  192. else if (strcmp (section.s_name, _DATA) == 0)
  193. {
  194. data_sect_num = i;
  195. memcpy (&coff_data_header, &section, sizeof section);
  196. }
  197. else if (strcmp (section.s_name, _BSS) == 0)
  198. {
  199. bss_sect_num = i;
  200. memcpy (&coff_bss_header, &section, sizeof section);
  201. }
  202. }
  203. /*
  204. ** Pass1 thru the symbol table - count usable symbols and map
  205. ** old symbol #'s into new ones (as used by relocation
  206. ** info). We're only interested in keeping the kinds of symbols
  207. ** we'd expect to find in a BSD library object file: no debug
  208. ** symbols, file names, section definition symbols, etc.
  209. ** Section definition symbols are referenced by reloc entries
  210. ** in the COFF file, so we note their position with a negative
  211. ** symbol number indicating the section. -1 is used to flag
  212. ** symbols we're not interested in, yielding an unexpected error
  213. ** if we find any reloc entries referencing them.
  214. */
  215. coff_sym_listp =
  216. (struct syment *) mem_alloc (coff_header.f_nsyms * sizeof (struct syment));
  217. symbol_map = (int *) mem_alloc (coff_header.f_nsyms * sizeof *symbol_map);
  218. if (lseek (fd_in, coff_header.f_symptr, 0) < 0L)
  219. sys_error ("can't seek to COFF symbols");
  220. for (i = 0; i < coff_header.f_nsyms; ++i)
  221. {
  222. if (read (fd_in, coff_sym_listp + i, sizeof_syment) != sizeof_syment)
  223. error ("can't read COFF symbols");
  224. }
  225. symbol_count = 0;
  226. for (i = 0; i < coff_header.f_nsyms; ++i)
  227. {
  228. if (coff_sym_listp[i].n_scnum != N_DEBUG
  229. && coff_sym_listp[i].n_name[0] != '.')
  230. {
  231. if (verbose_flag)
  232. printf ("map %d to %d\n", i, symbol_count);
  233. symbol_map[i] = symbol_count++;
  234. }
  235. else
  236. {
  237. if (coff_sym_listp[i].n_sclass == C_STAT)
  238. {
  239. if (strcmp (coff_sym_listp[i].n_name, _TEXT) == 0)
  240. symbol_map[i] = -N_TEXT;
  241. else if (strcmp (coff_sym_listp[i].n_name, _DATA) == 0)
  242. symbol_map[i] = -N_DATA;
  243. else if (strcmp (coff_sym_listp[i].n_name, _BSS) == 0)
  244. symbol_map[i] = -N_BSS;
  245. else
  246. symbol_map[i] = -1;
  247. }
  248. else
  249. {
  250. symbol_map[i] = -1;
  251. }
  252. }
  253. /* skip auxillary entries */
  254. j = coff_sym_listp[i].n_numaux;
  255. if (j != 0)
  256. {
  257. if (j < 0)
  258. error ("invalid numaux");
  259. if (j != 1)
  260. fprintf (stderr, "unlikely numaux value\n");
  261. while (--j >= 0)
  262. ++i;
  263. }
  264. }
  265. /* now we know enough to write the output file header */
  266. bsd_header.a_magic = OMAGIC;
  267. bsd_header.a_text = coff_text_header.s_size;
  268. bsd_header.a_data = coff_data_header.s_size;
  269. bsd_header.a_bss = coff_bss_header.s_size;
  270. bsd_header.a_syms = symbol_count * sizeof (struct nlist);
  271. bsd_header.a_entry = 0;
  272. bsd_header.a_trsize = coff_text_header.s_nreloc * sizeof (struct relocation_info);
  273. bsd_header.a_drsize = coff_data_header.s_nreloc * sizeof (struct relocation_info);
  274. if (write (fd_out, &bsd_header, sizeof bsd_header) != sizeof bsd_header)
  275. sys_error ("can't write BSD header");
  276. /*
  277. ** Read in and save text and data sections - some data in
  278. ** these sections may need to be altered due to relocations.
  279. */
  280. text_and_data = (char *) mem_alloc (coff_text_header.s_size + coff_data_header.s_size);
  281. if (lseek (fd_in, coff_text_header.s_scnptr, 0) < 0L)
  282. sys_error ("can't seek to text section");
  283. if (read (fd_in, text_and_data, coff_text_header.s_size) != coff_text_header.s_size)
  284. error ("can't read text section");
  285. if (lseek (fd_in, coff_data_header.s_scnptr, 0) < 0L)
  286. sys_error ("can't seek to data section");
  287. if (read (fd_in, text_and_data + coff_text_header.s_size, coff_data_header.s_size) != coff_data_header.s_size)
  288. error ("can't read data section");
  289. /*
  290. ** Convert the relocation entries and do any text or data
  291. ** modifications necessary.
  292. */
  293. relocations = (char *) mem_alloc (bsd_header.a_trsize + bsd_header.a_drsize);
  294. reloc_segment (&coff_text_header, relocations);
  295. reloc_segment (&coff_data_header, relocations + bsd_header.a_trsize);
  296. if (write (fd_out, text_and_data, coff_text_header.s_size + coff_data_header.s_size)
  297. != coff_text_header.s_size + coff_data_header.s_size)
  298. sys_error ("can't write text and data sections");
  299. /* ZZ - are there any alignment considerations?? */
  300. if ((coff_text_header.s_size & 1) || (coff_data_header.s_size & 1))
  301. fprintf (stderr, "non-aligned text or data section\n");
  302. if (write (fd_out, relocations, bsd_header.a_trsize + bsd_header.a_drsize)
  303. != bsd_header.a_trsize + bsd_header.a_drsize)
  304. sys_error ("can't write relocation entries");
  305. /*
  306. ** Second pass thru the symbol table.
  307. ** a COFF symbol entry may contain up to 8 chars of symbol name
  308. ** in the entry itself - symbol names > 8 go into the string table,
  309. ** whereas the BSD entry puts all symbol names into the string
  310. ** table.
  311. */
  312. if (lseek (fd_in, coff_header.f_symptr + coff_header.f_nsyms * sizeof_syment, 0) < 0L)
  313. error ("can't seek to string table");
  314. i = read (fd_in, &string_table_len, sizeof string_table_len);
  315. if (i == sizeof string_table_len)
  316. {
  317. coff_string_table = mem_alloc (string_table_len);
  318. string_table_len -= sizeof string_table_len;
  319. i = read (fd_in, coff_string_table + sizeof string_table_len, string_table_len);
  320. if (i < 0)
  321. error ("can't read string table");
  322. if (i != string_table_len)
  323. error ("truncated string table - expected %d, got %d",
  324. string_table_len, i);
  325. }
  326. else
  327. {
  328. string_table_len = 0;
  329. }
  330. bsd_string_table = mem_alloc (string_table_len + coff_header.f_nsyms * (SYMNMLEN + 1));
  331. pc = bsd_string_table + sizeof string_table_len;
  332. for (i = 0; i < coff_header.f_nsyms; ++i)
  333. {
  334. if (coff_sym_listp[i].n_scnum != N_DEBUG
  335. && coff_sym_listp[i].n_name[0] != '.')
  336. {
  337. if (coff_sym_listp[i].n_zeroes == 0)
  338. {
  339. j = pc - bsd_string_table;
  340. #ifndef nounderscore
  341. if (coff_sym_listp[i].n_sclass == C_EXT
  342. || coff_sym_listp[i].n_sclass == C_STAT)
  343. *pc++ = '_';
  344. #endif
  345. pc2 = coff_string_table + coff_sym_listp[i].n_offset;
  346. while (*pc++ = *pc2++)
  347. /* null */ ;
  348. name.n_un.n_strx = j;
  349. }
  350. else
  351. {
  352. pc2 = &coff_sym_listp[i].n_name[0];
  353. j = pc - bsd_string_table;
  354. #ifndef nounderscore
  355. if (coff_sym_listp[i].n_sclass == C_EXT
  356. || coff_sym_listp[i].n_sclass == C_STAT)
  357. *pc++ = '_';
  358. #endif
  359. {
  360. int x;
  361. for (x = 0; x < SYMNMLEN; x++)
  362. {
  363. if (*pc2 == 0)
  364. break;
  365. *pc++ = *pc2++;
  366. }
  367. *pc++ = 0;
  368. }
  369. name.n_un.n_strx = j;
  370. }
  371. switch (coff_sym_listp[i].n_scnum)
  372. {
  373. case N_ABS:
  374. name.n_type = N_ABSOLUTE;
  375. break;
  376. case N_UNDEF:
  377. name.n_type = N_UNDF;
  378. break;
  379. default:
  380. if (coff_sym_listp[i].n_scnum == text_sect_num)
  381. name.n_type = N_TEXT;
  382. else if (coff_sym_listp[i].n_scnum == data_sect_num)
  383. name.n_type = N_DATA;
  384. else if (coff_sym_listp[i].n_scnum == bss_sect_num)
  385. name.n_type = N_BSS;
  386. break;
  387. }
  388. if (coff_sym_listp[i].n_sclass == C_EXT)
  389. name.n_type |= N_EXT;
  390. name.n_other = 0;
  391. name.n_desc = 0;
  392. name.n_value = coff_sym_listp[i].n_value;
  393. if (write (fd_out, &name, sizeof name) != sizeof name)
  394. sys_error ("can't write symbol");
  395. }
  396. /* skip auxillary entries */
  397. j = coff_sym_listp[i].n_numaux;
  398. if (j != 0)
  399. {
  400. while (--j >= 0)
  401. ++i;
  402. }
  403. }
  404. i = *((int *) bsd_string_table) = pc - bsd_string_table;
  405. if (write (fd_out, bsd_string_table, i) != i)
  406. error ("can't write string table");
  407. close (fd_in);
  408. close (fd_out);
  409. exit (0);
  410. }
  411. /*
  412. ** Convert the relocation entries and do any text or data
  413. ** modifications necessary.
  414. */
  415. static void
  416. reloc_segment (section_headerp, reloc_infop)
  417. struct scnhdr *section_headerp;
  418. struct relocation_info *reloc_infop;
  419. {
  420. struct reloc coff_reloc;
  421. int i;
  422. if (lseek (fd_in, section_headerp->s_relptr, 0) < 0L)
  423. error ("can't seek to relocation entries");
  424. for (i = 0; i < section_headerp->s_nreloc; ++i)
  425. {
  426. if (read (fd_in, &coff_reloc, sizeof_reloc) != sizeof_reloc)
  427. error ("can't read relocation entry");
  428. if (verbose_flag)
  429. printf ("vaddr = 0x%x, symndx = %d\n", coff_reloc.r_vaddr, coff_reloc.r_symndx);
  430. /*
  431. ** The reloc references a symbol declared common, thus the
  432. ** value of the symbol holds its size (in bytes). In COFF,
  433. ** apparently this info is also put into the binary -
  434. ** BSD doesn't like this, so we subtract it out.
  435. */
  436. if (coff_sym_listp[coff_reloc.r_symndx].n_scnum == N_UNDEF)
  437. {
  438. if (coff_sym_listp[coff_reloc.r_symndx].n_value != 0)
  439. {
  440. if (verbose_flag)
  441. printf ("adjust common 0x%x (%d)\n",
  442. coff_sym_listp[coff_reloc.r_symndx].n_value,
  443. coff_sym_listp[coff_reloc.r_symndx].n_value);
  444. switch (coff_reloc.r_type)
  445. {
  446. case R_RELBYTE:
  447. *((char *) (text_and_data + coff_reloc.r_vaddr))
  448. -= coff_sym_listp[coff_reloc.r_symndx].n_value;
  449. break;
  450. case R_RELWORD:
  451. *((short *) (text_and_data + coff_reloc.r_vaddr))
  452. -= coff_sym_listp[coff_reloc.r_symndx].n_value;
  453. break;
  454. case R_RELLONG:
  455. case R_DIR32: /* these are the only two that really show up */
  456. case R_PCRLONG:
  457. *((int *) (text_and_data + coff_reloc.r_vaddr))
  458. -= coff_sym_listp[coff_reloc.r_symndx].n_value;
  459. break;
  460. default:
  461. error ("unknown relocation type 0%o", coff_reloc.r_type);
  462. }
  463. }
  464. }
  465. /*
  466. ** >= 0 means its an extern - value is the output symbol #.
  467. ** < 0 means its an intern - value is N_TEXT, N_DATA or N_BSS.
  468. */
  469. if (symbol_map[coff_reloc.r_symndx] >= 0)
  470. {
  471. reloc_infop->r_symbolnum = symbol_map[coff_reloc.r_symndx];
  472. reloc_infop->r_extern = 1;
  473. }
  474. else
  475. {
  476. if (symbol_map[coff_reloc.r_symndx] == -1)
  477. error ("Oops! possible bug - reloc reference to ignored symbol");
  478. reloc_infop->r_symbolnum = -symbol_map[coff_reloc.r_symndx];
  479. reloc_infop->r_extern = 0;
  480. }
  481. /*
  482. ** COFF address includes the section address - BSD doesn't, so
  483. ** subtract it out.
  484. */
  485. reloc_infop->r_address = coff_reloc.r_vaddr - section_headerp->s_vaddr;
  486. switch (coff_reloc.r_type)
  487. {
  488. case R_PCRLONG:
  489. reloc_infop->r_pcrel = 1;
  490. reloc_infop->r_length = 2; /* 4 bytes */
  491. break;
  492. case R_DIR32:
  493. reloc_infop->r_pcrel = 0;
  494. reloc_infop->r_length = 2;
  495. break;
  496. default:
  497. error ("can't handle coff reloction type 0%o", coff_reloc.r_type);
  498. }
  499. if (verbose_flag)
  500. printf ("reloc: addr = 0x%x, synum = %d\n",
  501. reloc_infop->r_address, reloc_infop->r_symbolnum);
  502. reloc_infop->r_pad = 0;
  503. ++reloc_infop;
  504. }
  505. }
  506. void
  507. error (format, va_alist)
  508. char *format;
  509. va_dcl
  510. {
  511. va_list args;
  512. va_start (args);
  513. fprintf (stderr, "robotussin: ");
  514. vfprintf (stderr, format, args);
  515. putc ('\n', stderr);
  516. va_end (args);
  517. exit (1);
  518. }
  519. extern char *sys_errlist[];
  520. extern int errno;
  521. void
  522. sys_error (format, va_alist)
  523. char *format;
  524. va_dcl
  525. {
  526. va_list args;
  527. va_start (args);
  528. fprintf (stderr, "robotussin: ");
  529. vfprintf (stderr, format, args);
  530. fprintf (stderr, ": %s\n", sys_errlist[errno]);
  531. va_end (args);
  532. exit (1);
  533. }
  534. extern char *malloc ();
  535. char *
  536. mem_alloc (size)
  537. int size;
  538. {
  539. char *pc;
  540. if ((pc = malloc (size)) == NULL)
  541. error ("memory exhausted!");
  542. return pc;
  543. }
  544. /* end */