pe-x86_64.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* BFD back-end for Intel/AMD x86_64 PECOFF files.
  2. Copyright (C) 2006-2022 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. Written by Kai Tietz, OneVision Software GmbH&CoKg. */
  17. #define PEI_HEADERS
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "libbfd.h"
  21. #include "libiberty.h"
  22. #include "coff/x86_64.h"
  23. #include "coff/internal.h"
  24. #include "coff/pe.h"
  25. #include "libcoff.h"
  26. #define TARGET_SYM x86_64_pe_vec
  27. #define TARGET_NAME "pe-x86-64"
  28. #define TARGET_SYM_BIG x86_64_pe_big_vec
  29. #define TARGET_NAME_BIG "pe-bigobj-x86-64"
  30. #define COFF_WITH_PE
  31. #define COFF_WITH_pex64
  32. #define COFF_WITH_PE_BIGOBJ
  33. #define PCRELOFFSET true
  34. #if defined (USE_MINGW64_LEADING_UNDERSCORES)
  35. #define TARGET_UNDERSCORE '_'
  36. #else
  37. #define TARGET_UNDERSCORE 0
  38. #endif
  39. #define COFF_LONG_SECTION_NAMES
  40. #define COFF_SUPPORT_GNU_LINKONCE
  41. #define COFF_LONG_FILENAMES
  42. #define COFF_SECTION_ALIGNMENT_ENTRIES \
  43. { COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
  44. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  45. { COFF_SECTION_NAME_PARTIAL_MATCH (".data"), \
  46. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  47. { COFF_SECTION_NAME_PARTIAL_MATCH (".rdata"), \
  48. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  49. { COFF_SECTION_NAME_PARTIAL_MATCH (".text"), \
  50. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
  51. { COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
  52. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
  53. { COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
  54. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
  55. { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
  56. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
  57. { COFF_SECTION_NAME_PARTIAL_MATCH (".zdebug"), \
  58. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
  59. { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
  60. COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
  61. /* The function pex64_bfd_print_pdata is implemented in pei-x86_64.c
  62. source, but has be extended to also handle pe objects. */
  63. extern bool pex64_bfd_print_pdata (bfd *, void *);
  64. #define bfd_pe_print_pdata pex64_bfd_print_pdata
  65. static bool
  66. pex64_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
  67. {
  68. if (bfd_link_pde (info)
  69. && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
  70. {
  71. /* NB: When linking Windows x86-64 relocatable object files to
  72. generate ELF executable, create an indirect reference to
  73. __executable_start for __ImageBase to support R_AMD64_IMAGEBASE
  74. relocation which is relative to __ImageBase. */
  75. struct bfd_link_hash_entry *h, *hi;
  76. hi = bfd_link_hash_lookup (info->hash, "__ImageBase", true, false,
  77. false);
  78. if (hi->type == bfd_link_hash_new
  79. || hi->type == bfd_link_hash_undefined
  80. || hi->type == bfd_link_hash_undefweak)
  81. {
  82. h = bfd_link_hash_lookup (info->hash, "__executable_start",
  83. true, false, true);
  84. hi->type = bfd_link_hash_indirect;
  85. hi->u.i.link = h;
  86. }
  87. }
  88. return _bfd_coff_link_add_symbols (abfd, info);
  89. }
  90. #define coff_bfd_link_add_symbols pex64_link_add_symbols
  91. #include "coff-x86_64.c"