Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/bfd/cpu-arc.c
Line
Count
Source (jump to first uncovered line)
1
/* BFD support for the ARC processor
2
   Copyright (C) 1994-2025 Free Software Foundation, Inc.
3
   Contributed by Doug Evans (dje@cygnus.com).
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "bfd.h"
24
#include "libbfd.h"
25
26
static const bfd_arch_info_type *
27
arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b);
28
29
#define ARC(mach, print_name, default_p, next) \
30
  {                \
31
    32, /* Bits in a word.  */    \
32
    32, /* Bits in an address.  */  \
33
    8,  /* Bits in a byte.  */    \
34
    bfd_arch_arc,     \
35
    mach,       \
36
    "arc",        \
37
    print_name,       \
38
    4, /* Section alignment power.  */  \
39
    default_p,        \
40
    arc_compatible,     \
41
    bfd_default_scan,     \
42
    bfd_arch_default_fill,    \
43
    next,       \
44
    0 /* Maximum offset of a reloc from the start of an insn.  */ \
45
  }
46
47
static const bfd_arch_info_type arch_info_struct[] =
48
{
49
  ARC (bfd_mach_arc_arc600, "A6"    , false, &arch_info_struct[1]),
50
  ARC (bfd_mach_arc_arc601, "ARC601", false, &arch_info_struct[2]),
51
  ARC (bfd_mach_arc_arc700, "ARC700", false, &arch_info_struct[3]),
52
  ARC (bfd_mach_arc_arc700, "A7",     false, &arch_info_struct[4]),
53
  ARC (bfd_mach_arc_arcv2,  "ARCv2",  false, &arch_info_struct[5]),
54
  ARC (bfd_mach_arc_arcv2,  "EM",     false, &arch_info_struct[6]),
55
  ARC (bfd_mach_arc_arcv2,  "HS",     false, NULL),
56
};
57
58
const bfd_arch_info_type bfd_arc_arch =
59
  ARC (bfd_mach_arc_arc600, "ARC600", true, &arch_info_struct[0]);
60
61
/* ARC-specific "compatible" function.  The general rule is that if A and B are
62
   compatible, then this function should return architecture that is more
63
   "feature-rich", that is, can run both A and B.  ARCv2, EM and HS all has
64
   same mach number, so bfd_default_compatible assumes they are the same, and
65
   returns an A.  That causes issues with GDB, because GDB assumes that if
66
   machines are compatible, then "compatible ()" always returns same machine
67
   regardless of argument order.  As a result GDB gets confused because, for
68
   example, compatible (ARCv2, EM) returns ARCv2, but compatible (EM, ARCv2)
69
   returns EM, hence GDB is not sure if they are compatible and prints a
70
   warning.  */
71
72
static const bfd_arch_info_type *
73
arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
74
0
{
75
0
  const bfd_arch_info_type * const em = &arch_info_struct[5];
76
0
  const bfd_arch_info_type * const hs = &arch_info_struct[6];
77
78
  /* Trivial case where a and b is the same instance.  Some callers already
79
     check this condition but some do not and get an invalid result.  */
80
0
  if (a == b)
81
0
    return a;
82
83
  /* If a & b are for different architecture we can do nothing.  */
84
0
  if (a->arch != b->arch)
85
0
    return NULL;
86
87
0
  if (a->bits_per_word != b->bits_per_word)
88
0
    return NULL;
89
90
  /* ARCv2|EM and EM.  */
91
0
  if ((a->mach == bfd_mach_arc_arcv2 && b == em)
92
0
      || (b->mach == bfd_mach_arc_arcv2 && a == em))
93
0
    return em;
94
95
  /* ARCv2|HS and HS.  */
96
0
  if ((a->mach == bfd_mach_arc_arcv2 && b == hs)
97
0
      || (b->mach == bfd_mach_arc_arcv2 && a == hs))
98
0
    return hs;
99
100
0
  return bfd_default_compatible (a, b);
101
0
}