Automatic date update in version.in
[binutils-gdb.git] / bfd / i386lynx.c
index 777fd3d72ebb0e6798b35b0ba8a1c2ad6e1886fd..c2eded8dfb6e6493ac6742a424c63a02b5822550 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for i386 a.out binaries under LynxOS.
-   Copyright (C) 1990-2020 Free Software Foundation, Inc.
+   Copyright (C) 1990-2023 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
 #include "libbfd.h"
 
 #ifndef WRITE_HEADERS
-#define WRITE_HEADERS(abfd, execp)                                           \
-      {                                                                              \
-       if (adata(abfd).magic == undecided_magic)                             \
-         NAME(aout,adjust_sizes_and_vmas) (abfd);                            \
-                                                                             \
-       execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;        \
-       execp->a_entry = bfd_get_start_address (abfd);                        \
-                                                                             \
-       execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *                \
-                          obj_reloc_entry_size (abfd));                      \
-       execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *                \
-                          obj_reloc_entry_size (abfd));                      \
-       NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes);           \
-                                                                             \
-       if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0                      \
-           || bfd_bwrite (&exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \
-                         abfd) != EXEC_BYTES_SIZE)                           \
-         return FALSE;                                                       \
-       /* Now write out reloc info, followed by syms and strings */          \
-                                                                             \
-       if (bfd_get_symcount (abfd) != 0)                                     \
-           {                                                                 \
-             if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (execp)), SEEK_SET)    \
-                 != 0)                                                       \
-               return FALSE;                                                 \
-                                                                             \
-             if (! NAME(aout,write_syms) (abfd)) return FALSE;               \
-                                                                             \
-             if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (execp)), SEEK_SET)   \
-                 != 0)                                                       \
-               return FALSE;                                                 \
-                                                                             \
-             if (!NAME(lynx,squirt_out_relocs) (abfd, obj_textsec (abfd)))   \
-               return FALSE;                                                 \
-             if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (execp)), SEEK_SET)   \
-                 != 0)                                                       \
-               return 0;                                                     \
-                                                                             \
-             if (!NAME(lynx,squirt_out_relocs) (abfd, obj_datasec (abfd)))   \
-               return FALSE;                                                 \
-           }                                                                 \
-      }
+#define WRITE_HEADERS(abfd, execp)                                     \
+  {                                                                    \
+    if (adata(abfd).magic == undecided_magic)                          \
+      NAME (aout, adjust_sizes_and_vmas) (abfd);                       \
+                                                                       \
+    execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;     \
+    execp->a_entry = bfd_get_start_address (abfd);                     \
+                                                                       \
+    execp->a_trsize = ((obj_textsec (abfd)->reloc_count)               \
+                      * obj_reloc_entry_size (abfd));                  \
+    execp->a_drsize = ((obj_datasec (abfd)->reloc_count)               \
+                      * obj_reloc_entry_size (abfd));                  \
+    NAME (aout, swap_exec_header_out) (abfd, execp, &exec_bytes);      \
+                                                                       \
+    if (bfd_seek (abfd, 0, SEEK_SET) != 0                              \
+       || bfd_write (&exec_bytes, EXEC_BYTES_SIZE,                     \
+                     abfd) != EXEC_BYTES_SIZE)                         \
+      return false;                                                    \
+    /* Now write out reloc info, followed by syms and strings.  */     \
+                                                                       \
+    if (bfd_get_outsymbols (abfd) != NULL                              \
+       && bfd_get_symcount (abfd) != 0)                                \
+      {                                                                        \
+       if (bfd_seek (abfd, N_SYMOFF (execp), SEEK_SET) != 0)           \
+         return false;                                                 \
+                                                                       \
+       if (! NAME (aout, write_syms) (abfd))                           \
+         return false;                                                 \
+      }                                                                        \
+                                                                       \
+    if (bfd_seek (abfd, N_TRELOFF (execp), SEEK_SET) != 0)             \
+      return false;                                                    \
+    if (!NAME (lynx, squirt_out_relocs) (abfd, obj_textsec (abfd)))    \
+      return false;                                                    \
+                                                                       \
+    if (bfd_seek (abfd, N_DRELOFF (execp), SEEK_SET) != 0)             \
+      return false;                                                    \
+    if (!NAME (lynx, squirt_out_relocs) (abfd, obj_datasec (abfd)))    \
+      return false;                                                    \
+  }
 #endif
 
 #include "libaout.h"
@@ -86,8 +84,8 @@
 
 char *lynx_core_file_failing_command ();
 int lynx_core_file_failing_signal ();
-bfd_boolean lynx_core_file_matches_executable_p ();
-const bfd_target *lynx_core_file_p ();
+bool lynx_core_file_matches_executable_p ();
+bfd_cleanup lynx_core_file_p ();
 
 #define        MY_core_file_failing_command lynx_core_file_failing_command
 #define        MY_core_file_failing_signal lynx_core_file_failing_signal
@@ -120,7 +118,7 @@ NAME(lynx,swap_std_reloc_out) (bfd *abfd,
 
   PUT_WORD (abfd, g->address, natptr->r_address);
 
-  r_length = g->howto->size;   /* Size as a power of two */
+  r_length = bfd_log2 (bfd_get_reloc_size (g->howto));
   r_pcrel = (int) g->howto->pc_relative;       /* Relative to PC? */
   /* r_baserel, r_jmptable, r_relative???  FIXME-soon */
   r_baserel = 0;
@@ -282,38 +280,42 @@ NAME(lynx,swap_ext_reloc_out) (bfd *abfd,
 #define MOVE_ADDRESS(ad)                                               \
   if (r_extern)                                                                \
     {                                                                  \
-   /* undefined symbol */                                              \
-     cache_ptr->sym_ptr_ptr = symbols + r_index;                       \
-     cache_ptr->addend = ad;                                           \
+      /* undefined symbol */                                           \
+      if (symbols != NULL && r_index < bfd_get_symcount (abfd))                \
+       cache_ptr->sym_ptr_ptr = symbols + r_index;                     \
+      else                                                             \
+       cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;   \
+      cache_ptr->addend = ad;                                          \
     }                                                                  \
   else                                                                 \
     {                                                                  \
-    /* defined, section relative. replace symbol with pointer to       \
-       symbol which points to section  */                              \
-    switch (r_index) {                                                 \
-    case N_TEXT:                                                       \
-    case N_TEXT | N_EXT:                                               \
-      cache_ptr->sym_ptr_ptr  = obj_textsec(abfd)->symbol_ptr_ptr;     \
-      cache_ptr->addend = ad  - su->textsec->vma;                      \
-      break;                                                           \
-    case N_DATA:                                                       \
-    case N_DATA | N_EXT:                                               \
-      cache_ptr->sym_ptr_ptr  = obj_datasec(abfd)->symbol_ptr_ptr;     \
-      cache_ptr->addend = ad - su->datasec->vma;                       \
-      break;                                                           \
-    case N_BSS:                                                                \
-    case N_BSS | N_EXT:                                                        \
-      cache_ptr->sym_ptr_ptr  = obj_bsssec(abfd)->symbol_ptr_ptr;      \
-      cache_ptr->addend = ad - su->bsssec->vma;                                \
-      break;                                                           \
-    default:                                                           \
-    case N_ABS:                                                                \
-    case N_ABS | N_EXT:                                                        \
-     cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;     \
-      cache_ptr->addend = ad;                                          \
-      break;                                                           \
+      /* defined, section relative. replace symbol with pointer to     \
+        symbol which points to section  */                             \
+      switch (r_index)                                                 \
+       {                                                               \
+       case N_TEXT:                                                    \
+       case N_TEXT | N_EXT:                                            \
+         cache_ptr->sym_ptr_ptr  = obj_textsec(abfd)->symbol_ptr_ptr;  \
+         cache_ptr->addend = ad  - su->textsec->vma;                   \
+         break;                                                        \
+       case N_DATA:                                                    \
+       case N_DATA | N_EXT:                                            \
+         cache_ptr->sym_ptr_ptr  = obj_datasec(abfd)->symbol_ptr_ptr;  \
+         cache_ptr->addend = ad - su->datasec->vma;                    \
+         break;                                                        \
+       case N_BSS:                                                     \
+       case N_BSS | N_EXT:                                             \
+         cache_ptr->sym_ptr_ptr  = obj_bsssec(abfd)->symbol_ptr_ptr;   \
+         cache_ptr->addend = ad - su->bsssec->vma;                     \
+         break;                                                        \
+       default:                                                        \
+       case N_ABS:                                                     \
+       case N_ABS | N_EXT:                                             \
+         cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
+         cache_ptr->addend = ad;                                       \
+         break;                                                        \
+       }                                                               \
     }                                                                  \
-  }                                                                    \
 
 static void
 NAME(lynx,swap_ext_reloc_in) (bfd *abfd,
@@ -322,7 +324,7 @@ NAME(lynx,swap_ext_reloc_in) (bfd *abfd,
                              asymbol **symbols,
                              bfd_size_type symcount ATTRIBUTE_UNUSED)
 {
-  int r_index;
+  unsigned int r_index;
   int r_extern;
   unsigned int r_type;
   struct aoutdata *su = &(abfd->tdata.aout_data->a);
@@ -345,7 +347,7 @@ NAME(lynx,swap_std_reloc_in) (bfd *abfd,
                              asymbol **symbols,
                              bfd_size_type symcount ATTRIBUTE_UNUSED)
 {
-  int r_index;
+  unsigned int r_index;
   int r_extern;
   unsigned int r_length;
   int r_pcrel;
@@ -367,7 +369,7 @@ NAME(lynx,swap_std_reloc_in) (bfd *abfd,
 
 /* Reloc hackery */
 
-static bfd_boolean
+static bool
 NAME(lynx,slurp_reloc_table) (bfd *abfd,
                              sec_ptr asect,
                              asymbol **symbols)
@@ -379,10 +381,10 @@ NAME(lynx,slurp_reloc_table) (bfd *abfd,
   size_t each_size;
 
   if (asect->relocation)
-    return TRUE;
+    return true;
 
   if (asect->flags & SEC_CONSTRUCTOR)
-    return TRUE;
+    return true;
 
   if (asect == obj_datasec (abfd))
     {
@@ -397,11 +399,11 @@ NAME(lynx,slurp_reloc_table) (bfd *abfd,
     }
 
   bfd_set_error (bfd_error_invalid_operation);
-  return FALSE;
+  return false;
 
-doit:
+ doit:
   if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
-    return FALSE;
+    return false;
   each_size = obj_reloc_entry_size (abfd);
 
   count = reloc_size / each_size;
@@ -409,20 +411,13 @@ doit:
 
   reloc_cache = (arelent *) bfd_zmalloc (count * sizeof (arelent));
   if (!reloc_cache && count != 0)
-    return FALSE;
+    return false;
 
-  relocs = bfd_alloc (abfd, reloc_size);
+  relocs = _bfd_alloc_and_read (abfd, reloc_size, reloc_size);
   if (!relocs && reloc_size != 0)
     {
       free (reloc_cache);
-      return FALSE;
-    }
-
-  if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
-    {
-      bfd_release (abfd, relocs);
-      free (reloc_cache);
-      return FALSE;
+      return false;
     }
 
   if (each_size == RELOC_EXT_SIZE)
@@ -454,14 +449,14 @@ doit:
   bfd_release (abfd, relocs);
   asect->relocation = reloc_cache;
   asect->reloc_count = count;
-  return TRUE;
+  return true;
 }
 
 
 
 /* Write out a relocation section into an object file.  */
 
-static bfd_boolean
+static bool
 NAME(lynx,squirt_out_relocs) (bfd *abfd, asection *section)
 {
   arelent **generic;
@@ -471,14 +466,14 @@ NAME(lynx,squirt_out_relocs) (bfd *abfd, asection *section)
   bfd_size_type natsize;
 
   if (count == 0)
-    return TRUE;
+    return true;
 
   each_size = obj_reloc_entry_size (abfd);
   natsize = count;
   natsize *= each_size;
   native = (unsigned char *) bfd_zalloc (abfd, natsize);
   if (!native)
-    return FALSE;
+    return false;
 
   generic = section->orelocation;
 
@@ -497,14 +492,14 @@ NAME(lynx,squirt_out_relocs) (bfd *abfd, asection *section)
        NAME(lynx,swap_std_reloc_out) (abfd, *generic, (struct reloc_std_external *) natptr);
     }
 
-  if (bfd_bwrite (native, natsize, abfd) != natsize)
+  if (bfd_write (native, natsize, abfd) != natsize)
     {
       bfd_release (abfd, native);
-      return FALSE;
+      return false;
     }
   bfd_release (abfd, native);
 
-  return TRUE;
+  return true;
 }
 
 /* This is stupid.  This function should be a boolean predicate */