m68klinux.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /* BFD back-end for linux flavored m68k a.out binaries.
  2. Copyright (C) 1992-2015 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #define TARGET_PAGE_SIZE 4096
  17. #define ZMAGIC_DISK_BLOCK_SIZE 1024
  18. #define SEGMENT_SIZE TARGET_PAGE_SIZE
  19. #define TEXT_START_ADDR 0x0
  20. #define MACHTYPE_OK(mtype) ((mtype) == M_68020 || (mtype) == M_UNKNOWN)
  21. #include "sysdep.h"
  22. #include "bfd.h"
  23. #include "libbfd.h"
  24. #include "aout/aout64.h"
  25. #include "aout/stab_gnu.h"
  26. #include "aout/ar.h"
  27. #include "libaout.h" /* BFD a.out internal data structures */
  28. #define TARGET_IS_BIG_ENDIAN_P
  29. #define DEFAULT_ARCH bfd_arch_m68k
  30. /* Do not "beautify" the CONCAT* macro args. Traditional C will not
  31. remove whitespace added here, and thus will fail to concatenate
  32. the tokens. */
  33. #define MY(OP) CONCAT2 (m68k_aout_linux_,OP)
  34. #define TARGETNAME "a.out-m68k-linux"
  35. extern const bfd_target MY(vec);
  36. /* We always generate QMAGIC files in preference to ZMAGIC files. It
  37. would be possible to make this a linker option, if that ever
  38. becomes important. */
  39. static void MY_final_link_callback
  40. (bfd *, file_ptr *, file_ptr *, file_ptr *);
  41. static bfd_boolean
  42. m68klinux_bfd_final_link (bfd *abfd,
  43. struct bfd_link_info *info)
  44. {
  45. obj_aout_subformat (abfd) = q_magic_format;
  46. return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
  47. }
  48. #define MY_bfd_final_link m68klinux_bfd_final_link
  49. /* Set the machine type correctly. */
  50. static bfd_boolean
  51. m68klinux_write_object_contents (bfd *abfd)
  52. {
  53. struct external_exec exec_bytes;
  54. struct internal_exec *execp = exec_hdr (abfd);
  55. N_SET_MACHTYPE (*execp, M_68020);
  56. obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  57. WRITE_HEADERS(abfd, execp);
  58. return TRUE;
  59. }
  60. #define MY_write_object_contents m68klinux_write_object_contents
  61. /* Code to link against Linux a.out shared libraries. */
  62. /* See if a symbol name is a reference to the global offset table. */
  63. #ifndef GOT_REF_PREFIX
  64. #define GOT_REF_PREFIX "__GOT_"
  65. #endif
  66. #define IS_GOT_SYM(name) (CONST_STRNEQ (name, GOT_REF_PREFIX))
  67. /* See if a symbol name is a reference to the procedure linkage table. */
  68. #ifndef PLT_REF_PREFIX
  69. #define PLT_REF_PREFIX "__PLT_"
  70. #endif
  71. #define IS_PLT_SYM(name) (CONST_STRNEQ (name, PLT_REF_PREFIX))
  72. /* This string is used to generate specialized error messages. */
  73. #ifndef NEEDS_SHRLIB
  74. #define NEEDS_SHRLIB "__NEEDS_SHRLIB_"
  75. #endif
  76. /* This special symbol is a set vector that contains a list of
  77. pointers to fixup tables. It will be present in any dynamically
  78. linked file. The linker generated fixup table should also be added
  79. to the list, and it should always appear in the second slot (the
  80. first one is a dummy with a magic number that is defined in
  81. crt0.o). */
  82. #ifndef SHARABLE_CONFLICTS
  83. #define SHARABLE_CONFLICTS "__SHARABLE_CONFLICTS__"
  84. #endif
  85. /* We keep a list of fixups. The terminology is a bit strange, but
  86. each fixup contains two 32 bit numbers. A regular fixup contains
  87. an address and a pointer, and at runtime we should store the
  88. address at the location pointed to by the pointer. A builtin fixup
  89. contains two pointers, and we should read the address using one
  90. pointer and store it at the location pointed to by the other
  91. pointer. Builtin fixups come into play when we have duplicate
  92. __GOT__ symbols for the same variable. The builtin fixup will copy
  93. the GOT pointer from one over into the other. */
  94. struct fixup
  95. {
  96. struct fixup *next;
  97. struct linux_link_hash_entry *h;
  98. bfd_vma value;
  99. /* Nonzero if this is a jump instruction that needs to be fixed,
  100. zero if this is just a pointer */
  101. char jump;
  102. char builtin;
  103. };
  104. /* We don't need a special hash table entry structure, but we do need
  105. to keep some information between linker passes, so we use a special
  106. hash table. */
  107. struct linux_link_hash_entry
  108. {
  109. struct aout_link_hash_entry root;
  110. };
  111. struct linux_link_hash_table
  112. {
  113. struct aout_link_hash_table root;
  114. /* First dynamic object found in link. */
  115. bfd *dynobj;
  116. /* Number of fixups. */
  117. size_t fixup_count;
  118. /* Number of builtin fixups. */
  119. size_t local_builtins;
  120. /* List of fixups. */
  121. struct fixup *fixup_list;
  122. };
  123. /* Routine to create an entry in an Linux link hash table. */
  124. static struct bfd_hash_entry *
  125. linux_link_hash_newfunc (struct bfd_hash_entry *entry,
  126. struct bfd_hash_table *table,
  127. const char *string)
  128. {
  129. struct linux_link_hash_entry *ret = (struct linux_link_hash_entry *) entry;
  130. /* Allocate the structure if it has not already been allocated by a
  131. subclass. */
  132. if (ret == (struct linux_link_hash_entry *) NULL)
  133. ret = ((struct linux_link_hash_entry *)
  134. bfd_hash_allocate (table, sizeof (struct linux_link_hash_entry)));
  135. if (ret == NULL)
  136. return (struct bfd_hash_entry *) ret;
  137. /* Call the allocation method of the superclass. */
  138. ret = ((struct linux_link_hash_entry *)
  139. NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
  140. table, string));
  141. if (ret != NULL)
  142. {
  143. /* Set local fields; there aren't any. */
  144. }
  145. return (struct bfd_hash_entry *) ret;
  146. }
  147. /* Create a Linux link hash table. */
  148. static struct bfd_link_hash_table *
  149. linux_link_hash_table_create (bfd *abfd)
  150. {
  151. struct linux_link_hash_table *ret;
  152. bfd_size_type amt = sizeof (struct linux_link_hash_table);
  153. ret = (struct linux_link_hash_table *) bfd_zmalloc (amt);
  154. if (ret == (struct linux_link_hash_table *) NULL)
  155. {
  156. bfd_set_error (bfd_error_no_memory);
  157. return (struct bfd_link_hash_table *) NULL;
  158. }
  159. if (!NAME(aout,link_hash_table_init) (&ret->root, abfd,
  160. linux_link_hash_newfunc,
  161. sizeof (struct linux_link_hash_entry)))
  162. {
  163. free (ret);
  164. return (struct bfd_link_hash_table *) NULL;
  165. }
  166. return &ret->root.root;
  167. }
  168. /* Look up an entry in a Linux link hash table. */
  169. #define linux_link_hash_lookup(table, string, create, copy, follow) \
  170. ((struct linux_link_hash_entry *) \
  171. aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
  172. (follow)))
  173. /* Traverse a Linux link hash table. */
  174. #define linux_link_hash_traverse(table, func, info) \
  175. (aout_link_hash_traverse \
  176. (&(table)->root, \
  177. (bfd_boolean (*) (struct aout_link_hash_entry *, void *)) (func), \
  178. (info)))
  179. /* Get the Linux link hash table from the info structure. This is
  180. just a cast. */
  181. #define linux_hash_table(p) ((struct linux_link_hash_table *) ((p)->hash))
  182. /* Store the information for a new fixup. */
  183. static struct fixup *
  184. new_fixup (struct bfd_link_info *info,
  185. struct linux_link_hash_entry *h,
  186. bfd_vma value,
  187. int builtin)
  188. {
  189. struct fixup *f;
  190. f = (struct fixup *) bfd_hash_allocate (&info->hash->table,
  191. sizeof (struct fixup));
  192. if (f == NULL)
  193. return f;
  194. f->next = linux_hash_table (info)->fixup_list;
  195. linux_hash_table (info)->fixup_list = f;
  196. f->h = h;
  197. f->value = value;
  198. f->builtin = builtin;
  199. f->jump = 0;
  200. ++linux_hash_table (info)->fixup_count;
  201. return f;
  202. }
  203. /* We come here once we realize that we are going to link to a shared
  204. library. We need to create a special section that contains the
  205. fixup table, and we ultimately need to add a pointer to this into
  206. the set vector for SHARABLE_CONFLICTS. At this point we do not
  207. know the size of the section, but that's OK - we just need to
  208. create it for now. */
  209. static bfd_boolean
  210. linux_link_create_dynamic_sections (bfd *abfd,
  211. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  212. {
  213. flagword flags;
  214. asection *s;
  215. /* Note that we set the SEC_IN_MEMORY flag. */
  216. flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
  217. /* We choose to use the name ".linux-dynamic" for the fixup table.
  218. Why not? */
  219. s = bfd_make_section_with_flags (abfd, ".linux-dynamic", flags);
  220. if (s == NULL
  221. || ! bfd_set_section_alignment (abfd, s, 2))
  222. return FALSE;
  223. s->size = 0;
  224. s->contents = 0;
  225. return TRUE;
  226. }
  227. /* Function to add a single symbol to the linker hash table. This is
  228. a wrapper around _bfd_generic_link_add_one_symbol which handles the
  229. tweaking needed for dynamic linking support. */
  230. static bfd_boolean
  231. linux_add_one_symbol (struct bfd_link_info *info,
  232. bfd *abfd,
  233. const char *name,
  234. flagword flags,
  235. asection *section,
  236. bfd_vma value,
  237. const char *string,
  238. bfd_boolean copy,
  239. bfd_boolean collect,
  240. struct bfd_link_hash_entry **hashp)
  241. {
  242. struct linux_link_hash_entry *h;
  243. bfd_boolean insert;
  244. /* Look up and see if we already have this symbol in the hash table.
  245. If we do, and the defining entry is from a shared library, we
  246. need to create the dynamic sections.
  247. FIXME: What if abfd->xvec != info->output_bfd->xvec? We may
  248. want to be able to link Linux a.out and ELF objects together,
  249. but serious confusion is possible. */
  250. insert = FALSE;
  251. if (! bfd_link_relocatable (info)
  252. && linux_hash_table (info)->dynobj == NULL
  253. && strcmp (name, SHARABLE_CONFLICTS) == 0
  254. && (flags & BSF_CONSTRUCTOR) != 0
  255. && abfd->xvec == info->output_bfd->xvec)
  256. {
  257. if (! linux_link_create_dynamic_sections (abfd, info))
  258. return FALSE;
  259. linux_hash_table (info)->dynobj = abfd;
  260. insert = TRUE;
  261. }
  262. if (bfd_is_abs_section (section)
  263. && abfd->xvec == info->output_bfd->xvec)
  264. {
  265. h = linux_link_hash_lookup (linux_hash_table (info), name, FALSE,
  266. FALSE, FALSE);
  267. if (h != NULL
  268. && (h->root.root.type == bfd_link_hash_defined
  269. || h->root.root.type == bfd_link_hash_defweak))
  270. {
  271. struct fixup *f;
  272. if (hashp != NULL)
  273. *hashp = (struct bfd_link_hash_entry *) h;
  274. f = new_fixup (info, h, value, ! IS_PLT_SYM (name));
  275. if (f == NULL)
  276. return FALSE;
  277. f->jump = IS_PLT_SYM (name);
  278. return TRUE;
  279. }
  280. }
  281. /* Do the usual procedure for adding a symbol. */
  282. if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
  283. value, string, copy, collect,
  284. hashp))
  285. return FALSE;
  286. /* Insert a pointer to our table in the set vector. The dynamic
  287. linker requires this information */
  288. if (insert)
  289. {
  290. asection *s;
  291. /* Here we do our special thing to add the pointer to the
  292. dynamic section in the SHARABLE_CONFLICTS set vector. */
  293. s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  294. ".linux-dynamic");
  295. BFD_ASSERT (s != NULL);
  296. if (! (_bfd_generic_link_add_one_symbol
  297. (info, linux_hash_table (info)->dynobj, SHARABLE_CONFLICTS,
  298. BSF_GLOBAL | BSF_CONSTRUCTOR, s, (bfd_vma) 0, NULL,
  299. FALSE, FALSE, NULL)))
  300. return FALSE;
  301. }
  302. return TRUE;
  303. }
  304. /* We will crawl the hash table and come here for every global symbol.
  305. We will examine each entry and see if there are indications that we
  306. need to add a fixup. There are two possible cases - one is where
  307. you have duplicate definitions of PLT or GOT symbols - these will
  308. have already been caught and added as "builtin" fixups. If we find
  309. that the corresponding non PLT/GOT symbol is also present, we
  310. convert it to a regular fixup instead.
  311. This function is called via linux_link_hash_traverse. */
  312. static bfd_boolean
  313. linux_tally_symbols (struct linux_link_hash_entry *h,
  314. void * data)
  315. {
  316. struct bfd_link_info *info = (struct bfd_link_info *) data;
  317. struct fixup *f, *f1;
  318. int is_plt;
  319. struct linux_link_hash_entry *h1, *h2;
  320. bfd_boolean exists;
  321. if (h->root.root.type == bfd_link_hash_undefined
  322. && CONST_STRNEQ (h->root.root.root.string, NEEDS_SHRLIB))
  323. {
  324. const char *name;
  325. char *p;
  326. char *alloc = NULL;
  327. name = h->root.root.root.string + sizeof NEEDS_SHRLIB - 1;
  328. p = strrchr (name, '_');
  329. if (p != NULL)
  330. alloc = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 1);
  331. if (p == NULL || alloc == NULL)
  332. (*_bfd_error_handler) (_("Output file requires shared library `%s'\n"),
  333. name);
  334. else
  335. {
  336. strcpy (alloc, name);
  337. p = strrchr (alloc, '_');
  338. *p++ = '\0';
  339. (*_bfd_error_handler)
  340. (_("Output file requires shared library `%s.so.%s'\n"),
  341. alloc, p);
  342. free (alloc);
  343. }
  344. abort ();
  345. }
  346. /* If this symbol is not a PLT/GOT, we do not even need to look at it */
  347. is_plt = IS_PLT_SYM (h->root.root.root.string);
  348. if (is_plt || IS_GOT_SYM (h->root.root.root.string))
  349. {
  350. /* Look up this symbol twice. Once just as a regular lookup,
  351. and then again following all of the indirect links until we
  352. reach a real symbol. */
  353. h1 = linux_link_hash_lookup (linux_hash_table (info),
  354. (h->root.root.root.string
  355. + sizeof PLT_REF_PREFIX - 1),
  356. FALSE, FALSE, TRUE);
  357. /* h2 does not follow indirect symbols. */
  358. h2 = linux_link_hash_lookup (linux_hash_table (info),
  359. (h->root.root.root.string
  360. + sizeof PLT_REF_PREFIX - 1),
  361. FALSE, FALSE, FALSE);
  362. /* The real symbol must exist but if it is also an ABS symbol,
  363. there is no need to have a fixup. This is because they both
  364. came from the same library. If on the other hand, we had to
  365. use an indirect symbol to get to the real symbol, we add the
  366. fixup anyway, since there are cases where these symbols come
  367. from different shared libraries */
  368. if (h1 != NULL
  369. && (((h1->root.root.type == bfd_link_hash_defined
  370. || h1->root.root.type == bfd_link_hash_defweak)
  371. && ! bfd_is_abs_section (h1->root.root.u.def.section))
  372. || h2->root.root.type == bfd_link_hash_indirect))
  373. {
  374. /* See if there is a "builtin" fixup already present
  375. involving this symbol. If so, convert it to a regular
  376. fixup. In the end, this relaxes some of the requirements
  377. about the order of performing fixups. */
  378. exists = FALSE;
  379. for (f1 = linux_hash_table (info)->fixup_list;
  380. f1 != NULL;
  381. f1 = f1->next)
  382. {
  383. if ((f1->h != h && f1->h != h1)
  384. || (! f1->builtin && ! f1->jump))
  385. continue;
  386. if (f1->h == h1)
  387. exists = TRUE;
  388. if (! exists
  389. && bfd_is_abs_section (h->root.root.u.def.section))
  390. {
  391. f = new_fixup (info, h1, f1->h->root.root.u.def.value, 0);
  392. f->jump = is_plt;
  393. }
  394. f1->h = h1;
  395. f1->jump = is_plt;
  396. f1->builtin = 0;
  397. exists = TRUE;
  398. }
  399. if (! exists
  400. && bfd_is_abs_section (h->root.root.u.def.section))
  401. {
  402. f = new_fixup (info, h1, h->root.root.u.def.value, 0);
  403. if (f == NULL)
  404. {
  405. /* FIXME: No way to return error. */
  406. abort ();
  407. }
  408. f->jump = is_plt;
  409. }
  410. }
  411. /* Quick and dirty way of stripping these symbols from the
  412. symtab. */
  413. if (bfd_is_abs_section (h->root.root.u.def.section))
  414. h->root.written = TRUE;
  415. }
  416. return TRUE;
  417. }
  418. /* This is called to set the size of the .linux-dynamic section is.
  419. It is called by the Linux linker emulation before_allocation
  420. routine. We have finished reading all of the input files, and now
  421. we just scan the hash tables to find out how many additional fixups
  422. are required. */
  423. bfd_boolean
  424. bfd_m68klinux_size_dynamic_sections (bfd *output_bfd,
  425. struct bfd_link_info *info)
  426. {
  427. struct fixup *f;
  428. asection *s;
  429. if (output_bfd->xvec != &MY(vec))
  430. return TRUE;
  431. /* First find the fixups... */
  432. linux_link_hash_traverse (linux_hash_table (info),
  433. linux_tally_symbols,
  434. info);
  435. /* If there are builtin fixups, leave room for a marker. This is
  436. used by the dynamic linker so that it knows that all that follow
  437. are builtin fixups instead of regular fixups. */
  438. for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  439. {
  440. if (f->builtin)
  441. {
  442. ++linux_hash_table (info)->fixup_count;
  443. ++linux_hash_table (info)->local_builtins;
  444. break;
  445. }
  446. }
  447. if (linux_hash_table (info)->dynobj == NULL)
  448. {
  449. if (linux_hash_table (info)->fixup_count > 0)
  450. abort ();
  451. return TRUE;
  452. }
  453. /* Allocate memory for our fixup table. We will fill it in later. */
  454. s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  455. ".linux-dynamic");
  456. if (s != NULL)
  457. {
  458. s->size = linux_hash_table (info)->fixup_count + 1;
  459. s->size *= 8;
  460. s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->size);
  461. if (s->contents == NULL)
  462. {
  463. bfd_set_error (bfd_error_no_memory);
  464. return FALSE;
  465. }
  466. }
  467. return TRUE;
  468. }
  469. /* We come here once we are ready to actually write the fixup table to
  470. the output file. Scan the fixup tables and so forth and generate
  471. the stuff we need. */
  472. static bfd_boolean
  473. linux_finish_dynamic_link (bfd *output_bfd, struct bfd_link_info *info)
  474. {
  475. asection *s, *os, *is;
  476. bfd_byte *fixup_table;
  477. struct linux_link_hash_entry *h;
  478. struct fixup *f;
  479. unsigned int new_addr;
  480. int section_offset;
  481. unsigned int fixups_written;
  482. if (linux_hash_table (info)->dynobj == NULL)
  483. return TRUE;
  484. s = bfd_get_section_by_name (linux_hash_table (info)->dynobj,
  485. ".linux-dynamic");
  486. BFD_ASSERT (s != NULL);
  487. os = s->output_section;
  488. fixups_written = 0;
  489. #ifdef LINUX_LINK_DEBUG
  490. printf ("Fixup table file offset: %x VMA: %x\n",
  491. os->filepos + s->output_offset,
  492. os->vma + s->output_offset);
  493. #endif
  494. fixup_table = s->contents;
  495. bfd_put_32 (output_bfd, (bfd_vma) linux_hash_table (info)->fixup_count,
  496. fixup_table);
  497. fixup_table += 4;
  498. /* Fill in fixup table. */
  499. for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  500. {
  501. if (f->builtin)
  502. continue;
  503. if (f->h->root.root.type != bfd_link_hash_defined
  504. && f->h->root.root.type != bfd_link_hash_defweak)
  505. {
  506. (*_bfd_error_handler)
  507. (_("Symbol %s not defined for fixups\n"),
  508. f->h->root.root.root.string);
  509. continue;
  510. }
  511. is = f->h->root.root.u.def.section;
  512. section_offset = is->output_section->vma + is->output_offset;
  513. new_addr = f->h->root.root.u.def.value + section_offset;
  514. #ifdef LINUX_LINK_DEBUG
  515. printf ("Fixup(%d) %s: %x %x\n",f->jump, f->h->root.root.string,
  516. new_addr, f->value);
  517. #endif
  518. if (f->jump)
  519. {
  520. bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
  521. fixup_table += 4;
  522. bfd_put_32 (output_bfd, f->value + 2, fixup_table);
  523. fixup_table += 4;
  524. }
  525. else
  526. {
  527. bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
  528. fixup_table += 4;
  529. bfd_put_32 (output_bfd, f->value, fixup_table);
  530. fixup_table += 4;
  531. }
  532. ++fixups_written;
  533. }
  534. if (linux_hash_table (info)->local_builtins != 0)
  535. {
  536. /* Special marker so we know to switch to the other type of fixup */
  537. bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
  538. fixup_table += 4;
  539. bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
  540. fixup_table += 4;
  541. ++fixups_written;
  542. for (f = linux_hash_table (info)->fixup_list; f != NULL; f = f->next)
  543. {
  544. if (! f->builtin)
  545. continue;
  546. if (f->h->root.root.type != bfd_link_hash_defined
  547. && f->h->root.root.type != bfd_link_hash_defweak)
  548. {
  549. (*_bfd_error_handler)
  550. (_("Symbol %s not defined for fixups\n"),
  551. f->h->root.root.root.string);
  552. continue;
  553. }
  554. is = f->h->root.root.u.def.section;
  555. section_offset = is->output_section->vma + is->output_offset;
  556. new_addr = f->h->root.root.u.def.value + section_offset;
  557. #ifdef LINUX_LINK_DEBUG
  558. printf ("Fixup(B) %s: %x %x\n", f->h->root.root.string,
  559. new_addr, f->value);
  560. #endif
  561. bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
  562. fixup_table += 4;
  563. bfd_put_32 (output_bfd, f->value, fixup_table);
  564. fixup_table += 4;
  565. ++fixups_written;
  566. }
  567. }
  568. if (linux_hash_table (info)->fixup_count != fixups_written)
  569. {
  570. (*_bfd_error_handler) (_("Warning: fixup count mismatch\n"));
  571. while (linux_hash_table (info)->fixup_count > fixups_written)
  572. {
  573. bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
  574. fixup_table += 4;
  575. bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
  576. fixup_table += 4;
  577. ++fixups_written;
  578. }
  579. }
  580. h = linux_link_hash_lookup (linux_hash_table (info),
  581. "__BUILTIN_FIXUPS__",
  582. FALSE, FALSE, FALSE);
  583. if (h != NULL
  584. && (h->root.root.type == bfd_link_hash_defined
  585. || h->root.root.type == bfd_link_hash_defweak))
  586. {
  587. is = h->root.root.u.def.section;
  588. section_offset = is->output_section->vma + is->output_offset;
  589. new_addr = h->root.root.u.def.value + section_offset;
  590. #ifdef LINUX_LINK_DEBUG
  591. printf ("Builtin fixup table at %x\n", new_addr);
  592. #endif
  593. bfd_put_32 (output_bfd, (bfd_vma) new_addr, fixup_table);
  594. }
  595. else
  596. bfd_put_32 (output_bfd, (bfd_vma) 0, fixup_table);
  597. if (bfd_seek (output_bfd, (file_ptr) (os->filepos + s->output_offset),
  598. SEEK_SET) != 0)
  599. return FALSE;
  600. if (bfd_bwrite (s->contents, s->size, output_bfd) != s->size)
  601. return FALSE;
  602. return TRUE;
  603. }
  604. #define MY_bfd_link_hash_table_create linux_link_hash_table_create
  605. #define MY_add_one_symbol linux_add_one_symbol
  606. #define MY_finish_dynamic_link linux_finish_dynamic_link
  607. #define MY_zmagic_contiguous 1
  608. #include "aout-target.h"