solaris2.em 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. if [ -z "$MACHINE" ]; then
  4. OUTPUT_ARCH=${ARCH}
  5. else
  6. OUTPUT_ARCH=${ARCH}:${MACHINE}
  7. fi
  8. fragment <<EOF
  9. /* This file is generated by a shell script. DO NOT EDIT! */
  10. /* Solaris 2 emulation code for ${EMULATION_NAME}
  11. Copyright (C) 2010-2015 Free Software Foundation, Inc.
  12. Written by Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
  13. This file is part of the GNU Binutils.
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 3 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  25. MA 02110-1301, USA. */
  26. #define TARGET_IS_${EMULATION_NAME}
  27. /* The Solaris 2 ABI requires some global symbols to be present in the
  28. .dynsym table of executables and shared objects. If generating a
  29. versioned shared object, they must always be bound to the base version.
  30. Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
  31. File, p.63. */
  32. static void
  33. elf_solaris2_before_allocation (void)
  34. {
  35. /* Global symbols required by the Solaris 2 ABI. */
  36. static const char *global_syms[] = {
  37. "_DYNAMIC",
  38. "_GLOBAL_OFFSET_TABLE_",
  39. "_PROCEDURE_LINKAGE_TABLE_",
  40. "_edata",
  41. "_end",
  42. "_etext",
  43. NULL
  44. };
  45. const char **sym;
  46. /* Do this for both executables and shared objects. */
  47. if (!bfd_link_relocatable (&link_info))
  48. {
  49. for (sym = global_syms; *sym != NULL; sym++)
  50. {
  51. struct elf_link_hash_entry *h;
  52. /* Lookup symbol. */
  53. h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
  54. FALSE, FALSE, FALSE);
  55. if (h == NULL)
  56. continue;
  57. /* Undo the hiding done by _bfd_elf_define_linkage_sym. */
  58. h->forced_local = 0;
  59. h->other &= ~STV_HIDDEN;
  60. /* Emit it into the .dynamic section, too. */
  61. bfd_elf_link_record_dynamic_symbol (&link_info, h);
  62. }
  63. }
  64. /* Only do this if emitting a shared object and versioning is in place. */
  65. if (bfd_link_dll (&link_info)
  66. && (link_info.version_info != NULL
  67. || link_info.create_default_symver))
  68. {
  69. struct bfd_elf_version_expr *globals = NULL, *locals = NULL;
  70. struct bfd_elf_version_tree *basever;
  71. const char *soname;
  72. for (sym = global_syms; *sym != NULL; sym++)
  73. {
  74. /* Create a version pattern for this symbol. Some of them start
  75. off as local, others as global, so try both. */
  76. globals = lang_new_vers_pattern (globals, *sym, NULL, TRUE);
  77. locals = lang_new_vers_pattern (locals, *sym, NULL, TRUE);
  78. }
  79. /* New version node for those symbols. */
  80. basever = lang_new_vers_node (globals, locals);
  81. /* The version name matches what bfd_elf_size_dynamic_sections uses
  82. for the base version. */
  83. soname = bfd_elf_get_dt_soname (link_info.output_bfd);
  84. if (soname == NULL)
  85. soname = lbasename (bfd_get_filename (link_info.output_bfd));
  86. /* Register the node. */
  87. lang_register_vers_node (soname, basever, NULL);
  88. /* Enforce base version. The encoded vd_ndx is vernum + 1. */
  89. basever->vernum = 0;
  90. }
  91. gld${EMULATION_NAME}_before_allocation ();
  92. }
  93. /* The Solaris 2 ABI requires two local symbols to be emitted for every
  94. executable and shared object.
  95. Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
  96. File, p.63. */
  97. static void
  98. elf_solaris2_after_allocation (void)
  99. {
  100. /* Local symbols required by the Solaris 2 ABI. Already emitted by
  101. emulparams/solaris2.sh. */
  102. static const char *local_syms[] = {
  103. "_START_",
  104. "_END_",
  105. NULL
  106. };
  107. const char **sym;
  108. /* Do this for both executables and shared objects. */
  109. if (!bfd_link_relocatable (&link_info))
  110. {
  111. for (sym = local_syms; *sym != NULL; sym++)
  112. {
  113. struct elf_link_hash_entry *h;
  114. /* Lookup symbol. */
  115. h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
  116. FALSE, FALSE, FALSE);
  117. if (h == NULL)
  118. continue;
  119. /* Turn it local. */
  120. h->forced_local = 1;
  121. /* Type should be STT_OBJECT, not STT_NOTYPE. */
  122. h->type = STT_OBJECT;
  123. }
  124. }
  125. gld${EMULATION_NAME}_after_allocation ();
  126. }
  127. EOF
  128. LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation
  129. LDEMUL_AFTER_ALLOCATION=elf_solaris2_after_allocation