i386linux.c 21 KB

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