versados.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /* BFD back-end for VERSAdos-E objects.
  2. Copyright (C) 1995-2015 Free Software Foundation, Inc.
  3. Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
  4. Versados is a Motorola trademark.
  5. This file is part of BFD, the Binary File Descriptor library.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. /*
  19. SUBSECTION
  20. VERSAdos-E relocatable object file format
  21. DESCRIPTION
  22. This module supports reading of VERSAdos relocatable
  23. object files.
  24. A VERSAdos file looks like contains
  25. o Identification Record
  26. o External Symbol Definition Record
  27. o Object Text Record
  28. o End Record. */
  29. #include "sysdep.h"
  30. #include "bfd.h"
  31. #include "libbfd.h"
  32. #include "libiberty.h"
  33. #define VHEADER '1'
  34. #define VESTDEF '2'
  35. #define VOTR '3'
  36. #define VEND '4'
  37. #define ES_BASE 17 /* First symbol has esdid 17. */
  38. /* Per file target dependent information. */
  39. /* One for each section. */
  40. struct esdid
  41. {
  42. asection *section; /* Ptr to bfd version. */
  43. unsigned char *contents; /* Used to build image. */
  44. bfd_size_type content_size; /* The size of the contents buffer. */
  45. int pc;
  46. int relocs; /* Reloc count, valid end of pass 1. */
  47. int donerel; /* Have relocs been translated. */
  48. };
  49. typedef struct versados_data_struct
  50. {
  51. int es_done; /* Count of symbol index, starts at ES_BASE. */
  52. asymbol *symbols; /* Pointer to local symbols. */
  53. char *strings; /* Strings of all the above. */
  54. int stringlen; /* Len of string table (valid end of pass1). */
  55. int nsecsyms; /* Number of sections. */
  56. int ndefs; /* Number of exported symbols (they dont get esdids). */
  57. int nrefs; /* Number of imported symbols (valid end of pass1). */
  58. int ref_idx; /* Current processed value of the above. */
  59. int def_idx;
  60. int pass_2_done;
  61. struct esdid e[16]; /* Per section info. */
  62. int alert; /* To see if we're trampling. */
  63. asymbol *rest[256 - 16]; /* Per symbol info. */
  64. }
  65. tdata_type;
  66. #define VDATA(abfd) (abfd->tdata.versados_data)
  67. #define EDATA(abfd, n) (abfd->tdata.versados_data->e[(n) < 16 ? (n) : 0])
  68. #define RDATA(abfd, n) (abfd->tdata.versados_data->rest[(n) < 240 ? (n) : 0])
  69. struct ext_otr
  70. {
  71. unsigned char size;
  72. char type;
  73. unsigned char map[4];
  74. unsigned char esdid;
  75. unsigned char data[200];
  76. };
  77. struct ext_vheader
  78. {
  79. unsigned char size;
  80. char type; /* Record type. */
  81. char name[10]; /* Module name. */
  82. char rev; /* Module rev number. */
  83. char lang;
  84. char vol[4];
  85. char user[2];
  86. char cat[8];
  87. char fname[8];
  88. char ext[2];
  89. char time[3];
  90. char date[3];
  91. char rest[211];
  92. };
  93. struct ext_esd
  94. {
  95. unsigned char size;
  96. char type;
  97. unsigned char esd_entries[1];
  98. };
  99. #define ESD_ABS 0
  100. #define ESD_COMMON 1
  101. #define ESD_STD_REL_SEC 2
  102. #define ESD_SHRT_REL_SEC 3
  103. #define ESD_XDEF_IN_SEC 4
  104. #define ESD_XDEF_IN_ABS 5
  105. #define ESD_XREF_SEC 6
  106. #define ESD_XREF_SYM 7
  107. union ext_any
  108. {
  109. unsigned char size;
  110. struct ext_vheader header;
  111. struct ext_esd esd;
  112. struct ext_otr otr;
  113. };
  114. /* Initialize by filling in the hex conversion array. */
  115. /* Set up the tdata information. */
  116. static bfd_boolean
  117. versados_mkobject (bfd *abfd)
  118. {
  119. if (abfd->tdata.versados_data == NULL)
  120. {
  121. bfd_size_type amt = sizeof (tdata_type);
  122. tdata_type *tdata = bfd_alloc (abfd, amt);
  123. if (tdata == NULL)
  124. return FALSE;
  125. abfd->tdata.versados_data = tdata;
  126. tdata->symbols = NULL;
  127. VDATA (abfd)->alert = 0x12345678;
  128. }
  129. bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0);
  130. return TRUE;
  131. }
  132. /* Report a problem in an S record file. FIXME: This probably should
  133. not call fprintf, but we really do need some mechanism for printing
  134. error messages. */
  135. static asymbol *
  136. versados_new_symbol (bfd *abfd,
  137. int snum,
  138. const char *name,
  139. bfd_vma val,
  140. asection *sec)
  141. {
  142. asymbol *n = VDATA (abfd)->symbols + snum;
  143. n->name = name;
  144. n->value = val;
  145. n->section = sec;
  146. n->the_bfd = abfd;
  147. n->flags = 0;
  148. return n;
  149. }
  150. static bfd_boolean
  151. get_record (bfd *abfd, union ext_any *ptr)
  152. {
  153. if (bfd_bread (&ptr->size, (bfd_size_type) 1, abfd) != 1
  154. || (bfd_bread ((char *) ptr + 1, (bfd_size_type) ptr->size, abfd)
  155. != ptr->size))
  156. return FALSE;
  157. {
  158. bfd_size_type amt = ptr->size + 1;
  159. if (amt < sizeof (* ptr))
  160. memset ((char *) ptr + amt, 0, sizeof (* ptr) - amt);
  161. }
  162. return TRUE;
  163. }
  164. static int
  165. get_4 (unsigned char **pp)
  166. {
  167. unsigned char *p = *pp;
  168. *pp += 4;
  169. return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0);
  170. }
  171. static void
  172. get_10 (unsigned char **pp, char *name)
  173. {
  174. char *p = (char *) *pp;
  175. int len = 10;
  176. *pp += len;
  177. while (*p != ' ' && len)
  178. {
  179. *name++ = *p++;
  180. len--;
  181. }
  182. *name = 0;
  183. }
  184. static char *
  185. new_symbol_string (bfd *abfd, const char *name)
  186. {
  187. char *n = VDATA (abfd)->strings;
  188. strcpy (VDATA (abfd)->strings, name);
  189. VDATA (abfd)->strings += strlen (VDATA (abfd)->strings) + 1;
  190. return n;
  191. }
  192. static void
  193. process_esd (bfd *abfd, struct ext_esd *esd, int pass)
  194. {
  195. /* Read through the ext def for the est entries. */
  196. int togo = esd->size - 2;
  197. bfd_vma size;
  198. bfd_vma start;
  199. asection *sec;
  200. char name[11];
  201. unsigned char *ptr = esd->esd_entries;
  202. unsigned char *end = ptr + togo;
  203. while (ptr < end)
  204. {
  205. int scn = *ptr & 0xf;
  206. int typ = (*ptr >> 4) & 0xf;
  207. /* Declare this section. */
  208. sprintf (name, "%d", scn);
  209. sec = bfd_make_section_old_way (abfd, strdup (name));
  210. sec->target_index = scn;
  211. EDATA (abfd, scn).section = sec;
  212. ptr++;
  213. switch (typ)
  214. {
  215. default:
  216. abort ();
  217. case ESD_XREF_SEC:
  218. case ESD_XREF_SYM:
  219. {
  220. int snum = VDATA (abfd)->ref_idx++;
  221. get_10 (&ptr, name);
  222. if (pass == 1)
  223. VDATA (abfd)->stringlen += strlen (name) + 1;
  224. else
  225. {
  226. int esidx;
  227. asymbol *s;
  228. char *n = new_symbol_string (abfd, name);
  229. s = versados_new_symbol (abfd, snum, n, (bfd_vma) 0,
  230. bfd_und_section_ptr);
  231. esidx = VDATA (abfd)->es_done++;
  232. RDATA (abfd, esidx - ES_BASE) = s;
  233. }
  234. }
  235. break;
  236. case ESD_ABS:
  237. size = get_4 (&ptr);
  238. (void) size;
  239. start = get_4 (&ptr);
  240. (void) start;
  241. break;
  242. case ESD_STD_REL_SEC:
  243. case ESD_SHRT_REL_SEC:
  244. sec->size = get_4 (&ptr);
  245. sec->flags |= SEC_ALLOC;
  246. break;
  247. case ESD_XDEF_IN_ABS:
  248. sec = bfd_abs_section_ptr;
  249. case ESD_XDEF_IN_SEC:
  250. {
  251. int snum = VDATA (abfd)->def_idx++;
  252. bfd_vma val;
  253. get_10 (&ptr, name);
  254. val = get_4 (&ptr);
  255. if (pass == 1)
  256. /* Just remember the symbol. */
  257. VDATA (abfd)->stringlen += strlen (name) + 1;
  258. else
  259. {
  260. asymbol *s;
  261. char *n = new_symbol_string (abfd, name);
  262. s = versados_new_symbol (abfd, snum + VDATA (abfd)->nrefs, n,
  263. val, sec);
  264. s->flags |= BSF_GLOBAL;
  265. }
  266. }
  267. break;
  268. }
  269. }
  270. }
  271. #define R_RELWORD 1
  272. #define R_RELLONG 2
  273. #define R_RELWORD_NEG 3
  274. #define R_RELLONG_NEG 4
  275. reloc_howto_type versados_howto_table[] =
  276. {
  277. HOWTO (R_RELWORD, 0, 1, 16, FALSE,
  278. 0, complain_overflow_dont, 0,
  279. "+v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
  280. HOWTO (R_RELLONG, 0, 2, 32, FALSE,
  281. 0, complain_overflow_dont, 0,
  282. "+v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
  283. HOWTO (R_RELWORD_NEG, 0, -1, 16, FALSE,
  284. 0, complain_overflow_dont, 0,
  285. "-v16", TRUE, 0x0000ffff, 0x0000ffff, FALSE),
  286. HOWTO (R_RELLONG_NEG, 0, -2, 32, FALSE,
  287. 0, complain_overflow_dont, 0,
  288. "-v32", TRUE, 0xffffffff, 0xffffffff, FALSE),
  289. };
  290. static int
  291. get_offset (int len, unsigned char *ptr)
  292. {
  293. int val = 0;
  294. if (len)
  295. {
  296. int i;
  297. val = *ptr++;
  298. if (val & 0x80)
  299. val |= ~0xff;
  300. for (i = 1; i < len; i++)
  301. val = (val << 8) | *ptr++;
  302. }
  303. return val;
  304. }
  305. static void
  306. process_otr (bfd *abfd, struct ext_otr *otr, int pass)
  307. {
  308. unsigned long shift;
  309. unsigned char *srcp = otr->data;
  310. unsigned char *endp = (unsigned char *) otr + otr->size;
  311. unsigned int bits = (otr->map[0] << 24)
  312. | (otr->map[1] << 16)
  313. | (otr->map[2] << 8)
  314. | (otr->map[3] << 0);
  315. struct esdid *esdid;
  316. unsigned char *contents;
  317. bfd_boolean need_contents = FALSE;
  318. unsigned int dst_idx;
  319. /* PR 17512: file: ac7da425. */
  320. if (otr->esdid == 0)
  321. return;
  322. esdid = &EDATA (abfd, otr->esdid - 1);
  323. contents = esdid->contents;
  324. dst_idx = esdid->pc;
  325. for (shift = ((unsigned long) 1 << 31); shift && srcp < endp; shift >>= 1)
  326. {
  327. if (bits & shift)
  328. {
  329. int flag = *srcp++;
  330. int esdids = (flag >> 5) & 0x7;
  331. int sizeinwords = ((flag >> 3) & 1) ? 2 : 1;
  332. int offsetlen = flag & 0x7;
  333. int j;
  334. if (esdids == 0)
  335. {
  336. /* A zero esdid means the new pc is the offset given. */
  337. dst_idx += get_offset (offsetlen, srcp);
  338. srcp += offsetlen;
  339. }
  340. else
  341. {
  342. int val = get_offset (offsetlen, srcp + esdids);
  343. if (pass == 1)
  344. need_contents = TRUE;
  345. else if (contents && dst_idx < esdid->content_size - sizeinwords * 2)
  346. for (j = 0; j < sizeinwords * 2; j++)
  347. {
  348. contents[dst_idx + (sizeinwords * 2) - j - 1] = val;
  349. val >>= 8;
  350. }
  351. for (j = 0; j < esdids; j++)
  352. {
  353. int id = *srcp++;
  354. if (id)
  355. {
  356. int rn = EDATA (abfd, otr->esdid - 1).relocs++;
  357. if (pass == 1)
  358. {
  359. /* This is the first pass over the data,
  360. just remember that we need a reloc. */
  361. }
  362. else
  363. {
  364. arelent *n;
  365. /* PR 17512: file: 54f733e0. */
  366. if (EDATA (abfd, otr->esdid - 1).section == NULL)
  367. continue;
  368. n = EDATA (abfd, otr->esdid - 1).section->relocation + rn;
  369. n->address = dst_idx;
  370. n->sym_ptr_ptr = (asymbol **) (size_t) id;
  371. n->addend = 0;
  372. n->howto = versados_howto_table + ((j & 1) * 2) + (sizeinwords - 1);
  373. }
  374. }
  375. }
  376. srcp += offsetlen;
  377. dst_idx += sizeinwords * 2;
  378. }
  379. }
  380. else
  381. {
  382. need_contents = TRUE;
  383. if (esdid->section && contents && dst_idx < esdid->content_size - 1)
  384. if (pass == 2)
  385. {
  386. /* Absolute code, comes in 16 bit lumps. */
  387. contents[dst_idx] = srcp[0];
  388. contents[dst_idx + 1] = srcp[1];
  389. }
  390. dst_idx += 2;
  391. srcp += 2;
  392. }
  393. }
  394. EDATA (abfd, otr->esdid - 1).pc = dst_idx;
  395. if (!contents && need_contents)
  396. {
  397. if (esdid->section)
  398. {
  399. bfd_size_type size;
  400. size = esdid->section->size;
  401. esdid->contents = bfd_alloc (abfd, size);
  402. esdid->content_size = size;
  403. }
  404. else
  405. esdid->contents = NULL;
  406. }
  407. }
  408. static bfd_boolean
  409. versados_scan (bfd *abfd)
  410. {
  411. bfd_boolean loop = TRUE;
  412. int i;
  413. int j;
  414. int nsecs = 0;
  415. bfd_size_type amt;
  416. VDATA (abfd)->stringlen = 0;
  417. VDATA (abfd)->nrefs = 0;
  418. VDATA (abfd)->ndefs = 0;
  419. VDATA (abfd)->ref_idx = 0;
  420. VDATA (abfd)->def_idx = 0;
  421. VDATA (abfd)->pass_2_done = 0;
  422. while (loop)
  423. {
  424. union ext_any any;
  425. if (!get_record (abfd, &any))
  426. return FALSE;
  427. switch (any.header.type)
  428. {
  429. case VHEADER:
  430. break;
  431. case VEND:
  432. loop = FALSE;
  433. break;
  434. case VESTDEF:
  435. process_esd (abfd, &any.esd, 1);
  436. break;
  437. case VOTR:
  438. process_otr (abfd, &any.otr, 1);
  439. break;
  440. }
  441. }
  442. /* Now allocate space for the relocs and sections. */
  443. VDATA (abfd)->nrefs = VDATA (abfd)->ref_idx;
  444. VDATA (abfd)->ndefs = VDATA (abfd)->def_idx;
  445. VDATA (abfd)->ref_idx = 0;
  446. VDATA (abfd)->def_idx = 0;
  447. abfd->symcount = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs;
  448. for (i = 0; i < 16; i++)
  449. {
  450. struct esdid *esdid = &EDATA (abfd, i);
  451. if (esdid->section)
  452. {
  453. amt = (bfd_size_type) esdid->relocs * sizeof (arelent);
  454. esdid->section->relocation = bfd_alloc (abfd, amt);
  455. esdid->pc = 0;
  456. if (esdid->contents)
  457. esdid->section->flags |= SEC_HAS_CONTENTS | SEC_LOAD;
  458. esdid->section->reloc_count = esdid->relocs;
  459. if (esdid->relocs)
  460. esdid->section->flags |= SEC_RELOC;
  461. esdid->relocs = 0;
  462. /* Add an entry into the symbol table for it. */
  463. nsecs++;
  464. VDATA (abfd)->stringlen += strlen (esdid->section->name) + 1;
  465. }
  466. }
  467. abfd->symcount += nsecs;
  468. amt = abfd->symcount;
  469. amt *= sizeof (asymbol);
  470. VDATA (abfd)->symbols = bfd_alloc (abfd, amt);
  471. amt = VDATA (abfd)->stringlen;
  472. VDATA (abfd)->strings = bfd_alloc (abfd, amt);
  473. if ((VDATA (abfd)->symbols == NULL && abfd->symcount > 0)
  474. || (VDATA (abfd)->strings == NULL && VDATA (abfd)->stringlen > 0))
  475. return FALSE;
  476. /* Actually fill in the section symbols,
  477. we stick them at the end of the table. */
  478. for (j = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs, i = 0; i < 16; i++)
  479. {
  480. struct esdid *esdid = &EDATA (abfd, i);
  481. asection *sec = esdid->section;
  482. if (sec)
  483. {
  484. asymbol *s = VDATA (abfd)->symbols + j;
  485. s->name = new_symbol_string (abfd, sec->name);
  486. s->section = sec;
  487. s->flags = BSF_LOCAL;
  488. s->value = 0;
  489. s->the_bfd = abfd;
  490. j++;
  491. }
  492. }
  493. if (abfd->symcount)
  494. abfd->flags |= HAS_SYMS;
  495. /* Set this to nsecs - since we've already planted the section
  496. symbols. */
  497. VDATA (abfd)->nsecsyms = nsecs;
  498. VDATA (abfd)->ref_idx = 0;
  499. return TRUE;
  500. }
  501. /* Check whether an existing file is a versados file. */
  502. static const bfd_target *
  503. versados_object_p (bfd *abfd)
  504. {
  505. struct ext_vheader ext;
  506. unsigned char len;
  507. tdata_type *tdata_save;
  508. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  509. return NULL;
  510. if (bfd_bread (&len, (bfd_size_type) 1, abfd) != 1)
  511. {
  512. if (bfd_get_error () != bfd_error_system_call)
  513. bfd_set_error (bfd_error_wrong_format);
  514. return NULL;
  515. }
  516. /* PR 17512: file: 726-2128-0.004. */
  517. if (len < 13)
  518. {
  519. bfd_set_error (bfd_error_wrong_format);
  520. return NULL;
  521. }
  522. if (bfd_bread (&ext.type, (bfd_size_type) len, abfd) != len)
  523. {
  524. if (bfd_get_error () != bfd_error_system_call)
  525. bfd_set_error (bfd_error_wrong_format);
  526. return NULL;
  527. }
  528. /* We guess that the language field will never be larger than 10.
  529. In sample files, it is always either 0 or 1. Checking for this
  530. prevents confusion with Intel Hex files. */
  531. if (ext.type != VHEADER
  532. || ext.lang > 10)
  533. {
  534. bfd_set_error (bfd_error_wrong_format);
  535. return NULL;
  536. }
  537. /* OK, looks like a record, build the tdata and read in. */
  538. tdata_save = abfd->tdata.versados_data;
  539. if (!versados_mkobject (abfd) || !versados_scan (abfd))
  540. {
  541. abfd->tdata.versados_data = tdata_save;
  542. return NULL;
  543. }
  544. return abfd->xvec;
  545. }
  546. static bfd_boolean
  547. versados_pass_2 (bfd *abfd)
  548. {
  549. union ext_any any;
  550. if (VDATA (abfd)->pass_2_done)
  551. return 1;
  552. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  553. return 0;
  554. VDATA (abfd)->es_done = ES_BASE;
  555. /* Read records till we get to where we want to be. */
  556. while (1)
  557. {
  558. get_record (abfd, &any);
  559. switch (any.header.type)
  560. {
  561. case VEND:
  562. VDATA (abfd)->pass_2_done = 1;
  563. return 1;
  564. case VESTDEF:
  565. process_esd (abfd, &any.esd, 2);
  566. break;
  567. case VOTR:
  568. process_otr (abfd, &any.otr, 2);
  569. break;
  570. }
  571. }
  572. }
  573. static bfd_boolean
  574. versados_get_section_contents (bfd *abfd,
  575. asection *section,
  576. void * location,
  577. file_ptr offset,
  578. bfd_size_type count)
  579. {
  580. struct esdid *esdid;
  581. if (!versados_pass_2 (abfd))
  582. return FALSE;
  583. esdid = &EDATA (abfd, section->target_index);
  584. if (esdid->contents == NULL
  585. || offset < 0
  586. || (bfd_size_type) offset > esdid->content_size
  587. || offset + count > esdid->content_size)
  588. return FALSE;
  589. memcpy (location, esdid->contents + offset, (size_t) count);
  590. return TRUE;
  591. }
  592. #define versados_get_section_contents_in_window \
  593. _bfd_generic_get_section_contents_in_window
  594. static bfd_boolean
  595. versados_set_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
  596. sec_ptr section ATTRIBUTE_UNUSED,
  597. const void * location ATTRIBUTE_UNUSED,
  598. file_ptr offset ATTRIBUTE_UNUSED,
  599. bfd_size_type bytes_to_do ATTRIBUTE_UNUSED)
  600. {
  601. return FALSE;
  602. }
  603. static int
  604. versados_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
  605. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  606. {
  607. return 0;
  608. }
  609. /* Return the amount of memory needed to read the symbol table. */
  610. static long
  611. versados_get_symtab_upper_bound (bfd *abfd)
  612. {
  613. return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *);
  614. }
  615. /* Return the symbol table. */
  616. static long
  617. versados_canonicalize_symtab (bfd *abfd, asymbol **alocation)
  618. {
  619. unsigned int symcount = bfd_get_symcount (abfd);
  620. unsigned int i;
  621. asymbol *s;
  622. versados_pass_2 (abfd);
  623. for (i = 0, s = VDATA (abfd)->symbols;
  624. i < symcount;
  625. s++, i++)
  626. *alocation++ = s;
  627. *alocation = NULL;
  628. return symcount;
  629. }
  630. static void
  631. versados_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
  632. asymbol *symbol,
  633. symbol_info *ret)
  634. {
  635. bfd_symbol_info (symbol, ret);
  636. }
  637. static void
  638. versados_print_symbol (bfd *abfd,
  639. void * afile,
  640. asymbol *symbol,
  641. bfd_print_symbol_type how)
  642. {
  643. FILE *file = (FILE *) afile;
  644. switch (how)
  645. {
  646. case bfd_print_symbol_name:
  647. fprintf (file, "%s", symbol->name);
  648. break;
  649. default:
  650. bfd_print_symbol_vandf (abfd, (void *) file, symbol);
  651. fprintf (file, " %-5s %s",
  652. symbol->section->name,
  653. symbol->name);
  654. }
  655. }
  656. static long
  657. versados_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
  658. sec_ptr asect)
  659. {
  660. return (asect->reloc_count + 1) * sizeof (arelent *);
  661. }
  662. static long
  663. versados_canonicalize_reloc (bfd *abfd,
  664. sec_ptr section,
  665. arelent **relptr,
  666. asymbol **symbols)
  667. {
  668. unsigned int count;
  669. arelent *src;
  670. versados_pass_2 (abfd);
  671. src = section->relocation;
  672. if (!EDATA (abfd, section->target_index).donerel)
  673. {
  674. EDATA (abfd, section->target_index).donerel = 1;
  675. /* Translate from indexes to symptr ptrs. */
  676. for (count = 0; count < section->reloc_count; count++)
  677. {
  678. int esdid = (int) (size_t) src[count].sym_ptr_ptr;
  679. if (esdid == 0)
  680. src[count].sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  681. else if (esdid < ES_BASE)
  682. {
  683. /* Section relative thing. */
  684. struct esdid *e = &EDATA (abfd, esdid - 1);
  685. /* PR 17512: file:cd92277c. */
  686. if (e->section)
  687. src[count].sym_ptr_ptr = e->section->symbol_ptr_ptr;
  688. else
  689. src[count].sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr;
  690. }
  691. /* PR 17512: file:3757-2936-0.004. */
  692. else if ((unsigned) (esdid - ES_BASE) >= bfd_get_symcount (abfd))
  693. src[count].sym_ptr_ptr = bfd_und_section_ptr->symbol_ptr_ptr;
  694. else
  695. src[count].sym_ptr_ptr = symbols + esdid - ES_BASE;
  696. }
  697. }
  698. for (count = 0; count < section->reloc_count; count++)
  699. *relptr++ = src++;
  700. *relptr = 0;
  701. return section->reloc_count;
  702. }
  703. #define versados_close_and_cleanup _bfd_generic_close_and_cleanup
  704. #define versados_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  705. #define versados_new_section_hook _bfd_generic_new_section_hook
  706. #define versados_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  707. #define versados_bfd_is_local_label_name bfd_generic_is_local_label_name
  708. #define versados_get_lineno _bfd_nosymbols_get_lineno
  709. #define versados_find_nearest_line _bfd_nosymbols_find_nearest_line
  710. #define versados_find_line _bfd_nosymbols_find_line
  711. #define versados_find_inliner_info _bfd_nosymbols_find_inliner_info
  712. #define versados_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string
  713. #define versados_make_empty_symbol _bfd_generic_make_empty_symbol
  714. #define versados_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  715. #define versados_read_minisymbols _bfd_generic_read_minisymbols
  716. #define versados_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
  717. #define versados_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
  718. #define versados_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
  719. #define versados_set_arch_mach bfd_default_set_arch_mach
  720. #define versados_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  721. #define versados_bfd_relax_section bfd_generic_relax_section
  722. #define versados_bfd_gc_sections bfd_generic_gc_sections
  723. #define versados_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  724. #define versados_bfd_merge_sections bfd_generic_merge_sections
  725. #define versados_bfd_is_group_section bfd_generic_is_group_section
  726. #define versados_bfd_discard_group bfd_generic_discard_group
  727. #define versados_section_already_linked _bfd_generic_section_already_linked
  728. #define versados_bfd_define_common_symbol bfd_generic_define_common_symbol
  729. #define versados_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  730. #define versados_bfd_link_add_symbols _bfd_generic_link_add_symbols
  731. #define versados_bfd_link_just_syms _bfd_generic_link_just_syms
  732. #define versados_bfd_copy_link_hash_symbol_type \
  733. _bfd_generic_copy_link_hash_symbol_type
  734. #define versados_bfd_final_link _bfd_generic_final_link
  735. #define versados_bfd_link_split_section _bfd_generic_link_split_section
  736. const bfd_target m68k_versados_vec =
  737. {
  738. "versados", /* Name. */
  739. bfd_target_versados_flavour,
  740. BFD_ENDIAN_BIG, /* Target byte order. */
  741. BFD_ENDIAN_BIG, /* Target headers byte order. */
  742. (HAS_RELOC | EXEC_P | /* Object flags. */
  743. HAS_LINENO | HAS_DEBUG |
  744. HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  745. (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
  746. | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
  747. 0, /* Leading underscore. */
  748. ' ', /* AR_pad_char. */
  749. 16, /* AR_max_namelen. */
  750. 0, /* match priority. */
  751. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  752. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  753. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
  754. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  755. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  756. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
  757. {
  758. _bfd_dummy_target,
  759. versados_object_p, /* bfd_check_format. */
  760. _bfd_dummy_target,
  761. _bfd_dummy_target,
  762. },
  763. {
  764. bfd_false,
  765. versados_mkobject,
  766. _bfd_generic_mkarchive,
  767. bfd_false,
  768. },
  769. { /* bfd_write_contents. */
  770. bfd_false,
  771. bfd_false,
  772. _bfd_write_archive_contents,
  773. bfd_false,
  774. },
  775. BFD_JUMP_TABLE_GENERIC (versados),
  776. BFD_JUMP_TABLE_COPY (_bfd_generic),
  777. BFD_JUMP_TABLE_CORE (_bfd_nocore),
  778. BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  779. BFD_JUMP_TABLE_SYMBOLS (versados),
  780. BFD_JUMP_TABLE_RELOCS (versados),
  781. BFD_JUMP_TABLE_WRITE (versados),
  782. BFD_JUMP_TABLE_LINK (versados),
  783. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  784. NULL,
  785. NULL
  786. };