/* NLM (NetWare Loadable Module) executable support for BFD.
- Copyright (C) 1993 Free Software Foundation, Inc.
+ Copyright 1993, 1994, 1995, 1998, 2000 Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support, using ELF support as the
template.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#include <string.h> /* For strrchr and friends */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#define Nlm_External_Copyright_Header NlmNAME(External_Copyright_Header)
#define Nlm_External_Extended_Header NlmNAME(External_Extended_Header)
#define Nlm_External_Custom_Header NlmNAME(External_Custom_Header)
-#define Nlm_External_Cygnus_Section_Header \
- NlmNAME(External_Cygnus_Section_Header)
+#define Nlm_External_Cygnus_Ext_Header NlmNAME(External_Cygnus_Ext_Header)
#define nlm_symbol_type nlmNAME(symbol_type)
#define nlm_get_symtab_upper_bound nlmNAME(get_symtab_upper_bound)
#define nlm_write_object_contents nlmNAME(write_object_contents)
#define nlm_swap_fixed_header_in(abfd,src,dst) \
- (nlm_swap_fixed_header_in_func(abfd))(abfd,src,dst)
+ (nlm_swap_fixed_header_in_func(abfd)) (abfd,src,dst)
#define nlm_swap_fixed_header_out(abfd,src,dst) \
- (nlm_swap_fixed_header_out_func(abfd))(abfd,src,dst)
+ (nlm_swap_fixed_header_out_func(abfd)) (abfd,src,dst)
/* Forward declarations of static functions */
#define get_word bfd_h_get_32
#endif
-bfd_target *
+const bfd_target *
nlm_object_p (abfd)
bfd *abfd;
{
/* Read in the fixed length portion of the NLM header in external format. */
- x_fxdhdr = (PTR) malloc (nlm_fixed_header_size (abfd));
+ x_fxdhdr = (PTR) bfd_malloc ((size_t) nlm_fixed_header_size (abfd));
if (x_fxdhdr == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto got_no_match;
- }
+ goto got_no_match;
if (bfd_read ((PTR) x_fxdhdr, nlm_fixed_header_size (abfd), 1, abfd) !=
nlm_fixed_header_size (abfd))
new_tdata = ((struct nlm_obj_tdata *)
bfd_zalloc (abfd, sizeof (struct nlm_obj_tdata)));
if (new_tdata == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto got_no_match;
- }
+ goto got_no_match;
nlm_tdata (abfd) = new_tdata;
x_fxdhdr = NULL;
/* Check to see if we have an NLM file for this backend by matching
- the NLM signature. */
+ the NLM signature. */
signature = nlm_signature (abfd);
if (signature != NULL
/* Add the sections supplied by all NLM's, and then read in the
auxiliary headers. Reading the auxiliary headers may create
- additional sections described in the cygnus_sections header.
+ additional sections described in the cygnus_ext header.
From this point on we assume that we have an NLM, and do not
treat errors as indicating the wrong format. */
if (arch != bfd_arch_unknown)
bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
+ abfd->flags |= EXEC_P;
+ bfd_get_start_address (abfd) = nlm_fixed_header (abfd)->codeStartOffset;
+
return (abfd->xvec);
got_wrong_format_error:
return (NULL);
}
-/* Add a section to the bfd. */
+/* Add a section to the bfd. */
static boolean
add_bfd_section (abfd, name, offset, size, flags)
{
return (false);
}
- newsect->vma = 0; /* NLM's are relocatable. */
+ newsect->vma = 0; /* NLM's are relocatable. */
newsect->_raw_size = size;
newsect->filepos = offset;
newsect->flags = flags;
}
/* Read and swap in the variable length header. All the fields must
- exist in the NLM, and must exist in the order they are read here. */
+ exist in the NLM, and must exist in the order they are read here. */
static boolean
nlm_swap_variable_header_in (abfd)
{
unsigned char temp[NLM_TARGET_LONG_SIZE];
- /* Read the description length and text members. */
+ /* Read the description length and text members. */
if (bfd_read ((PTR) & nlm_variable_header (abfd)->descriptionLength,
sizeof (nlm_variable_header (abfd)->descriptionLength),
if (bfd_read ((PTR) nlm_variable_header (abfd)->descriptionText,
nlm_variable_header (abfd)->descriptionLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->descriptionLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->descriptionLength + 1)
return (false);
- /* Read and convert the stackSize field. */
+ /* Read and convert the stackSize field. */
if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
return (false);
nlm_variable_header (abfd)->stackSize = get_word (abfd, (bfd_byte *) temp);
- /* Read and convert the reserved field. */
+ /* Read and convert the reserved field. */
if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
return (false);
nlm_variable_header (abfd)->reserved = get_word (abfd, (bfd_byte *) temp);
- /* Read the oldThreadName field. This field is a fixed length string. */
+ /* Read the oldThreadName field. This field is a fixed length string. */
if (bfd_read ((PTR) nlm_variable_header (abfd)->oldThreadName,
sizeof (nlm_variable_header (abfd)->oldThreadName),
sizeof (nlm_variable_header (abfd)->oldThreadName))
return (false);
- /* Read the screen name length and text members. */
+ /* Read the screen name length and text members. */
if (bfd_read ((PTR) & nlm_variable_header (abfd)->screenNameLength,
sizeof (nlm_variable_header (abfd)->screenNameLength),
if (bfd_read ((PTR) nlm_variable_header (abfd)->screenName,
nlm_variable_header (abfd)->screenNameLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->screenNameLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->screenNameLength + 1)
return (false);
- /* Read the thread name length and text members. */
+ /* Read the thread name length and text members. */
if (bfd_read ((PTR) & nlm_variable_header (abfd)->threadNameLength,
sizeof (nlm_variable_header (abfd)->threadNameLength),
if (bfd_read ((PTR) nlm_variable_header (abfd)->threadName,
nlm_variable_header (abfd)->threadNameLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->threadNameLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->threadNameLength + 1)
return (false);
return (true);
}
{
unsigned char temp[NLM_TARGET_LONG_SIZE];
- /* Write the description length and text members. */
+ /* Write the description length and text members. */
if (bfd_write ((PTR) & nlm_variable_header (abfd)->descriptionLength,
sizeof (nlm_variable_header (abfd)->descriptionLength),
if (bfd_write ((PTR) nlm_variable_header (abfd)->descriptionText,
nlm_variable_header (abfd)->descriptionLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->descriptionLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->descriptionLength + 1)
return (false);
- /* Convert and write the stackSize field. */
+ /* Convert and write the stackSize field. */
put_word (abfd, (bfd_vma) nlm_variable_header (abfd)->stackSize,
(bfd_byte *) temp);
if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
return (false);
- /* Convert and write the reserved field. */
+ /* Convert and write the reserved field. */
put_word (abfd, (bfd_vma) nlm_variable_header (abfd)->reserved,
(bfd_byte *) temp);
if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
return (false);
- /* Write the oldThreadName field. This field is a fixed length string. */
+ /* Write the oldThreadName field. This field is a fixed length string. */
if (bfd_write ((PTR) nlm_variable_header (abfd)->oldThreadName,
sizeof (nlm_variable_header (abfd)->oldThreadName),
sizeof (nlm_variable_header (abfd)->oldThreadName))
return (false);
- /* Write the screen name length and text members. */
+ /* Write the screen name length and text members. */
if (bfd_write ((PTR) & nlm_variable_header (abfd)->screenNameLength,
sizeof (nlm_variable_header (abfd)->screenNameLength),
if (bfd_write ((PTR) nlm_variable_header (abfd)->screenName,
nlm_variable_header (abfd)->screenNameLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->screenNameLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->screenNameLength + 1)
return (false);
- /* Write the thread name length and text members. */
+ /* Write the thread name length and text members. */
if (bfd_write ((PTR) & nlm_variable_header (abfd)->threadNameLength,
sizeof (nlm_variable_header (abfd)->threadNameLength),
if (bfd_write ((PTR) nlm_variable_header (abfd)->threadName,
nlm_variable_header (abfd)->threadNameLength + 1,
1, abfd) !=
- nlm_variable_header (abfd)->threadNameLength + 1)
+ (bfd_size_type) nlm_variable_header (abfd)->threadNameLength + 1)
return (false);
return (true);
}
of the auxiliary headers are, except by finding something that doesn't
look like a known auxiliary header. This means that the first new type
of auxiliary header added will break all existing tools that don't
- recognize it. */
+ recognize it. */
static boolean
nlm_swap_auxiliary_headers_in (abfd)
nlm_extended_header (abfd)->reserved5 =
get_word (abfd, (bfd_byte *) thdr.reserved5);
}
- else if (strncmp (tempstr, "CuStHeAd", 8) == 0)
- {
- Nlm_External_Custom_Header thdr;
- if (bfd_read ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
- return false;
- memcpy (nlm_custom_header (abfd)->stamp, thdr.stamp,
- sizeof (thdr.stamp));
- nlm_custom_header (abfd)->dataLength =
- get_word (abfd, (bfd_byte *) thdr.dataLength);
- nlm_custom_header (abfd)->data =
- bfd_alloc (abfd, nlm_custom_header (abfd)->dataLength);
- if (nlm_custom_header (abfd)->data == NULL)
- return false;
- if (bfd_read (nlm_custom_header (abfd)->data, 1,
- nlm_custom_header (abfd)->dataLength, abfd)
- != nlm_custom_header (abfd)->dataLength)
- return false;
- }
else if (strncmp (tempstr, "CoPyRiGhT=", 10) == 0)
{
if (bfd_read ((PTR) nlm_copyright_header (abfd)->stamp,
->copyrightMessageLength),
1, 1, abfd) != 1)
return (false);
- /* The copyright message is a variable length string. */
+ /* The copyright message is a variable length string. */
if (bfd_read ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
nlm_copyright_header (abfd)->copyrightMessageLength + 1,
1, abfd) !=
- nlm_copyright_header (abfd)->copyrightMessageLength + 1)
+ ((bfd_size_type)
+ nlm_copyright_header (abfd)->copyrightMessageLength + 1))
return (false);
}
- else if (strncmp (tempstr, "CyGnUsSeCs", 10) == 0)
+ else if (strncmp (tempstr, "CuStHeAd", 8) == 0)
{
- Nlm_External_Cygnus_Section_Header thdr;
- bfd_size_type len;
- file_ptr pos;
- bfd_byte *contents;
- bfd_byte *p, *pend;
-
- if (bfd_read ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
+ Nlm_External_Custom_Header thdr;
+ bfd_size_type hdrLength;
+ file_ptr dataOffset;
+ bfd_size_type dataLength;
+ char dataStamp[8];
+ PTR hdr;
+
+ /* Read the stamp ("CuStHeAd"). */
+ if (bfd_read ((PTR) thdr.stamp, 1, sizeof (thdr.stamp), abfd)
+ != sizeof (thdr.stamp))
return false;
- memcpy (nlm_cygnus_section_header (abfd)->stamp, thdr.stamp,
- sizeof (thdr.stamp));
- nlm_cygnus_section_header (abfd)->offset =
- get_word (abfd, (bfd_byte *) thdr.offset);
- len = get_word (abfd, (bfd_byte *) thdr.length);
- nlm_cygnus_section_header (abfd)->length = len;
-
- /* This data this header points to provides a list of the
- sections which were in the original object file which was
- converted to become an NLM. We locate those sections and
- add them to the BFD. Note that this is likely to create
- a second .text, .data and .bss section; retrieving the
- sections by name will get the actual NLM sections, which
- is what we want to happen. The sections from the
- original file, which may be subsets of the NLM section,
- can only be found using bfd_map_over_sections. */
-
- contents = (bfd_byte *) bfd_alloc (abfd, len);
- if (contents == (bfd_byte *) NULL)
+ /* Read the length of this custom header. */
+ if (bfd_read ((PTR) thdr.length, 1, sizeof (thdr.length), abfd)
+ != sizeof (thdr.length))
+ return false;
+ hdrLength = get_word (abfd, (bfd_byte *) thdr.length);
+ /* Read further fields if we have them. */
+ if (hdrLength < NLM_TARGET_LONG_SIZE)
+ dataOffset = 0;
+ else
{
- bfd_set_error (bfd_error_no_memory);
- return false;
+ if (bfd_read ((PTR) thdr.dataOffset, 1,
+ sizeof (thdr.dataOffset), abfd)
+ != sizeof (thdr.dataOffset))
+ return false;
+ dataOffset = get_word (abfd, (bfd_byte *) thdr.dataOffset);
}
- pos = bfd_tell (abfd);
- if (bfd_seek (abfd, nlm_cygnus_section_header (abfd)->offset,
- SEEK_SET) != 0
- || bfd_read (contents, len, 1, abfd) != len)
- return false;
- p = contents;
- pend = p + len;
- while (p < pend)
+ if (hdrLength < 2 * NLM_TARGET_LONG_SIZE)
+ dataLength = 0;
+ else
+ {
+ if (bfd_read ((PTR) thdr.dataLength, 1,
+ sizeof (thdr.dataLength), abfd)
+ != sizeof (thdr.dataLength))
+ return false;
+ dataLength = get_word (abfd, (bfd_byte *) thdr.dataLength);
+ }
+ if (hdrLength < 2 * NLM_TARGET_LONG_SIZE + 8)
+ memset (dataStamp, 0, sizeof (dataStamp));
+ else
+ {
+ if (bfd_read ((PTR) dataStamp, 1, sizeof (dataStamp), abfd)
+ != sizeof (dataStamp))
+ return false;
+ }
+
+ /* Read the rest of the header, if any. */
+ if (hdrLength <= 2 * NLM_TARGET_LONG_SIZE + 8)
+ {
+ hdr = NULL;
+ hdrLength = 0;
+ }
+ else
{
- char *name;
- size_t l;
- file_ptr filepos;
- bfd_size_type size;
- asection *newsec;
+ hdrLength -= 2 * NLM_TARGET_LONG_SIZE + 8;
+ hdr = bfd_alloc (abfd, hdrLength);
+ if (hdr == NULL)
+ return false;
+ if (bfd_read (hdr, 1, hdrLength, abfd) != hdrLength)
+ return false;
+ }
+
+ /* If we have found a Cygnus header, process it. Otherwise,
+ just save the associated data without trying to interpret
+ it. */
+ if (strncmp (dataStamp, "CyGnUsEx", 8) == 0)
+ {
+ file_ptr pos;
+ bfd_byte *contents;
+ bfd_byte *p, *pend;
+
+ BFD_ASSERT (hdrLength == 0 && hdr == NULL);
+
+ pos = bfd_tell (abfd);
+ if (bfd_seek (abfd, dataOffset, SEEK_SET) != 0)
+ return false;
+ contents = (bfd_byte *) bfd_alloc (abfd, dataLength);
+ if (contents == NULL)
+ return false;
+ if (bfd_read (contents, 1, dataLength, abfd) != dataLength)
+ return false;
+ if (bfd_seek (abfd, pos, SEEK_SET) != 0)
+ return false;
+
+ memcpy (nlm_cygnus_ext_header (abfd), "CyGnUsEx", 8);
+ nlm_cygnus_ext_header (abfd)->offset = dataOffset;
+ nlm_cygnus_ext_header (abfd)->length = dataLength;
+
+ /* This data this header points to provides a list of
+ the sections which were in the original object file
+ which was converted to become an NLM. We locate
+ those sections and add them to the BFD. Note that
+ this is likely to create a second .text, .data and
+ .bss section; retrieving the sections by name will
+ get the actual NLM sections, which is what we want to
+ happen. The sections from the original file, which
+ may be subsets of the NLM section, can only be found
+ using bfd_map_over_sections. */
+ p = contents;
+ pend = p + dataLength;
+ while (p < pend)
+ {
+ char *name;
+ size_t l;
+ file_ptr filepos;
+ bfd_size_type size;
+ asection *newsec;
- /* The format of this information is
+ /* The format of this information is
null terminated section name
zeroes to adjust to 4 byte boundary
4 byte section data file pointer
4 byte section size
- */
-
- name = p;
- l = strlen (name) + 1;
- l = (l + 3) &~ 3;
- p += l;
- filepos = bfd_h_get_32 (abfd, p);
- p += 4;
- size = bfd_h_get_32 (abfd, p);
- p += 4;
-
- newsec = bfd_make_section_anyway (abfd, name);
- if (newsec == (asection *) NULL)
- return false;
- newsec->_raw_size = size;
- if (filepos != 0)
- {
- newsec->filepos = filepos;
- newsec->flags |= SEC_HAS_CONTENTS;
+ */
+
+ name = (char *) p;
+ l = strlen (name) + 1;
+ l = (l + 3) &~ 3;
+ p += l;
+ filepos = bfd_h_get_32 (abfd, p);
+ p += 4;
+ size = bfd_h_get_32 (abfd, p);
+ p += 4;
+
+ newsec = bfd_make_section_anyway (abfd, name);
+ if (newsec == (asection *) NULL)
+ return false;
+ newsec->_raw_size = size;
+ if (filepos != 0)
+ {
+ newsec->filepos = filepos;
+ newsec->flags |= SEC_HAS_CONTENTS;
+ }
}
}
-
- if (bfd_seek (abfd, pos, SEEK_SET) != 0)
- return false;
+ else
+ {
+ memcpy (nlm_custom_header (abfd)->stamp, thdr.stamp,
+ sizeof (thdr.stamp));
+ nlm_custom_header (abfd)->hdrLength = hdrLength;
+ nlm_custom_header (abfd)->dataOffset = dataOffset;
+ nlm_custom_header (abfd)->dataLength = dataLength;
+ memcpy (nlm_custom_header (abfd)->dataStamp, dataStamp,
+ sizeof (dataStamp));
+ nlm_custom_header (abfd)->hdr = hdr;
+ }
}
else
{
return false;
}
- /* Write out the custom header if there is one. */
- if (find_nonzero ((PTR) nlm_custom_header (abfd),
- sizeof (Nlm_Internal_Custom_Header)))
- {
- Nlm_External_Custom_Header thdr;
-
- /* Right now we assume the custom header is always the suggested
- format for alternate debugging records. */
- BFD_ASSERT (nlm_custom_header (abfd)->dataLength == 8);
-
- memcpy (thdr.stamp, "CuStHeAd", 8);
- put_word (abfd, (bfd_vma) nlm_custom_header (abfd)->dataLength,
- (bfd_byte *) thdr.dataLength);
- if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
- return false;
- if (bfd_write (nlm_custom_header (abfd)->data, 1,
- nlm_custom_header (abfd)->dataLength, abfd)
- != nlm_custom_header (abfd)->dataLength)
- return false;
- }
-
/* Write out the copyright header if there is one. */
if (find_nonzero ((PTR) nlm_copyright_header (abfd),
sizeof (Nlm_Internal_Copyright_Header)))
nlm_copyright_header (abfd)->copyrightMessageLength;
if (bfd_write ((PTR) thdr.copyrightMessageLength, 1, 1, abfd) != 1)
return false;
- /* The copyright message is a variable length string. */
+ /* The copyright message is a variable length string. */
if (bfd_write ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
nlm_copyright_header (abfd)->copyrightMessageLength + 1,
1, abfd) !=
- nlm_copyright_header (abfd)->copyrightMessageLength + 1)
+ ((bfd_size_type)
+ nlm_copyright_header (abfd)->copyrightMessageLength + 1))
return false;
}
+ /* Write out the custom header if there is one. */
+ if (find_nonzero ((PTR) nlm_custom_header (abfd),
+ sizeof (Nlm_Internal_Custom_Header)))
+ {
+ Nlm_External_Custom_Header thdr;
+ boolean ds;
+ bfd_size_type hdrLength;
+
+ ds = find_nonzero ((PTR) nlm_custom_header (abfd)->dataStamp,
+ sizeof (nlm_custom_header (abfd)->dataStamp));
+ memcpy (thdr.stamp, "CuStHeAd", 8);
+ hdrLength = (2 * NLM_TARGET_LONG_SIZE + (ds ? 8 : 0)
+ + nlm_custom_header (abfd)->hdrLength);
+ put_word (abfd, hdrLength, thdr.length);
+ put_word (abfd, (bfd_vma) nlm_custom_header (abfd)->dataOffset,
+ thdr.dataOffset);
+ put_word (abfd, (bfd_vma) nlm_custom_header (abfd)->dataLength,
+ thdr.dataLength);
+ if (! ds)
+ {
+ BFD_ASSERT (nlm_custom_header (abfd)->hdrLength == 0);
+ if (bfd_write ((PTR) &thdr, 1,
+ sizeof (thdr) - sizeof (thdr.dataStamp), abfd)
+ != sizeof (thdr) - sizeof (thdr.dataStamp))
+ return false;
+ }
+ else
+ {
+ memcpy (thdr.dataStamp, nlm_custom_header (abfd)->dataStamp,
+ sizeof (thdr.dataStamp));
+ if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
+ return false;
+ if (bfd_write (nlm_custom_header (abfd)->hdr, 1,
+ nlm_custom_header (abfd)->hdrLength, abfd)
+ != nlm_custom_header (abfd)->hdrLength)
+ return false;
+ }
+ }
+
/* Write out the Cygnus debugging header if there is one. */
- if (find_nonzero ((PTR) nlm_cygnus_section_header (abfd),
- sizeof (Nlm_Internal_Cygnus_Section_Header)))
+ if (find_nonzero ((PTR) nlm_cygnus_ext_header (abfd),
+ sizeof (Nlm_Internal_Cygnus_Ext_Header)))
{
- Nlm_External_Cygnus_Section_Header thdr;
+ Nlm_External_Custom_Header thdr;
- memcpy (thdr.stamp, "CyGnUsSeCs", 10);
- put_word (abfd, (bfd_vma) nlm_cygnus_section_header (abfd)->offset,
- (bfd_byte *) thdr.offset);
- put_word (abfd, (bfd_vma) nlm_cygnus_section_header (abfd)->length,
+ memcpy (thdr.stamp, "CuStHeAd", 8);
+ put_word (abfd, (bfd_vma) 2 * NLM_TARGET_LONG_SIZE + 8,
(bfd_byte *) thdr.length);
+ put_word (abfd, (bfd_vma) nlm_cygnus_ext_header (abfd)->offset,
+ (bfd_byte *) thdr.dataOffset);
+ put_word (abfd, (bfd_vma) nlm_cygnus_ext_header (abfd)->length,
+ (bfd_byte *) thdr.dataLength);
+ memcpy (thdr.dataStamp, "CyGnUsEx", 8);
if (bfd_write ((PTR) &thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))
return false;
}
Return the number of bytes required to hold the symtab vector, based on
the count plus 1, since we will NULL terminate the vector allocated based
- on this size. */
+ on this size. */
long
nlm_get_symtab_upper_bound (abfd)
}
/* Note that bfd_get_symcount is guaranteed to be zero if slurping the
- symbol table fails. */
+ symbol table fails. */
long
nlm_get_symtab (abfd, alocation)
void
nlm_get_symbol_info (ignore_abfd, symbol, ret)
- bfd *ignore_abfd;
+ bfd *ignore_abfd ATTRIBUTE_UNUSED;
asymbol *symbol;
symbol_info *ret;
{
void
nlm_print_symbol (abfd, afile, symbol, how)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
PTR afile;
asymbol *symbol;
bfd_print_symbol_type how;
Note that we allocate the initial bfd canonical symbol buffer based on a
one-to-one mapping of the NLM symbols to canonical symbols. We actually
use all the NLM symbols, so there will be no space left over at the end.
- When we have all the symbols, we build the caller's pointer vector. */
+ When we have all the symbols, we build the caller's pointer vector. */
abfd->symcount = 0;
i_fxdhdrp = nlm_fixed_header (abfd);
sym = ((nlm_symbol_type *)
bfd_zalloc (abfd, totsymcount * sizeof (nlm_symbol_type)));
if (!sym)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
nlm_set_symbols (abfd, sym);
/* We use the bfd's symcount directly as the control count, so that early
termination of the loop leaves the symcount correct for the symbols that
- were read. */
+ were read. */
set_public_section_func = nlm_set_public_section_func (abfd);
symcount = i_fxdhdrp->numberOfPublics;
sym->symbol.the_bfd = abfd;
sym->symbol.name = bfd_alloc (abfd, symlength + 1);
if (!sym->symbol.name)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_read ((PTR) sym->symbol.name, symlength, 1, abfd)
!= symlength)
return (false);
sym->symbol.the_bfd = abfd;
sym->symbol.name = bfd_alloc (abfd, symlength + 1);
if (!sym->symbol.name)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
if (bfd_read ((PTR) sym->symbol.name, symlength, 1, abfd)
!= symlength)
return (false);
}
else
{
- sym->symbol.section = &bfd_abs_section;
+ sym->symbol.section = bfd_abs_section_ptr;
}
sym->rcnt = 0;
abfd->symcount++;
rels = (arelent *) bfd_alloc (abfd, count * sizeof (arelent));
secs = (asection **) bfd_alloc (abfd, count * sizeof (asection *));
if ((rels == NULL || secs == NULL) && count != 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return false;
- }
+ return false;
nlm_relocation_fixups (abfd) = rels;
nlm_relocation_fixup_secs (abfd) = secs;
asection *sec;
bfd_vma text, data, bss;
bfd_vma text_low, data_low;
- int text_align, data_align, other_align;
+ unsigned int text_align, data_align, other_align;
file_ptr text_ptr, data_ptr, other_ptr;
asection *bss_sec;
asymbol **sym_ptr_ptr;
if (find_nonzero ((PTR) nlm_extended_header (abfd),
sizeof (Nlm_Internal_Extended_Header)))
sofar += sizeof (Nlm_External_Extended_Header);
- if (find_nonzero ((PTR) nlm_custom_header (abfd),
- sizeof (Nlm_Internal_Custom_Header)))
- sofar += (sizeof (Nlm_External_Custom_Header)
- + nlm_custom_header (abfd)->dataLength);
if (find_nonzero ((PTR) nlm_copyright_header (abfd),
sizeof (Nlm_Internal_Copyright_Header)))
sofar += (sizeof (Nlm_External_Copyright_Header)
+ nlm_copyright_header (abfd)->copyrightMessageLength + 1);
- if (find_nonzero ((PTR) nlm_cygnus_section_header (abfd),
- sizeof (Nlm_Internal_Cygnus_Section_Header)))
- sofar += sizeof (Nlm_External_Cygnus_Section_Header);
+ if (find_nonzero ((PTR) nlm_custom_header (abfd),
+ sizeof (Nlm_Internal_Custom_Header)))
+ sofar += (sizeof (Nlm_External_Custom_Header)
+ + nlm_custom_header (abfd)->hdrLength);
+ if (find_nonzero ((PTR) nlm_cygnus_ext_header (abfd),
+ sizeof (Nlm_Internal_Cygnus_Ext_Header)))
+ sofar += sizeof (Nlm_External_Custom_Header);
/* Compute the section file positions in two passes. First get the
sizes of the text and data sections, and then set the file
boolean (*write_prefix_func) PARAMS ((bfd *));
unsigned char *fixed_header = NULL;
- fixed_header = (unsigned char *) malloc (nlm_fixed_header_size (abfd));
+ fixed_header = ((unsigned char *)
+ bfd_malloc ((size_t) nlm_fixed_header_size (abfd)));
if (fixed_header == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
if (abfd->output_has_begun == false
&& nlm_compute_section_file_positions (abfd) == false)
rel = *rel_ptr_ptr;
sym = *rel->sym_ptr_ptr;
- if (bfd_get_section (sym) != &bfd_und_section)
+ if (! bfd_is_und_section (bfd_get_section (sym)))
{
++internal_reloc_count;
if ((*write_import_func) (abfd, sec, rel) == false)
(external_reloc_count
* sizeof (struct reloc_and_sec)));
if (external_relocs == (struct reloc_and_sec *) NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto error_return;
- }
+ goto error_return;
i = 0;
for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
{
rel = *rel_ptr_ptr;
sym = *rel->sym_ptr_ptr;
- if (bfd_get_section (sym) != &bfd_und_section)
+ if (! bfd_is_und_section (bfd_get_section (sym)))
continue;
external_relocs[i].rel = rel;
sym = *sym_ptr_ptr;
if ((sym->flags & (BSF_EXPORT | BSF_GLOBAL)) == 0
- || bfd_get_section (sym) == &bfd_und_section)
+ || bfd_is_und_section (bfd_get_section (sym)))
continue;
++c;
debugging symbol NLM does not understand at all. */
if ((sym->flags & (BSF_LOCAL | BSF_GLOBAL | BSF_EXPORT)) == 0
|| (sym->flags & BSF_DEBUGGING) != 0
- || bfd_get_section (sym) == &bfd_und_section)
+ || bfd_is_und_section (bfd_get_section (sym)))
continue;
++c;
goto error_return;
}
- BFD_ASSERT (bfd_tell (abfd) == nlm_optional_prefix_size (abfd));
+ BFD_ASSERT ((bfd_size_type) bfd_tell (abfd)
+ == nlm_optional_prefix_size (abfd));
nlm_swap_fixed_header_out (abfd, nlm_fixed_header (abfd), fixed_header);
if (bfd_write (fixed_header, nlm_fixed_header_size (abfd), 1, abfd)