Home | History | Annotate | Line # | Download | only in bfd
      1      1.1  christos /* BFD back-end for LoongArch64 COFF files.
      2  1.1.1.2  christos    Copyright (C) 2022-2024 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      5      1.1  christos 
      6      1.1  christos    This program is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      9      1.1  christos    (at your option) any later version.
     10      1.1  christos 
     11      1.1  christos    This program is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with this program; if not, write to the Free Software
     18      1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19      1.1  christos    MA 02110-1301, USA.  */
     20      1.1  christos 
     21      1.1  christos 
     22      1.1  christos #ifndef COFF_WITH_peLoongArch64
     23      1.1  christos #define COFF_WITH_peLoongArch64
     24      1.1  christos #endif
     25      1.1  christos 
     26      1.1  christos #include "sysdep.h"
     27      1.1  christos #include "bfd.h"
     28      1.1  christos #include "libbfd.h"
     29      1.1  christos #include "coff/loongarch64.h"
     30      1.1  christos #include "coff/internal.h"
     31      1.1  christos #include "coff/pe.h"
     32      1.1  christos #include "libcoff.h"
     33      1.1  christos #include "libiberty.h"
     34      1.1  christos 
     35      1.1  christos /* The page size is a guess based on ELF.  */
     36      1.1  christos 
     37      1.1  christos #define COFF_PAGE_SIZE 0x4000
     38      1.1  christos 
     39      1.1  christos /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
     40      1.1  christos #define OCTETS_PER_BYTE(ABFD, SEC) 1
     41      1.1  christos 
     42      1.1  christos #ifndef PCRELOFFSET
     43      1.1  christos #define PCRELOFFSET true
     44      1.1  christos #endif
     45      1.1  christos 
     46      1.1  christos /* Currently we don't handle any relocations.  */
     47      1.1  christos static reloc_howto_type pe_loongarch64_std_reloc_howto[] =
     48      1.1  christos   {
     49      1.1  christos 
     50      1.1  christos   };
     51      1.1  christos 
     52      1.1  christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  2
     53      1.1  christos 
     54      1.1  christos #ifndef NUM_ELEM
     55      1.1  christos #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
     56      1.1  christos #endif
     57      1.1  christos 
     58      1.1  christos #define NUM_RELOCS NUM_ELEM (pe_loongarch64_std_reloc_howto)
     59      1.1  christos 
     60      1.1  christos #define RTYPE2HOWTO(cache_ptr, dst)             \
     61      1.1  christos   (cache_ptr)->howto = NULL
     62      1.1  christos 
     63      1.1  christos #ifndef bfd_pe_print_pdata
     64      1.1  christos #define bfd_pe_print_pdata      NULL
     65      1.1  christos #endif
     66      1.1  christos 
     67      1.1  christos /* Handle include/coff/loongarch64.h external_reloc.  */
     68      1.1  christos #define SWAP_IN_RELOC_OFFSET	H_GET_32
     69      1.1  christos #define SWAP_OUT_RELOC_OFFSET	H_PUT_32
     70      1.1  christos 
     71      1.1  christos /* Return TRUE if this relocation should
     72      1.1  christos    appear in the output .reloc section.  */
     73      1.1  christos 
     74      1.1  christos static bool
     75      1.1  christos in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
     76      1.1  christos 	    reloc_howto_type * howto)
     77      1.1  christos {
     78      1.1  christos   return !howto->pc_relative;
     79      1.1  christos }
     80      1.1  christos 
     81      1.1  christos #include "coffcode.h"
     82      1.1  christos 
     83      1.1  christos /* Target vectors.  */
     84      1.1  christos const bfd_target
     85      1.1  christos #ifdef TARGET_SYM
     86      1.1  christos   TARGET_SYM =
     87      1.1  christos #else
     88      1.1  christos   loongarch64_pei_vec =
     89      1.1  christos #endif
     90      1.1  christos {
     91      1.1  christos #ifdef TARGET_NAME
     92      1.1  christos   TARGET_NAME,
     93      1.1  christos #else
     94      1.1  christos  "pei-loongarch64",			/* Name.  */
     95      1.1  christos #endif
     96      1.1  christos   bfd_target_coff_flavour,
     97      1.1  christos   BFD_ENDIAN_LITTLE,		/* Data byte order is little.  */
     98      1.1  christos   BFD_ENDIAN_LITTLE,		/* Header byte order is little.  */
     99      1.1  christos 
    100      1.1  christos   (HAS_RELOC | EXEC_P		/* Object flags.  */
    101      1.1  christos    | HAS_LINENO | HAS_DEBUG
    102      1.1  christos    | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS),
    103      1.1  christos 
    104      1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags.  */
    105      1.1  christos #if defined(COFF_WITH_PE)
    106      1.1  christos    | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING
    107      1.1  christos #endif
    108      1.1  christos    | SEC_CODE | SEC_DATA | SEC_EXCLUDE ),
    109      1.1  christos 
    110      1.1  christos #ifdef TARGET_UNDERSCORE
    111      1.1  christos   TARGET_UNDERSCORE,		/* Leading underscore.  */
    112      1.1  christos #else
    113      1.1  christos   0,				/* Leading underscore.  */
    114      1.1  christos #endif
    115      1.1  christos   '/',				/* Ar_pad_char.  */
    116      1.1  christos   15,				/* Ar_max_namelen.  */
    117      1.1  christos   0,				/* match priority.  */
    118      1.1  christos   TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
    119      1.1  christos 
    120      1.1  christos      /* Data conversion functions.  */
    121      1.1  christos      bfd_getl64, bfd_getl_signed_64, bfd_putl64,
    122      1.1  christos      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
    123      1.1  christos      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data.  */
    124      1.1  christos      /* Header conversion functions.  */
    125      1.1  christos      bfd_getl64, bfd_getl_signed_64, bfd_putl64,
    126      1.1  christos      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
    127      1.1  christos      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs.  */
    128      1.1  christos 
    129      1.1  christos   /* Note that we allow an object file to be treated as a core file as well.  */
    130      1.1  christos   {				/* bfd_check_format.  */
    131      1.1  christos     _bfd_dummy_target,
    132      1.1  christos     coff_object_p,
    133      1.1  christos     bfd_generic_archive_p,
    134      1.1  christos     coff_object_p
    135      1.1  christos   },
    136      1.1  christos   {				/* bfd_set_format.  */
    137      1.1  christos     _bfd_bool_bfd_false_error,
    138      1.1  christos     coff_mkobject,
    139      1.1  christos     _bfd_generic_mkarchive,
    140      1.1  christos     _bfd_bool_bfd_false_error
    141      1.1  christos   },
    142      1.1  christos   {				/* bfd_write_contents.  */
    143      1.1  christos     _bfd_bool_bfd_false_error,
    144      1.1  christos     coff_write_object_contents,
    145      1.1  christos     _bfd_write_archive_contents,
    146      1.1  christos     _bfd_bool_bfd_false_error
    147      1.1  christos   },
    148      1.1  christos 
    149      1.1  christos   BFD_JUMP_TABLE_GENERIC (coff),
    150      1.1  christos   BFD_JUMP_TABLE_COPY (coff),
    151      1.1  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
    152      1.1  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
    153      1.1  christos   BFD_JUMP_TABLE_SYMBOLS (coff),
    154      1.1  christos   BFD_JUMP_TABLE_RELOCS (coff),
    155      1.1  christos   BFD_JUMP_TABLE_WRITE (coff),
    156      1.1  christos   BFD_JUMP_TABLE_LINK (coff),
    157      1.1  christos   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
    158      1.1  christos 
    159      1.1  christos   NULL,
    160      1.1  christos 
    161      1.1  christos   COFF_SWAP_TABLE
    162      1.1  christos };
    163