1 /* BFD back-end for AMD 64 COFF files.
2 Copyright (C) 2006-2022 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 Written by Kai Tietz, OneVision Software GmbH&CoKg. */
23 /* Note we have to make sure not to include headers twice.
24 Not all headers are wrapped in #ifdef guards, so we define
25 PEI_HEADERS to prevent double including here. */
30 #include "coff/x86_64.h"
31 #include "coff/internal.h"
33 #include "libiberty.h"
36 #define BADMAG(x) AMD64BADMAG(x)
38 #ifdef COFF_WITH_pex64
40 # define AOUTSZ PEPAOUTSZ
41 # define PEAOUTHDR PEPAOUTHDR
44 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
46 /* The page size is a guess based on ELF. */
48 #define COFF_PAGE_SIZE 0x1000
50 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
51 #define OCTETS_PER_BYTE(ABFD, SEC) 1
53 /* For some reason when using AMD COFF the value stored in the .text
54 section for a reference to a common symbol is the value itself plus
55 any desired offset. Ian Taylor, Cygnus Support. */
57 /* If we are producing relocatable output, we need to do some
58 adjustments to the object file that are not done by the
59 bfd_perform_relocation function. This function is called by every
60 reloc type to make any required adjustments. */
62 static bfd_reloc_status_type
63 coff_amd64_reloc (bfd
*abfd
,
67 asection
*input_section ATTRIBUTE_UNUSED
,
69 char **error_message ATTRIBUTE_UNUSED
)
73 #if !defined (COFF_WITH_PE)
74 if (output_bfd
== NULL
)
75 return bfd_reloc_continue
;
78 if (bfd_is_com_section (symbol
->section
))
80 #if !defined (COFF_WITH_PE)
81 /* We are relocating a common symbol. The current value in the
82 object file is ORIG + OFFSET, where ORIG is the value of the
83 common symbol as seen by the object file when it was compiled
84 (this may be zero if the symbol was undefined) and OFFSET is
85 the offset into the common symbol (normally zero, but may be
86 non-zero when referring to a field in a common structure).
87 ORIG is the negative of reloc_entry->addend, which is set by
88 the CALC_ADDEND macro below. We want to replace the value in
89 the object file with NEW + OFFSET, where NEW is the value of
90 the common symbol which we are going to put in the final
91 object file. NEW is symbol->value. */
92 diff
= symbol
->value
+ reloc_entry
->addend
;
94 /* In PE mode, we do not offset the common symbol. */
95 diff
= reloc_entry
->addend
;
100 /* For some reason bfd_perform_relocation always effectively
101 ignores the addend for a COFF target when producing
102 relocatable output. This seems to be always wrong for 386
103 COFF, so we handle the addend here instead. */
104 #if defined (COFF_WITH_PE)
105 if (output_bfd
== NULL
)
107 if (symbol
->flags
& BSF_WEAK
)
108 diff
= reloc_entry
->addend
- symbol
->value
;
110 diff
= -reloc_entry
->addend
;
114 diff
= reloc_entry
->addend
;
117 #if defined (COFF_WITH_PE)
118 if (output_bfd
== NULL
)
120 /* PC relative relocations are off by their size. */
121 if (reloc_entry
->howto
->pc_relative
)
122 diff
-= bfd_get_reloc_size (reloc_entry
->howto
);
124 if (reloc_entry
->howto
->type
>= R_AMD64_PCRLONG_1
125 && reloc_entry
->howto
->type
<= R_AMD64_PCRLONG_5
)
126 diff
-= reloc_entry
->howto
->type
- R_AMD64_PCRLONG
;
129 if (reloc_entry
->howto
->type
== R_AMD64_IMAGEBASE
130 && output_bfd
== NULL
)
132 bfd
*obfd
= input_section
->output_section
->owner
;
133 struct bfd_link_info
*link_info
;
134 struct bfd_link_hash_entry
*h
;
135 switch (bfd_get_flavour (obfd
))
137 case bfd_target_coff_flavour
:
138 diff
-= pe_data (obfd
)->pe_opthdr
.ImageBase
;
140 case bfd_target_elf_flavour
:
141 /* Subtract __ImageBase. */
142 link_info
= _bfd_get_link_info (obfd
);
143 if (link_info
== NULL
)
144 return bfd_reloc_dangerous
;
145 h
= bfd_link_hash_lookup (link_info
->hash
, "__ImageBase",
146 false, false, false);
148 return bfd_reloc_dangerous
;
149 while (h
->type
== bfd_link_hash_indirect
)
151 /* ELF symbols in relocatable files are section relative,
152 but in nonrelocatable files they are virtual addresses. */
153 diff
-= (h
->u
.def
.value
154 + h
->u
.def
.section
->output_offset
155 + h
->u
.def
.section
->output_section
->vma
);
164 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
168 reloc_howto_type
*howto
= reloc_entry
->howto
;
169 bfd_size_type octets
= (reloc_entry
->address
170 * OCTETS_PER_BYTE (abfd
, input_section
));
171 unsigned char *addr
= (unsigned char *) data
+ octets
;
173 if (!bfd_reloc_offset_in_range (howto
, abfd
, input_section
, octets
))
174 return bfd_reloc_outofrange
;
180 char x
= bfd_get_8 (abfd
, addr
);
182 bfd_put_8 (abfd
, x
, addr
);
188 short x
= bfd_get_16 (abfd
, addr
);
190 bfd_put_16 (abfd
, (bfd_vma
) x
, addr
);
196 long x
= bfd_get_32 (abfd
, addr
);
198 bfd_put_32 (abfd
, (bfd_vma
) x
, addr
);
204 bfd_uint64_t x
= bfd_get_64 (abfd
, addr
);
206 bfd_put_64 (abfd
, x
, addr
);
211 bfd_set_error (bfd_error_bad_value
);
212 return bfd_reloc_notsupported
;
216 /* Now let bfd_perform_relocation finish everything up. */
217 return bfd_reloc_continue
;
220 #if defined(COFF_WITH_PE)
221 /* Return TRUE if this relocation should appear in the output .reloc
225 in_reloc_p (bfd
*abfd ATTRIBUTE_UNUSED
, reloc_howto_type
*howto
)
227 return ! howto
->pc_relative
&& howto
->type
!= R_AMD64_IMAGEBASE
228 && howto
->type
!= R_AMD64_SECREL
;
230 #endif /* COFF_WITH_PE */
233 #define PCRELOFFSET true
236 static reloc_howto_type howto_table
[] =
239 HOWTO (R_AMD64_DIR64
, /* type 1*/
241 4, /* size (0 = byte, 1 = short, 2 = long, 4 = long long) */
243 false, /* pc_relative */
245 complain_overflow_bitfield
, /* complain_on_overflow */
246 coff_amd64_reloc
, /* special_function */
247 "IMAGE_REL_AMD64_ADDR64", /* name */
248 true, /* partial_inplace */
249 0xffffffffffffffffll
, /* src_mask */
250 0xffffffffffffffffll
, /* dst_mask */
251 true), /* pcrel_offset */
252 HOWTO (R_AMD64_DIR32
, /* type 2 */
254 2, /* size (0 = byte, 1 = short, 2 = long) */
256 false, /* pc_relative */
258 complain_overflow_bitfield
, /* complain_on_overflow */
259 coff_amd64_reloc
, /* special_function */
260 "IMAGE_REL_AMD64_ADDR32", /* name */
261 true, /* partial_inplace */
262 0xffffffff, /* src_mask */
263 0xffffffff, /* dst_mask */
264 true), /* pcrel_offset */
265 /* PE IMAGE_REL_AMD64_ADDR32NB relocation (3). */
266 HOWTO (R_AMD64_IMAGEBASE
, /* type */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
270 false, /* pc_relative */
272 complain_overflow_bitfield
, /* complain_on_overflow */
273 coff_amd64_reloc
, /* special_function */
274 "IMAGE_REL_AMD64_ADDR32NB", /* name */
275 true, /* partial_inplace */
276 0xffffffff, /* src_mask */
277 0xffffffff, /* dst_mask */
278 false), /* pcrel_offset */
279 /* 32-bit longword PC relative relocation (4). */
280 HOWTO (R_AMD64_PCRLONG
, /* type 4 */
282 2, /* size (0 = byte, 1 = short, 2 = long) */
284 true, /* pc_relative */
286 complain_overflow_signed
, /* complain_on_overflow */
287 coff_amd64_reloc
, /* special_function */
288 "IMAGE_REL_AMD64_REL32", /* name */
289 true, /* partial_inplace */
290 0xffffffff, /* src_mask */
291 0xffffffff, /* dst_mask */
292 PCRELOFFSET
), /* pcrel_offset */
294 HOWTO (R_AMD64_PCRLONG_1
, /* type 5 */
296 2, /* size (0 = byte, 1 = short, 2 = long) */
298 true, /* pc_relative */
300 complain_overflow_signed
, /* complain_on_overflow */
301 coff_amd64_reloc
, /* special_function */
302 "IMAGE_REL_AMD64_REL32_1", /* name */
303 true, /* partial_inplace */
304 0xffffffff, /* src_mask */
305 0xffffffff, /* dst_mask */
306 PCRELOFFSET
), /* pcrel_offset */
307 HOWTO (R_AMD64_PCRLONG_2
, /* type 6 */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 true, /* pc_relative */
313 complain_overflow_signed
, /* complain_on_overflow */
314 coff_amd64_reloc
, /* special_function */
315 "IMAGE_REL_AMD64_REL32_2", /* name */
316 true, /* partial_inplace */
317 0xffffffff, /* src_mask */
318 0xffffffff, /* dst_mask */
319 PCRELOFFSET
), /* pcrel_offset */
320 HOWTO (R_AMD64_PCRLONG_3
, /* type 7 */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 true, /* pc_relative */
326 complain_overflow_signed
, /* complain_on_overflow */
327 coff_amd64_reloc
, /* special_function */
328 "IMAGE_REL_AMD64_REL32_3", /* name */
329 true, /* partial_inplace */
330 0xffffffff, /* src_mask */
331 0xffffffff, /* dst_mask */
332 PCRELOFFSET
), /* pcrel_offset */
333 HOWTO (R_AMD64_PCRLONG_4
, /* type 8 */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 true, /* pc_relative */
339 complain_overflow_signed
, /* complain_on_overflow */
340 coff_amd64_reloc
, /* special_function */
341 "IMAGE_REL_AMD64_REL32_4", /* name */
342 true, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 PCRELOFFSET
), /* pcrel_offset */
346 HOWTO (R_AMD64_PCRLONG_5
, /* type 9 */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 true, /* pc_relative */
352 complain_overflow_signed
, /* complain_on_overflow */
353 coff_amd64_reloc
, /* special_function */
354 "IMAGE_REL_AMD64_REL32_5", /* name */
355 true, /* partial_inplace */
356 0xffffffff, /* src_mask */
357 0xffffffff, /* dst_mask */
358 PCRELOFFSET
), /* pcrel_offset */
359 EMPTY_HOWTO (10), /* R_AMD64_SECTION 10 */
360 #if defined(COFF_WITH_PE)
361 /* 32-bit longword section relative relocation (11). */
362 HOWTO (R_AMD64_SECREL
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 false, /* pc_relative */
368 complain_overflow_bitfield
, /* complain_on_overflow */
369 coff_amd64_reloc
, /* special_function */
370 "IMAGE_REL_AMD64_SECREL", /* name */
371 true, /* partial_inplace */
372 0xffffffff, /* src_mask */
373 0xffffffff, /* dst_mask */
374 true), /* pcrel_offset */
380 #ifndef DONT_EXTEND_AMD64
381 HOWTO (R_AMD64_PCRQUAD
,
383 4, /* size (0 = byte, 1 = short, 2 = long) */
385 true, /* pc_relative */
387 complain_overflow_signed
, /* complain_on_overflow */
388 coff_amd64_reloc
, /* special_function */
389 "R_X86_64_PC64", /* name */
390 true, /* partial_inplace */
391 0xffffffffffffffffll
, /* src_mask */
392 0xffffffffffffffffll
, /* dst_mask */
393 PCRELOFFSET
), /* pcrel_offset */
397 /* Byte relocation (15). */
398 HOWTO (R_RELBYTE
, /* type */
400 0, /* size (0 = byte, 1 = short, 2 = long) */
402 false, /* pc_relative */
404 complain_overflow_bitfield
, /* complain_on_overflow */
405 coff_amd64_reloc
, /* special_function */
406 "R_X86_64_8", /* name */
407 true, /* partial_inplace */
408 0x000000ff, /* src_mask */
409 0x000000ff, /* dst_mask */
410 PCRELOFFSET
), /* pcrel_offset */
411 /* 16-bit word relocation (16). */
412 HOWTO (R_RELWORD
, /* type */
414 1, /* size (0 = byte, 1 = short, 2 = long) */
416 false, /* pc_relative */
418 complain_overflow_bitfield
, /* complain_on_overflow */
419 coff_amd64_reloc
, /* special_function */
420 "R_X86_64_16", /* name */
421 true, /* partial_inplace */
422 0x0000ffff, /* src_mask */
423 0x0000ffff, /* dst_mask */
424 PCRELOFFSET
), /* pcrel_offset */
425 /* 32-bit longword relocation (17). */
426 HOWTO (R_RELLONG
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_bitfield
, /* complain_on_overflow */
433 coff_amd64_reloc
, /* special_function */
434 "R_X86_64_32S", /* name */
435 true, /* partial_inplace */
436 0xffffffff, /* src_mask */
437 0xffffffff, /* dst_mask */
438 PCRELOFFSET
), /* pcrel_offset */
439 /* Byte PC relative relocation (18). */
440 HOWTO (R_PCRBYTE
, /* type */
442 0, /* size (0 = byte, 1 = short, 2 = long) */
444 true, /* pc_relative */
446 complain_overflow_signed
, /* complain_on_overflow */
447 coff_amd64_reloc
, /* special_function */
448 "R_X86_64_PC8", /* name */
449 true, /* partial_inplace */
450 0x000000ff, /* src_mask */
451 0x000000ff, /* dst_mask */
452 PCRELOFFSET
), /* pcrel_offset */
453 /* 16-bit word PC relative relocation (19). */
454 HOWTO (R_PCRWORD
, /* type */
456 1, /* size (0 = byte, 1 = short, 2 = long) */
458 true, /* pc_relative */
460 complain_overflow_signed
, /* complain_on_overflow */
461 coff_amd64_reloc
, /* special_function */
462 "R_X86_64_PC16", /* name */
463 true, /* partial_inplace */
464 0x0000ffff, /* src_mask */
465 0x0000ffff, /* dst_mask */
466 PCRELOFFSET
), /* pcrel_offset */
467 /* 32-bit longword PC relative relocation (20). */
468 HOWTO (R_PCRLONG
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 true, /* pc_relative */
474 complain_overflow_signed
, /* complain_on_overflow */
475 coff_amd64_reloc
, /* special_function */
476 "R_X86_64_PC32", /* name */
477 true, /* partial_inplace */
478 0xffffffff, /* src_mask */
479 0xffffffff, /* dst_mask */
480 PCRELOFFSET
) /* pcrel_offset */
483 #define NUM_HOWTOS ARRAY_SIZE (howto_table)
485 /* Turn a howto into a reloc nunmber */
487 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
488 #define I386 1 /* Customize coffcode.h */
491 #define RTYPE2HOWTO(cache_ptr, dst) \
492 ((cache_ptr)->howto = \
493 ((dst)->r_type < NUM_HOWTOS) \
494 ? howto_table + (dst)->r_type \
497 /* For 386 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
498 library. On some other COFF targets STYP_BSS is normally
500 #define BSS_NOLOAD_IS_SHARED_LIBRARY
502 /* Compute the addend of a reloc. If the reloc is to a common symbol,
503 the object file contains the value of the common symbol. By the
504 time this is called, the linker may be using a different symbol
505 from a different object file with a different value. Therefore, we
506 hack wildly to locate the original symbol from this file so that we
507 can make the correct adjustment. This macro sets coffsym to the
508 symbol from the original file, and uses it to set the addend value
509 correctly. If this is not a common symbol, the usual addend
510 calculation is done, except that an additional tweak is needed for
512 FIXME: This macro refers to symbols and asect; these are from the
513 calling function, not the macro arguments. */
515 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
517 coff_symbol_type *coffsym = NULL; \
519 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
520 coffsym = (obj_symbols (abfd) \
521 + (cache_ptr->sym_ptr_ptr - symbols)); \
523 coffsym = coff_symbol_from (ptr); \
525 if (coffsym != NULL \
526 && coffsym->native->u.syment.n_scnum == 0) \
527 cache_ptr->addend = - coffsym->native->u.syment.n_value; \
528 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
529 && ptr->section != NULL) \
530 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
532 cache_ptr->addend = 0; \
533 if (ptr && reloc.r_type < NUM_HOWTOS \
534 && howto_table[reloc.r_type].pc_relative) \
535 cache_ptr->addend += asect->vma; \
538 /* We use the special COFF backend linker. For normal AMD64 COFF, we
539 can use the generic relocate_section routine. For PE, we need our
542 #if !defined(COFF_WITH_PE)
544 #define coff_relocate_section _bfd_coff_generic_relocate_section
546 #else /* COFF_WITH_PE */
548 /* The PE relocate section routine. The only difference between this
549 and the regular routine is that we don't want to do anything for a
553 coff_pe_amd64_relocate_section (bfd
*output_bfd
,
554 struct bfd_link_info
*info
,
556 asection
*input_section
,
558 struct internal_reloc
*relocs
,
559 struct internal_syment
*syms
,
562 if (bfd_link_relocatable (info
))
565 return _bfd_coff_generic_relocate_section (output_bfd
, info
, input_bfd
,input_section
, contents
,relocs
, syms
, sections
);
568 #define coff_relocate_section coff_pe_amd64_relocate_section
570 #endif /* COFF_WITH_PE */
572 /* Convert an rtype to howto for the COFF backend linker. */
574 static reloc_howto_type
*
575 coff_amd64_rtype_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
577 struct internal_reloc
*rel
,
578 struct coff_link_hash_entry
*h
,
579 struct internal_syment
*sym
,
582 reloc_howto_type
*howto
;
584 if (rel
->r_type
>= NUM_HOWTOS
)
586 bfd_set_error (bfd_error_bad_value
);
589 howto
= howto_table
+ rel
->r_type
;
591 #if defined(COFF_WITH_PE)
592 /* Cancel out code in _bfd_coff_generic_relocate_section. */
594 if (rel
->r_type
>= R_AMD64_PCRLONG_1
&& rel
->r_type
<= R_AMD64_PCRLONG_5
)
596 *addendp
-= (bfd_vma
)(rel
->r_type
- R_AMD64_PCRLONG
);
597 rel
->r_type
= R_AMD64_PCRLONG
;
601 if (howto
->pc_relative
)
602 *addendp
+= sec
->vma
;
604 if (sym
!= NULL
&& sym
->n_scnum
== 0 && sym
->n_value
!= 0)
606 /* This is a common symbol. The section contents include the
607 size (sym->n_value) as an addend. The relocate_section
608 function will be adding in the final value of the symbol. We
609 need to subtract out the current size in order to get the
611 BFD_ASSERT (h
!= NULL
);
613 #if !defined(COFF_WITH_PE)
614 /* I think we *do* want to bypass this. If we don't, I have
615 seen some data parameters get the wrong relocation address.
616 If I link two versions with and without this section bypassed
617 and then do a binary comparison, the addresses which are
618 different can be looked up in the map. The case in which
619 this section has been bypassed has addresses which correspond
620 to values I can find in the map. */
621 *addendp
-= sym
->n_value
;
625 #if !defined(COFF_WITH_PE)
626 /* If the output symbol is common (in which case this must be a
627 relocatable link), we need to add in the final size of the
629 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_common
)
630 *addendp
+= h
->root
.u
.c
.size
;
633 #if defined(COFF_WITH_PE)
634 if (howto
->pc_relative
)
636 #ifndef DONT_EXTEND_AMD64
637 if (rel
->r_type
== R_AMD64_PCRQUAD
)
643 /* If the symbol is defined, then the generic code is going to
644 add back the symbol value in order to cancel out an
645 adjustment it made to the addend. However, we set the addend
646 to 0 at the start of this function. We need to adjust here,
647 to avoid the adjustment the generic code will make. FIXME:
648 This is getting a bit hackish. */
649 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
650 *addendp
-= sym
->n_value
;
653 if (rel
->r_type
== R_AMD64_IMAGEBASE
654 && (bfd_get_flavour (sec
->output_section
->owner
) == bfd_target_coff_flavour
))
655 *addendp
-= pe_data (sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
657 if (rel
->r_type
== R_AMD64_SECREL
)
661 if (h
&& (h
->root
.type
== bfd_link_hash_defined
662 || h
->root
.type
== bfd_link_hash_defweak
))
663 osect_vma
= h
->root
.u
.def
.section
->output_section
->vma
;
669 /* Sigh, the only way to get the section to offset against
670 is to find it the hard way. */
671 for (s
= abfd
->sections
, i
= 1; i
< sym
->n_scnum
; i
++)
674 osect_vma
= s
->output_section
->vma
;
677 *addendp
-= osect_vma
;
684 #define coff_bfd_reloc_type_lookup coff_amd64_reloc_type_lookup
685 #define coff_bfd_reloc_name_lookup coff_amd64_reloc_name_lookup
687 static reloc_howto_type
*
688 coff_amd64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_reloc_code_real_type code
)
693 return howto_table
+ R_AMD64_IMAGEBASE
;
695 return howto_table
+ R_AMD64_DIR32
;
697 return howto_table
+ R_AMD64_DIR64
;
698 case BFD_RELOC_64_PCREL
:
699 #ifndef DONT_EXTEND_AMD64
700 return howto_table
+ R_AMD64_PCRQUAD
;
704 case BFD_RELOC_32_PCREL
:
705 return howto_table
+ R_AMD64_PCRLONG
;
706 case BFD_RELOC_X86_64_32S
:
707 return howto_table
+ R_RELLONG
;
709 return howto_table
+ R_RELWORD
;
710 case BFD_RELOC_16_PCREL
:
711 return howto_table
+ R_PCRWORD
;
713 return howto_table
+ R_RELBYTE
;
714 case BFD_RELOC_8_PCREL
:
715 return howto_table
+ R_PCRBYTE
;
716 #if defined(COFF_WITH_PE)
717 case BFD_RELOC_32_SECREL
:
718 return howto_table
+ R_AMD64_SECREL
;
726 static reloc_howto_type
*
727 coff_amd64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
732 for (i
= 0; i
< NUM_HOWTOS
; i
++)
733 if (howto_table
[i
].name
!= NULL
734 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
735 return &howto_table
[i
];
740 #define coff_rtype_to_howto coff_amd64_rtype_to_howto
742 #ifdef TARGET_UNDERSCORE
744 /* If amd64 gcc uses underscores for symbol names, then it does not use
745 a leading dot for local labels, so if TARGET_UNDERSCORE is defined
746 we treat all symbols starting with L as local. */
749 coff_amd64_is_local_label_name (bfd
*abfd
, const char *name
)
754 return _bfd_coff_is_local_label_name (abfd
, name
);
757 #define coff_bfd_is_local_label_name coff_amd64_is_local_label_name
759 #endif /* TARGET_UNDERSCORE */
761 #ifndef bfd_pe_print_pdata
762 #define bfd_pe_print_pdata NULL
765 #include "coffcode.h"
768 #define amd64coff_object_p pe_bfd_object_p
770 #define amd64coff_object_p coff_object_p
783 "coff-x86-64", /* Name. */
785 bfd_target_coff_flavour
,
786 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
787 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
789 (HAS_RELOC
| EXEC_P
/* Object flags. */
790 | HAS_LINENO
| HAS_DEBUG
791 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
| BFD_COMPRESS
| BFD_DECOMPRESS
),
793 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* Section flags. */
794 #if defined(COFF_WITH_PE)
795 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
| SEC_READONLY
| SEC_DEBUGGING
797 | SEC_CODE
| SEC_DATA
| SEC_EXCLUDE
),
799 #ifdef TARGET_UNDERSCORE
800 TARGET_UNDERSCORE
, /* Leading underscore. */
802 0, /* Leading underscore. */
804 '/', /* Ar_pad_char. */
805 15, /* Ar_max_namelen. */
806 0, /* match priority. */
807 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
809 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
810 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
811 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
812 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
813 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
814 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
816 /* Note that we allow an object file to be treated as a core file as well. */
817 { /* bfd_check_format. */
820 bfd_generic_archive_p
,
823 { /* bfd_set_format. */
824 _bfd_bool_bfd_false_error
,
826 _bfd_generic_mkarchive
,
827 _bfd_bool_bfd_false_error
829 { /* bfd_write_contents. */
830 _bfd_bool_bfd_false_error
,
831 coff_write_object_contents
,
832 _bfd_write_archive_contents
,
833 _bfd_bool_bfd_false_error
836 BFD_JUMP_TABLE_GENERIC (coff
),
837 BFD_JUMP_TABLE_COPY (coff
),
838 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
839 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
840 BFD_JUMP_TABLE_SYMBOLS (coff
),
841 BFD_JUMP_TABLE_RELOCS (coff
),
842 BFD_JUMP_TABLE_WRITE (coff
),
843 BFD_JUMP_TABLE_LINK (coff
),
844 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
851 /* Entry for big object files. */
853 #ifdef COFF_WITH_PE_BIGOBJ
858 bfd_target_coff_flavour
,
859 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
860 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
862 (HAS_RELOC
| EXEC_P
/* Object flags. */
863 | HAS_LINENO
| HAS_DEBUG
864 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
| BFD_COMPRESS
| BFD_DECOMPRESS
),
866 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* Section flags. */
867 #if defined(COFF_WITH_PE)
868 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
| SEC_READONLY
| SEC_DEBUGGING
870 | SEC_CODE
| SEC_DATA
| SEC_EXCLUDE
),
872 #ifdef TARGET_UNDERSCORE
873 TARGET_UNDERSCORE
, /* Leading underscore. */
875 0, /* Leading underscore. */
877 '/', /* Ar_pad_char. */
878 15, /* Ar_max_namelen. */
879 0, /* match priority. */
880 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
882 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
883 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
884 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
885 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
886 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
887 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
889 /* Note that we allow an object file to be treated as a core file as well. */
890 { /* bfd_check_format. */
893 bfd_generic_archive_p
,
896 { /* bfd_set_format. */
897 _bfd_bool_bfd_false_error
,
899 _bfd_generic_mkarchive
,
900 _bfd_bool_bfd_false_error
902 { /* bfd_write_contents. */
903 _bfd_bool_bfd_false_error
,
904 coff_write_object_contents
,
905 _bfd_write_archive_contents
,
906 _bfd_bool_bfd_false_error
909 BFD_JUMP_TABLE_GENERIC (coff
),
910 BFD_JUMP_TABLE_COPY (coff
),
911 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
912 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
913 BFD_JUMP_TABLE_SYMBOLS (coff
),
914 BFD_JUMP_TABLE_RELOCS (coff
),
915 BFD_JUMP_TABLE_WRITE (coff
),
916 BFD_JUMP_TABLE_LINK (coff
),
917 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),