ldcref.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /* ldcref.c -- output a cross reference table
  2. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor <ian@cygnus.com>
  4. This file is part of the GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. /* This file holds routines that manage the cross reference table.
  18. The table is used to generate cross reference reports. It is also
  19. used to implement the NOCROSSREFS command in the linker script. */
  20. #include "sysdep.h"
  21. #include "bfd.h"
  22. #include "bfdlink.h"
  23. #include "ctf-api.h"
  24. #include "libiberty.h"
  25. #include "demangle.h"
  26. #include "objalloc.h"
  27. #include "ld.h"
  28. #include "ldmain.h"
  29. #include "ldmisc.h"
  30. #include "ldexp.h"
  31. #include "ldlang.h"
  32. /* We keep an instance of this structure for each reference to a
  33. symbol from a given object. */
  34. struct cref_ref
  35. {
  36. /* The next reference. */
  37. struct cref_ref *next;
  38. /* The object. */
  39. bfd *abfd;
  40. /* True if the symbol is defined. */
  41. unsigned int def : 1;
  42. /* True if the symbol is common. */
  43. unsigned int common : 1;
  44. /* True if the symbol is undefined. */
  45. unsigned int undef : 1;
  46. };
  47. /* We keep a hash table of symbols. Each entry looks like this. */
  48. struct cref_hash_entry
  49. {
  50. struct bfd_hash_entry root;
  51. /* The demangled name. */
  52. const char *demangled;
  53. /* References to and definitions of this symbol. */
  54. struct cref_ref *refs;
  55. };
  56. /* This is what the hash table looks like. */
  57. struct cref_hash_table
  58. {
  59. struct bfd_hash_table root;
  60. };
  61. /* Forward declarations. */
  62. static void output_one_cref (FILE *, struct cref_hash_entry *);
  63. static void check_local_sym_xref (lang_input_statement_type *);
  64. static bool check_nocrossref (struct cref_hash_entry *, void *);
  65. static void check_refs (const char *, bool, asection *, bfd *,
  66. struct lang_nocrossrefs *);
  67. static void check_reloc_refs (bfd *, asection *, void *);
  68. /* Look up an entry in the cref hash table. */
  69. #define cref_hash_lookup(table, string, create, copy) \
  70. ((struct cref_hash_entry *) \
  71. bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
  72. /* Traverse the cref hash table. */
  73. #define cref_hash_traverse(table, func, info) \
  74. (bfd_hash_traverse \
  75. (&(table)->root, \
  76. (bool (*) (struct bfd_hash_entry *, void *)) (func), (info)))
  77. /* The cref hash table. */
  78. static struct cref_hash_table cref_table;
  79. /* Whether the cref hash table has been initialized. */
  80. static bool cref_initialized;
  81. /* The number of symbols seen so far. */
  82. static size_t cref_symcount;
  83. /* Used to take a snapshot of the cref hash table when starting to
  84. add syms from an as-needed library. */
  85. static struct bfd_hash_entry **old_table;
  86. static unsigned int old_size;
  87. static unsigned int old_count;
  88. static void *old_tab;
  89. static void *alloc_mark;
  90. static size_t tabsize, entsize, refsize;
  91. static size_t old_symcount;
  92. /* Create an entry in a cref hash table. */
  93. static struct bfd_hash_entry *
  94. cref_hash_newfunc (struct bfd_hash_entry *entry,
  95. struct bfd_hash_table *table,
  96. const char *string)
  97. {
  98. struct cref_hash_entry *ret = (struct cref_hash_entry *) entry;
  99. /* Allocate the structure if it has not already been allocated by a
  100. subclass. */
  101. if (ret == NULL)
  102. ret = ((struct cref_hash_entry *)
  103. bfd_hash_allocate (table, sizeof (struct cref_hash_entry)));
  104. if (ret == NULL)
  105. return NULL;
  106. /* Call the allocation method of the superclass. */
  107. ret = ((struct cref_hash_entry *)
  108. bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
  109. if (ret != NULL)
  110. {
  111. /* Set local fields. */
  112. ret->demangled = NULL;
  113. ret->refs = NULL;
  114. /* Keep a count of the number of entries created in the hash
  115. table. */
  116. ++cref_symcount;
  117. }
  118. return &ret->root;
  119. }
  120. /* Add a symbol to the cref hash table. This is called for every
  121. global symbol that is seen during the link. */
  122. void
  123. add_cref (const char *name,
  124. bfd *abfd,
  125. asection *section,
  126. bfd_vma value ATTRIBUTE_UNUSED)
  127. {
  128. struct cref_hash_entry *h;
  129. struct cref_ref *r;
  130. if (!cref_initialized)
  131. {
  132. if (!bfd_hash_table_init (&cref_table.root, cref_hash_newfunc,
  133. sizeof (struct cref_hash_entry)))
  134. einfo (_("%X%P: bfd_hash_table_init of cref table failed: %E\n"));
  135. cref_initialized = true;
  136. }
  137. h = cref_hash_lookup (&cref_table, name, true, false);
  138. if (h == NULL)
  139. einfo (_("%X%P: cref_hash_lookup failed: %E\n"));
  140. for (r = h->refs; r != NULL; r = r->next)
  141. if (r->abfd == abfd)
  142. break;
  143. if (r == NULL)
  144. {
  145. r = (struct cref_ref *) bfd_hash_allocate (&cref_table.root, sizeof *r);
  146. if (r == NULL)
  147. einfo (_("%X%P: cref alloc failed: %E\n"));
  148. r->next = h->refs;
  149. h->refs = r;
  150. r->abfd = abfd;
  151. r->def = false;
  152. r->common = false;
  153. r->undef = false;
  154. }
  155. if (bfd_is_und_section (section))
  156. r->undef = true;
  157. else if (bfd_is_com_section (section))
  158. r->common = true;
  159. else
  160. r->def = true;
  161. }
  162. /* Called before loading an as-needed library to take a snapshot of
  163. the cref hash table, and after we have loaded or found that the
  164. library was not needed. */
  165. bool
  166. handle_asneeded_cref (bfd *abfd ATTRIBUTE_UNUSED,
  167. enum notice_asneeded_action act)
  168. {
  169. unsigned int i;
  170. if (!cref_initialized)
  171. return true;
  172. if (act == notice_as_needed)
  173. {
  174. char *old_ent, *old_ref;
  175. for (i = 0; i < cref_table.root.size; i++)
  176. {
  177. struct bfd_hash_entry *p;
  178. struct cref_hash_entry *c;
  179. struct cref_ref *r;
  180. for (p = cref_table.root.table[i]; p != NULL; p = p->next)
  181. {
  182. entsize += cref_table.root.entsize;
  183. c = (struct cref_hash_entry *) p;
  184. for (r = c->refs; r != NULL; r = r->next)
  185. refsize += sizeof (struct cref_ref);
  186. }
  187. }
  188. tabsize = cref_table.root.size * sizeof (struct bfd_hash_entry *);
  189. old_tab = xmalloc (tabsize + entsize + refsize);
  190. alloc_mark = bfd_hash_allocate (&cref_table.root, 1);
  191. if (alloc_mark == NULL)
  192. return false;
  193. memcpy (old_tab, cref_table.root.table, tabsize);
  194. old_ent = (char *) old_tab + tabsize;
  195. old_ref = (char *) old_ent + entsize;
  196. old_table = cref_table.root.table;
  197. old_size = cref_table.root.size;
  198. old_count = cref_table.root.count;
  199. old_symcount = cref_symcount;
  200. for (i = 0; i < cref_table.root.size; i++)
  201. {
  202. struct bfd_hash_entry *p;
  203. struct cref_hash_entry *c;
  204. struct cref_ref *r;
  205. for (p = cref_table.root.table[i]; p != NULL; p = p->next)
  206. {
  207. memcpy (old_ent, p, cref_table.root.entsize);
  208. old_ent = (char *) old_ent + cref_table.root.entsize;
  209. c = (struct cref_hash_entry *) p;
  210. for (r = c->refs; r != NULL; r = r->next)
  211. {
  212. memcpy (old_ref, r, sizeof (struct cref_ref));
  213. old_ref = (char *) old_ref + sizeof (struct cref_ref);
  214. }
  215. }
  216. }
  217. return true;
  218. }
  219. if (act == notice_not_needed)
  220. {
  221. char *old_ent, *old_ref;
  222. if (old_tab == NULL)
  223. {
  224. /* The only way old_tab can be NULL is if the cref hash table
  225. had not been initialised when notice_as_needed. */
  226. bfd_hash_table_free (&cref_table.root);
  227. cref_initialized = false;
  228. return true;
  229. }
  230. old_ent = (char *) old_tab + tabsize;
  231. old_ref = (char *) old_ent + entsize;
  232. cref_table.root.table = old_table;
  233. cref_table.root.size = old_size;
  234. cref_table.root.count = old_count;
  235. memcpy (cref_table.root.table, old_tab, tabsize);
  236. cref_symcount = old_symcount;
  237. for (i = 0; i < cref_table.root.size; i++)
  238. {
  239. struct bfd_hash_entry *p;
  240. struct cref_hash_entry *c;
  241. struct cref_ref *r;
  242. for (p = cref_table.root.table[i]; p != NULL; p = p->next)
  243. {
  244. memcpy (p, old_ent, cref_table.root.entsize);
  245. old_ent = (char *) old_ent + cref_table.root.entsize;
  246. c = (struct cref_hash_entry *) p;
  247. for (r = c->refs; r != NULL; r = r->next)
  248. {
  249. memcpy (r, old_ref, sizeof (struct cref_ref));
  250. old_ref = (char *) old_ref + sizeof (struct cref_ref);
  251. }
  252. }
  253. }
  254. objalloc_free_block ((struct objalloc *) cref_table.root.memory,
  255. alloc_mark);
  256. }
  257. else if (act != notice_needed)
  258. return false;
  259. free (old_tab);
  260. old_tab = NULL;
  261. return true;
  262. }
  263. /* Copy the addresses of the hash table entries into an array. This
  264. is called via cref_hash_traverse. We also fill in the demangled
  265. name. */
  266. static bool
  267. cref_fill_array (struct cref_hash_entry *h, void *data)
  268. {
  269. struct cref_hash_entry ***pph = (struct cref_hash_entry ***) data;
  270. ASSERT (h->demangled == NULL);
  271. h->demangled = bfd_demangle (link_info.output_bfd, h->root.string,
  272. DMGL_ANSI | DMGL_PARAMS);
  273. if (h->demangled == NULL)
  274. h->demangled = h->root.string;
  275. **pph = h;
  276. ++*pph;
  277. return true;
  278. }
  279. /* Sort an array of cref hash table entries by name. */
  280. static int
  281. cref_sort_array (const void *a1, const void *a2)
  282. {
  283. const struct cref_hash_entry *const *p1
  284. = (const struct cref_hash_entry *const *) a1;
  285. const struct cref_hash_entry *const *p2
  286. = (const struct cref_hash_entry *const *) a2;
  287. if (demangling)
  288. return strcmp ((*p1)->demangled, (*p2)->demangled);
  289. else
  290. return strcmp ((*p1)->root.string, (*p2)->root.string);
  291. }
  292. /* Write out the cref table. */
  293. #define FILECOL (50)
  294. void
  295. output_cref (FILE *fp)
  296. {
  297. int len;
  298. struct cref_hash_entry **csyms, **csym_fill, **csym, **csym_end;
  299. const char *msg;
  300. fprintf (fp, _("\nCross Reference Table\n\n"));
  301. msg = _("Symbol");
  302. fprintf (fp, "%s", msg);
  303. len = strlen (msg);
  304. while (len < FILECOL)
  305. {
  306. putc (' ', fp);
  307. ++len;
  308. }
  309. fprintf (fp, _("File\n"));
  310. if (!cref_initialized)
  311. {
  312. fprintf (fp, _("No symbols\n"));
  313. return;
  314. }
  315. csyms = (struct cref_hash_entry **) xmalloc (cref_symcount * sizeof (*csyms));
  316. csym_fill = csyms;
  317. cref_hash_traverse (&cref_table, cref_fill_array, &csym_fill);
  318. ASSERT ((size_t) (csym_fill - csyms) == cref_symcount);
  319. qsort (csyms, cref_symcount, sizeof (*csyms), cref_sort_array);
  320. csym_end = csyms + cref_symcount;
  321. for (csym = csyms; csym < csym_end; csym++)
  322. output_one_cref (fp, *csym);
  323. }
  324. /* Output one entry in the cross reference table. */
  325. static void
  326. output_one_cref (FILE *fp, struct cref_hash_entry *h)
  327. {
  328. int len;
  329. struct bfd_link_hash_entry *hl;
  330. struct cref_ref *r;
  331. hl = bfd_link_hash_lookup (link_info.hash, h->root.string, false,
  332. false, true);
  333. if (hl == NULL)
  334. einfo (_("%P: symbol `%pT' missing from main hash table\n"),
  335. h->root.string);
  336. else
  337. {
  338. /* If this symbol is defined in a dynamic object but never
  339. referenced by a normal object, then don't print it. */
  340. if (hl->type == bfd_link_hash_defined)
  341. {
  342. if (hl->u.def.section->output_section == NULL)
  343. return;
  344. if (hl->u.def.section->owner != NULL
  345. && (hl->u.def.section->owner->flags & DYNAMIC) != 0)
  346. {
  347. for (r = h->refs; r != NULL; r = r->next)
  348. if ((r->abfd->flags & DYNAMIC) == 0)
  349. break;
  350. if (r == NULL)
  351. return;
  352. }
  353. }
  354. }
  355. if (demangling)
  356. {
  357. fprintf (fp, "%s ", h->demangled);
  358. len = strlen (h->demangled) + 1;
  359. }
  360. else
  361. {
  362. fprintf (fp, "%s ", h->root.string);
  363. len = strlen (h->root.string) + 1;
  364. }
  365. for (r = h->refs; r != NULL; r = r->next)
  366. {
  367. if (r->def)
  368. {
  369. while (len < FILECOL)
  370. {
  371. putc (' ', fp);
  372. ++len;
  373. }
  374. lfinfo (fp, "%pB\n", r->abfd);
  375. len = 0;
  376. }
  377. }
  378. for (r = h->refs; r != NULL; r = r->next)
  379. {
  380. if (r->common)
  381. {
  382. while (len < FILECOL)
  383. {
  384. putc (' ', fp);
  385. ++len;
  386. }
  387. lfinfo (fp, "%pB\n", r->abfd);
  388. len = 0;
  389. }
  390. }
  391. for (r = h->refs; r != NULL; r = r->next)
  392. {
  393. if (!r->def && !r->common)
  394. {
  395. while (len < FILECOL)
  396. {
  397. putc (' ', fp);
  398. ++len;
  399. }
  400. lfinfo (fp, "%pB\n", r->abfd);
  401. len = 0;
  402. }
  403. }
  404. ASSERT (len == 0);
  405. }
  406. /* Check for prohibited cross references. */
  407. void
  408. check_nocrossrefs (void)
  409. {
  410. if (!cref_initialized)
  411. return;
  412. cref_hash_traverse (&cref_table, check_nocrossref, NULL);
  413. lang_for_each_file (check_local_sym_xref);
  414. }
  415. /* Check for prohibited cross references to local and section symbols. */
  416. static void
  417. check_local_sym_xref (lang_input_statement_type *statement)
  418. {
  419. bfd *abfd;
  420. asymbol **syms;
  421. abfd = statement->the_bfd;
  422. if (abfd == NULL)
  423. return;
  424. if (!bfd_generic_link_read_symbols (abfd))
  425. einfo (_("%F%P: %pB: could not read symbols: %E\n"), abfd);
  426. for (syms = bfd_get_outsymbols (abfd); *syms; ++syms)
  427. {
  428. asymbol *sym = *syms;
  429. if (sym->flags & (BSF_GLOBAL | BSF_WARNING | BSF_INDIRECT | BSF_FILE))
  430. continue;
  431. if ((sym->flags & (BSF_LOCAL | BSF_SECTION_SYM)) != 0
  432. && sym->section->output_section != NULL)
  433. {
  434. const char *outsecname, *symname;
  435. struct lang_nocrossrefs *ncrs;
  436. struct lang_nocrossref *ncr;
  437. outsecname = sym->section->output_section->name;
  438. symname = NULL;
  439. if ((sym->flags & BSF_SECTION_SYM) == 0)
  440. symname = sym->name;
  441. for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
  442. for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
  443. {
  444. if (strcmp (ncr->name, outsecname) == 0)
  445. check_refs (symname, false, sym->section, abfd, ncrs);
  446. /* The NOCROSSREFS_TO command only checks symbols defined in
  447. the first section in the list. */
  448. if (ncrs->onlyfirst)
  449. break;
  450. }
  451. }
  452. }
  453. }
  454. /* Check one symbol to see if it is a prohibited cross reference. */
  455. static bool
  456. check_nocrossref (struct cref_hash_entry *h, void *ignore ATTRIBUTE_UNUSED)
  457. {
  458. struct bfd_link_hash_entry *hl;
  459. asection *defsec;
  460. const char *defsecname;
  461. struct lang_nocrossrefs *ncrs;
  462. struct lang_nocrossref *ncr;
  463. struct cref_ref *ref;
  464. hl = bfd_link_hash_lookup (link_info.hash, h->root.string, false,
  465. false, true);
  466. if (hl == NULL)
  467. {
  468. einfo (_("%P: symbol `%pT' missing from main hash table\n"),
  469. h->root.string);
  470. return true;
  471. }
  472. if (hl->type != bfd_link_hash_defined
  473. && hl->type != bfd_link_hash_defweak)
  474. return true;
  475. defsec = hl->u.def.section->output_section;
  476. if (defsec == NULL)
  477. return true;
  478. defsecname = bfd_section_name (defsec);
  479. for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
  480. for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
  481. {
  482. if (strcmp (ncr->name, defsecname) == 0)
  483. for (ref = h->refs; ref != NULL; ref = ref->next)
  484. check_refs (hl->root.string, true, hl->u.def.section,
  485. ref->abfd, ncrs);
  486. /* The NOCROSSREFS_TO command only checks symbols defined in the first
  487. section in the list. */
  488. if (ncrs->onlyfirst)
  489. break;
  490. }
  491. return true;
  492. }
  493. /* The struct is used to pass information from check_refs to
  494. check_reloc_refs through bfd_map_over_sections. */
  495. struct check_refs_info
  496. {
  497. const char *sym_name;
  498. asection *defsec;
  499. struct lang_nocrossrefs *ncrs;
  500. asymbol **asymbols;
  501. bool global;
  502. };
  503. /* This function is called for each symbol defined in a section which
  504. prohibits cross references. We need to look through all references
  505. to this symbol, and ensure that the references are not from
  506. prohibited sections. */
  507. static void
  508. check_refs (const char *name,
  509. bool global,
  510. asection *sec,
  511. bfd *abfd,
  512. struct lang_nocrossrefs *ncrs)
  513. {
  514. struct check_refs_info info;
  515. /* We need to look through the relocations for this BFD, to see
  516. if any of the relocations which refer to this symbol are from
  517. a prohibited section. Note that we need to do this even for
  518. the BFD in which the symbol is defined, since even a single
  519. BFD might contain a prohibited cross reference. */
  520. if (!bfd_generic_link_read_symbols (abfd))
  521. einfo (_("%F%P: %pB: could not read symbols: %E\n"), abfd);
  522. info.sym_name = name;
  523. info.global = global;
  524. info.defsec = sec;
  525. info.ncrs = ncrs;
  526. info.asymbols = bfd_get_outsymbols (abfd);
  527. bfd_map_over_sections (abfd, check_reloc_refs, &info);
  528. }
  529. /* This is called via bfd_map_over_sections. INFO->SYM_NAME is a symbol
  530. defined in INFO->DEFSECNAME. If this section maps into any of the
  531. sections listed in INFO->NCRS, other than INFO->DEFSECNAME, then we
  532. look through the relocations. If any of the relocations are to
  533. INFO->SYM_NAME, then we report a prohibited cross reference error. */
  534. static void
  535. check_reloc_refs (bfd *abfd, asection *sec, void *iarg)
  536. {
  537. struct check_refs_info *info = (struct check_refs_info *) iarg;
  538. asection *outsec;
  539. const char *outsecname;
  540. asection *outdefsec;
  541. const char *outdefsecname;
  542. struct lang_nocrossref *ncr;
  543. const char *symname;
  544. bool global;
  545. long relsize;
  546. arelent **relpp;
  547. long relcount;
  548. arelent **p, **pend;
  549. outsec = sec->output_section;
  550. outsecname = bfd_section_name (outsec);
  551. outdefsec = info->defsec->output_section;
  552. outdefsecname = bfd_section_name (outdefsec);
  553. /* The section where the symbol is defined is permitted. */
  554. if (strcmp (outsecname, outdefsecname) == 0)
  555. return;
  556. for (ncr = info->ncrs->list; ncr != NULL; ncr = ncr->next)
  557. if (strcmp (outsecname, ncr->name) == 0)
  558. break;
  559. if (ncr == NULL)
  560. return;
  561. /* This section is one for which cross references are prohibited.
  562. Look through the relocations, and see if any of them are to
  563. INFO->SYM_NAME. If INFO->SYMNAME is NULL, check for relocations
  564. against the section symbol. If INFO->GLOBAL is TRUE, the
  565. definition is global, check for relocations against the global
  566. symbols. Otherwise check for relocations against the local and
  567. section symbols. */
  568. symname = info->sym_name;
  569. global = info->global;
  570. relsize = bfd_get_reloc_upper_bound (abfd, sec);
  571. if (relsize < 0)
  572. einfo (_("%F%P: %pB: could not read relocs: %E\n"), abfd);
  573. if (relsize == 0)
  574. return;
  575. relpp = (arelent **) xmalloc (relsize);
  576. relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols);
  577. if (relcount < 0)
  578. einfo (_("%F%P: %pB: could not read relocs: %E\n"), abfd);
  579. p = relpp;
  580. pend = p + relcount;
  581. for (; p < pend && *p != NULL; p++)
  582. {
  583. arelent *q = *p;
  584. if (q->sym_ptr_ptr != NULL
  585. && *q->sym_ptr_ptr != NULL
  586. && ((global
  587. && (bfd_is_und_section (bfd_asymbol_section (*q->sym_ptr_ptr))
  588. || bfd_is_com_section (bfd_asymbol_section (*q->sym_ptr_ptr))
  589. || ((*q->sym_ptr_ptr)->flags & (BSF_GLOBAL
  590. | BSF_WEAK)) != 0))
  591. || (!global
  592. && ((*q->sym_ptr_ptr)->flags & (BSF_LOCAL
  593. | BSF_SECTION_SYM)) != 0
  594. && bfd_asymbol_section (*q->sym_ptr_ptr) == info->defsec))
  595. && (symname != NULL
  596. ? strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
  597. : ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0))
  598. {
  599. /* We found a reloc for the symbol. The symbol is defined
  600. in OUTSECNAME. This reloc is from a section which is
  601. mapped into a section from which references to OUTSECNAME
  602. are prohibited. We must report an error. */
  603. einfo (_("%X%P: %C: prohibited cross reference from %s to `%pT' in %s\n"),
  604. abfd, sec, q->address, outsecname,
  605. bfd_asymbol_name (*q->sym_ptr_ptr), outdefsecname);
  606. }
  607. }
  608. free (relpp);
  609. }