/src/binutils-gdb/bfd/coff-bfd.c
Line | Count | Source |
1 | | /* BFD COFF interfaces used outside of BFD. |
2 | | Copyright (C) 1990-2026 Free Software Foundation, Inc. |
3 | | Written by Cygnus Support. |
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 | | #include "coff/internal.h" |
26 | | #include "libcoff.h" |
27 | | |
28 | | /* Return the COFF syment for a symbol. */ |
29 | | |
30 | | bool |
31 | | bfd_coff_get_syment (bfd *abfd, |
32 | | asymbol *symbol, |
33 | | struct internal_syment *psyment) |
34 | 8.86k | { |
35 | 8.86k | coff_symbol_type *csym; |
36 | | |
37 | 8.86k | csym = coff_symbol_from (symbol); |
38 | 8.86k | if (csym == NULL || csym->native == NULL |
39 | 8.86k | || ! csym->native->is_sym) |
40 | 0 | { |
41 | 0 | bfd_set_error (bfd_error_invalid_operation); |
42 | 0 | return false; |
43 | 0 | } |
44 | | |
45 | 8.86k | *psyment = csym->native->u.syment; |
46 | | |
47 | 8.86k | if (csym->native->fix_value) |
48 | 0 | { |
49 | 0 | psyment->n_value = |
50 | 0 | ((psyment->n_value - (uintptr_t) obj_raw_syments (abfd)) |
51 | 0 | / sizeof (combined_entry_type)); |
52 | 0 | csym->native->fix_value = 0; |
53 | 0 | } |
54 | | |
55 | | /* FIXME: We should handle fix_line here. */ |
56 | | |
57 | 8.86k | return true; |
58 | 8.86k | } |
59 | | |
60 | | /* Return the COFF auxent for a symbol. */ |
61 | | |
62 | | bool |
63 | | bfd_coff_get_auxent (bfd *abfd, |
64 | | asymbol *symbol, |
65 | | int indx, |
66 | | union internal_auxent *pauxent) |
67 | 704 | { |
68 | 704 | coff_symbol_type *csym; |
69 | 704 | combined_entry_type *ent; |
70 | | |
71 | 704 | csym = coff_symbol_from (symbol); |
72 | | |
73 | 704 | if (csym == NULL |
74 | 704 | || csym->native == NULL |
75 | 704 | || ! csym->native->is_sym |
76 | 704 | || indx >= csym->native->u.syment.n_numaux) |
77 | 0 | { |
78 | 0 | bfd_set_error (bfd_error_invalid_operation); |
79 | 0 | return false; |
80 | 0 | } |
81 | | |
82 | 704 | ent = csym->native + indx + 1; |
83 | | |
84 | 704 | BFD_ASSERT (! ent->is_sym); |
85 | 704 | *pauxent = ent->u.auxent; |
86 | | |
87 | 704 | if (ent->fix_tag) |
88 | 138 | { |
89 | 138 | pauxent->x_sym.x_tagndx.u32 = |
90 | 138 | ((combined_entry_type *) pauxent->x_sym.x_tagndx.p |
91 | 138 | - obj_raw_syments (abfd)); |
92 | 138 | ent->fix_tag = 0; |
93 | 138 | } |
94 | | |
95 | 704 | if (ent->fix_end) |
96 | 4 | { |
97 | 4 | pauxent->x_sym.x_fcnary.x_fcn.x_endndx.u32 = |
98 | 4 | ((combined_entry_type *) pauxent->x_sym.x_fcnary.x_fcn.x_endndx.p |
99 | 4 | - obj_raw_syments (abfd)); |
100 | 4 | ent->fix_end = 0; |
101 | 4 | } |
102 | | |
103 | 704 | if (ent->fix_scnlen) |
104 | 0 | { |
105 | 0 | pauxent->x_csect.x_scnlen.u64 = |
106 | 0 | ((combined_entry_type *) pauxent->x_csect.x_scnlen.p |
107 | 0 | - obj_raw_syments (abfd)); |
108 | 0 | ent->fix_scnlen = 0; |
109 | 0 | } |
110 | | |
111 | 704 | return true; |
112 | 704 | } |
113 | | |
114 | | /* Return TRUE if SYMBOL is a PE weak external whose fallback symbol is |
115 | | a real definition. A weak declaration with no fallback uses the COFF |
116 | | null symbol as its fallback; do not treat that as an archive provider. */ |
117 | | |
118 | | bool |
119 | | bfd_coff_pe_weak_external_has_real_fallback (bfd *abfd, |
120 | | asymbol *symbol) |
121 | 864 | { |
122 | 864 | coff_symbol_type *csym; |
123 | 864 | combined_entry_type *aux; |
124 | 864 | combined_entry_type *fallback; |
125 | | |
126 | 864 | if (bfd_get_flavour (abfd) != bfd_target_coff_flavour |
127 | 271 | || coff_data (abfd) == NULL |
128 | 271 | || ! obj_pe (abfd)) |
129 | 595 | return false; |
130 | | |
131 | 269 | csym = coff_symbol_from (symbol); |
132 | 269 | if (csym == NULL |
133 | 269 | || csym->native == NULL |
134 | 269 | || ! csym->native->is_sym |
135 | 269 | || csym->native->u.syment.n_sclass != C_NT_WEAK |
136 | 0 | || csym->native->u.syment.n_numaux != 1) |
137 | 269 | return false; |
138 | | |
139 | 0 | aux = csym->native + 1; |
140 | 0 | if (aux->is_sym) |
141 | 0 | return false; |
142 | | |
143 | 0 | if (aux->fix_tag) |
144 | 0 | fallback = (combined_entry_type *) aux->u.auxent.x_sym.x_tagndx.p; |
145 | 0 | else |
146 | 0 | { |
147 | 0 | uint32_t tagndx = aux->u.auxent.x_sym.x_tagndx.u32; |
148 | |
|
149 | 0 | if (tagndx >= obj_raw_syment_count (abfd)) |
150 | 0 | return false; |
151 | 0 | fallback = obj_raw_syments (abfd) + tagndx; |
152 | 0 | } |
153 | | |
154 | 0 | return (fallback != NULL |
155 | 0 | && fallback->is_sym |
156 | 0 | && fallback->u.syment.n_scnum != N_UNDEF |
157 | 0 | && !(fallback->u.syment.n_scnum == N_ABS |
158 | 0 | && fallback->u.syment.n_value == 0)); |
159 | 0 | } |