175fd0b74Schristos /* BFD COFF interfaces used outside of BFD.
2*e992f068Schristos Copyright (C) 1990-2022 Free Software Foundation, Inc.
375fd0b74Schristos Written by Cygnus Support.
475fd0b74Schristos
575fd0b74Schristos This file is part of BFD, the Binary File Descriptor library.
675fd0b74Schristos
775fd0b74Schristos This program is free software; you can redistribute it and/or modify
875fd0b74Schristos it under the terms of the GNU General Public License as published by
975fd0b74Schristos the Free Software Foundation; either version 3 of the License, or
1075fd0b74Schristos (at your option) any later version.
1175fd0b74Schristos
1275fd0b74Schristos This program is distributed in the hope that it will be useful,
1375fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1475fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1575fd0b74Schristos GNU General Public License for more details.
1675fd0b74Schristos
1775fd0b74Schristos You should have received a copy of the GNU General Public License
1875fd0b74Schristos along with this program; if not, write to the Free Software
1975fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2075fd0b74Schristos MA 02110-1301, USA. */
2175fd0b74Schristos
2275fd0b74Schristos #include "sysdep.h"
2375fd0b74Schristos #include "bfd.h"
2475fd0b74Schristos #include "libbfd.h"
2575fd0b74Schristos #include "coff/internal.h"
2675fd0b74Schristos #include "libcoff.h"
2775fd0b74Schristos
2875fd0b74Schristos /* Return the COFF syment for a symbol. */
2975fd0b74Schristos
30*e992f068Schristos bool
bfd_coff_get_syment(bfd * abfd,asymbol * symbol,struct internal_syment * psyment)3175fd0b74Schristos bfd_coff_get_syment (bfd *abfd,
3275fd0b74Schristos asymbol *symbol,
3375fd0b74Schristos struct internal_syment *psyment)
3475fd0b74Schristos {
3575fd0b74Schristos coff_symbol_type *csym;
3675fd0b74Schristos
3775fd0b74Schristos csym = coff_symbol_from (symbol);
3875fd0b74Schristos if (csym == NULL || csym->native == NULL
3975fd0b74Schristos || ! csym->native->is_sym)
4075fd0b74Schristos {
4175fd0b74Schristos bfd_set_error (bfd_error_invalid_operation);
42*e992f068Schristos return false;
4375fd0b74Schristos }
4475fd0b74Schristos
4575fd0b74Schristos *psyment = csym->native->u.syment;
4675fd0b74Schristos
4775fd0b74Schristos if (csym->native->fix_value)
48*e992f068Schristos psyment->n_value =
49*e992f068Schristos ((psyment->n_value - (uintptr_t) obj_raw_syments (abfd))
50*e992f068Schristos / sizeof (combined_entry_type));
5175fd0b74Schristos
5275fd0b74Schristos /* FIXME: We should handle fix_line here. */
5375fd0b74Schristos
54*e992f068Schristos return true;
5575fd0b74Schristos }
5675fd0b74Schristos
5775fd0b74Schristos /* Return the COFF auxent for a symbol. */
5875fd0b74Schristos
59*e992f068Schristos bool
bfd_coff_get_auxent(bfd * abfd,asymbol * symbol,int indx,union internal_auxent * pauxent)6075fd0b74Schristos bfd_coff_get_auxent (bfd *abfd,
6175fd0b74Schristos asymbol *symbol,
6275fd0b74Schristos int indx,
6375fd0b74Schristos union internal_auxent *pauxent)
6475fd0b74Schristos {
6575fd0b74Schristos coff_symbol_type *csym;
6675fd0b74Schristos combined_entry_type *ent;
6775fd0b74Schristos
6875fd0b74Schristos csym = coff_symbol_from (symbol);
6975fd0b74Schristos
7075fd0b74Schristos if (csym == NULL
7175fd0b74Schristos || csym->native == NULL
7275fd0b74Schristos || ! csym->native->is_sym
7375fd0b74Schristos || indx >= csym->native->u.syment.n_numaux)
7475fd0b74Schristos {
7575fd0b74Schristos bfd_set_error (bfd_error_invalid_operation);
76*e992f068Schristos return false;
7775fd0b74Schristos }
7875fd0b74Schristos
7975fd0b74Schristos ent = csym->native + indx + 1;
8075fd0b74Schristos
8175fd0b74Schristos BFD_ASSERT (! ent->is_sym);
8275fd0b74Schristos *pauxent = ent->u.auxent;
8375fd0b74Schristos
8475fd0b74Schristos if (ent->fix_tag)
8575fd0b74Schristos pauxent->x_sym.x_tagndx.l =
8675fd0b74Schristos ((combined_entry_type *) pauxent->x_sym.x_tagndx.p
8775fd0b74Schristos - obj_raw_syments (abfd));
8875fd0b74Schristos
8975fd0b74Schristos if (ent->fix_end)
9075fd0b74Schristos pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l =
9175fd0b74Schristos ((combined_entry_type *) pauxent->x_sym.x_fcnary.x_fcn.x_endndx.p
9275fd0b74Schristos - obj_raw_syments (abfd));
9375fd0b74Schristos
9475fd0b74Schristos if (ent->fix_scnlen)
9575fd0b74Schristos pauxent->x_csect.x_scnlen.l =
9675fd0b74Schristos ((combined_entry_type *) pauxent->x_csect.x_scnlen.p
9775fd0b74Schristos - obj_raw_syments (abfd));
9875fd0b74Schristos
99*e992f068Schristos return true;
10075fd0b74Schristos }
101