This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
PATCH SCNHSZ/FILHSZ/RELSZ usage
- To: nickc at cygnus dot com, binutils at sourceware dot cygnus dot com
- Subject: PATCH SCNHSZ/FILHSZ/RELSZ usage
- From: Timothy Wall <twall at tiac dot net>
- Date: Thu, 13 Jan 2000 15:58:20 -0500
This patch replaces usage of the constant SCNHSZ/FILHSZ/RELSZ macros
with dynamic lookups. This allows a particular BFD implementation to
have variants of these field sizes. Specifically, different versions of
TI COFF have different sizes for these fields.
* coffcode.h: use bfd_coff_xxx instead of the macro XXX (where xxx =
scnhsz, filhsz, relsz)
* coffswap.h: ditto
Index: coffcode.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/coffcode.h,v
retrieving revision 1.26
diff -c -3 -p -r1.26 coffcode.h
*** coffcode.h 1999/09/13 23:55:22 1.26
--- coffcode.h 2000/01/13 20:47:40
*************** coff_write_relocs (abfd, first_undef)
*** 2293,2299 ****
n.r_type = q->howto->type;
#endif
coff_swap_reloc_out (abfd, &n, &dst);
! if (bfd_write ((PTR) & dst, 1, RELSZ, abfd) != RELSZ)
return false;
}
--- 2293,2300 ----
n.r_type = q->howto->type;
#endif
coff_swap_reloc_out (abfd, &n, &dst);
! if (bfd_write ((PTR) & dst, 1, bfd_coff_relsz (abfd), abfd) !=
! bfd_coff_relsz (abfd))
return false;
}
*************** coff_compute_section_file_positions (abf
*** 2613,2619 ****
{
asection *current;
asection *previous = (asection *) NULL;
! file_ptr sofar = FILHSZ;
boolean align_adjust;
#ifdef ALIGN_SECTIONS_IN_FILE
file_ptr old_sofar;
--- 2614,2620 ----
{
asection *current;
asection *previous = (asection *) NULL;
! file_ptr sofar = bfd_coff_filhsz (abfd);
boolean align_adjust;
#ifdef ALIGN_SECTIONS_IN_FILE
file_ptr old_sofar;
*************** coff_compute_section_file_positions (abf
*** 2688,2701 ****
sofar += SMALL_AOUTSZ;
#endif
! sofar += abfd->section_count * SCNHSZ;
#ifdef RS6000COFF_C
/* XCOFF handles overflows in the reloc and line number count fields
by allocating a new section header to hold the correct counts. */
for (current = abfd->sections; current != NULL; current = current->next)
if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
! sofar += SCNHSZ;
#endif
#ifdef COFF_IMAGE_WITH_PE
--- 2689,2702 ----
sofar += SMALL_AOUTSZ;
#endif
! sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
#ifdef RS6000COFF_C
/* XCOFF handles overflows in the reloc and line number count fields
by allocating a new section header to hold the correct counts. */
for (current = abfd->sections; current != NULL; current = current->next)
if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
! sofar += bfd_coff_scnhsz (abfd);
#endif
#ifdef COFF_IMAGE_WITH_PE
*************** coff_write_object_contents (abfd)
*** 3029,3035 ****
for (current = abfd->sections; current != NULL; current =
current->next)
! reloc_size += current->reloc_count * RELSZ;
lineno_base = reloc_base + reloc_size;
sym_base = lineno_base + lnno_size;
--- 3030,3036 ----
for (current = abfd->sections; current != NULL; current =
current->next)
! reloc_size += current->reloc_count * bfd_coff_relsz (abfd);
lineno_base = reloc_base + reloc_size;
sym_base = lineno_base + lnno_size;
*************** coff_write_object_contents (abfd)
*** 3051,3057 ****
if (current->reloc_count)
{
current->rel_filepos = reloc_base;
! reloc_base += current->reloc_count * RELSZ;
}
else
{
--- 3052,3058 ----
if (current->reloc_count)
{
current->rel_filepos = reloc_base;
! reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
}
else
{
*************** coff_write_object_contents (abfd)
*** 3063,3072 ****
internal_f.f_nscns = 0;
if ((abfd->flags & EXEC_P) != 0)
! scn_base = FILHSZ + AOUTSZ;
else
{
! scn_base = FILHSZ;
#ifdef RS6000COFF_C
if (xcoff_data (abfd)->full_aouthdr)
scn_base += AOUTSZ;
--- 3064,3073 ----
internal_f.f_nscns = 0;
if ((abfd->flags & EXEC_P) != 0)
! scn_base = bfd_coff_filhsz (abfd) + AOUTSZ;
else
{
! scn_base = bfd_coff_filhsz (abfd);
#ifdef RS6000COFF_C
if (xcoff_data (abfd)->full_aouthdr)
scn_base += AOUTSZ;
*************** coff_write_object_contents (abfd)
*** 3214,3220 ****
{
SCNHDR buff;
if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
! || bfd_write ((PTR) (&buff), 1, SCNHSZ, abfd) != SCNHSZ)
return false;
}
--- 3215,3221 ----
{
SCNHDR buff;
if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0
! || bfd_write ((PTR) (&buff), 1, bfd_coff_scnhsz (abfd), abfd) != bfd_coff_scnhsz (abfd))
return false;
}
*************** coff_write_object_contents (abfd)
*** 3335,3341 ****
scnhdr.s_nlnno = current->target_index;
scnhdr.s_flags = STYP_OVRFLO;
if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
! || bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ)
return false;
}
}
--- 3336,3342 ----
scnhdr.s_nlnno = current->target_index;
scnhdr.s_flags = STYP_OVRFLO;
if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
! || bfd_write ((PTR) &buff, 1, bfd_coff_scnhsz (abfd), abfd) != bfd_coff_scnhsz (abfd))
return false;
}
}
*************** coff_write_object_contents (abfd)
*** 3678,3686 ****
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
return false;
{
! char buff[FILHSZ];
coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff);
! if (bfd_write ((PTR) buff, 1, FILHSZ, abfd) != FILHSZ)
return false;
}
if (abfd->flags & EXEC_P)
--- 3679,3688 ----
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
return false;
{
! char buff[bfd_coff_filhsz (abfd)];
coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff);
! if (bfd_write ((PTR) buff, 1, bfd_coff_filhsz (abfd), abfd) !=
! bfd_coff_filehsz (abfd))
return false;
}
if (abfd->flags & EXEC_P)
*************** coff_slurp_reloc_table (abfd, asect, sym
*** 4471,4477 ****
(RELOC *) buy_and_read (abfd,
asect->rel_filepos,
SEEK_SET,
! (size_t) (RELSZ *
asect->reloc_count));
reloc_cache = (arelent *)
bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent)));
--- 4473,4479 ----
(RELOC *) buy_and_read (abfd,
asect->rel_filepos,
SEEK_SET,
! (size_t) (bfd_coff_relsz (abfd) *
asect->reloc_count));
reloc_cache = (arelent *)
bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent)));
Index: coffswap.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/coffswap.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 coffswap.h
*** coffswap.h 1999/09/11 22:10:33 1.4
--- coffswap.h 2000/01/13 20:47:41
*************** coff_swap_reloc_out (abfd, src, dst)
*** 261,267 ****
SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
#endif
! return RELSZ;
}
#endif /* NO_COFF_RELOCS */
--- 261,267 ----
SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
#endif
! return bfd_coff_relsz (abfd);
}
#endif /* NO_COFF_RELOCS */
*************** coff_swap_filehdr_out (abfd, in, out)
*** 321,327 ****
#ifdef COFF_ADJUST_FILEHDR_OUT_POST
COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out);
#endif
! return FILHSZ;
}
--- 321,327 ----
#ifdef COFF_ADJUST_FILEHDR_OUT_POST
COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out);
#endif
! return bfd_coff_filhsz (abfd);
}
*************** coff_swap_scnhdr_out (abfd, in, out)
*** 845,851 ****
{
struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
SCNHDR *scnhdr_ext = (SCNHDR *)out;
! unsigned int ret = SCNHSZ;
#ifdef COFF_ADJUST_SCNHDR_OUT_PRE
COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out);
--- 845,851 ----
{
struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
SCNHDR *scnhdr_ext = (SCNHDR *)out;
! unsigned int ret = bfd_coff_scnhsz (abfd);
#ifdef COFF_ADJUST_SCNHDR_OUT_PRE
COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out);