aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2004-01-22 17:03:45 +0000
committerAndrew Cagney <cagney@redhat.com>2004-01-22 17:03:45 +0000
commitf060829e7f4bc3b2a39325ecf91fde96b20ae76b (patch)
tree380d6c24dbcb8a8f89f52f08306e8bfe193416c3 /bfd/elf.c
parenta5dd37ab655106440e987830db5111b43f271ecc (diff)
downloadgdb-cagney_bigcore-20040122-branch.zip
gdb-cagney_bigcore-20040122-branch.tar.gz
gdb-cagney_bigcore-20040122-branch.tar.bz2
Index: bfd/ChangeLogcagney_bigcore-20040122-branch
2004-01-21 Andrew Cagney <cagney@redhat.com> * bfdio.c: Update copyright. Include "bfdio.h". (real_ftell, real_fseek): New functions. (bfd_tell): Use real_ftell, change return-type to file_ptr. (bfd_seek): Use real_ftell and real_fseek. Change type of file_position to a file_ptr. * cache.c: Update copyright. Include "bfdio.h". (close_one): Use real_ftell. (bfd_cache_lookup_worker): Use real_fseek, use ufile_ptr in cast. * bfd-in.h: Update copyright. (file_ptr, ufile_ptr): Specify type using @BFD_FILE_PTR@. (bfd_tell): Make return-type "file_ptr". * bfd-in2.h: Re-generate. * configure.in (AC_CHECK_FUNCS): Check for ftello, ftello64, fseeko and fseeko64. * config.in, configure: Re-generate. * libbfd-in.h: Update copyright. (real_ftell, real_fseek): Declare. * libbfd.h: Re-generate. * elf.c (offset_vma_page_alignment): New function. (assign_file_positions_for_segments): Replace broken modulo code with offset_vma_page_alignment. (assign_file_positions_except_relocs): Ditto. Index: gdb/testsuite/ChangeLog 2004-01-22 Andrew Cagney <cagney@redhat.com> * gdb.base/bigcore.exp: New file. * gdb.base/bigcore.c: New file.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index cd107bd..7999bf3 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3571,6 +3571,34 @@ elf_sort_sections (const void *arg1, const void *arg2)
return sec1->target_index - sec2->target_index;
}
+/* Ian Lance Taylor writes:
+
+ We shouldn't be using % with a negative signed number. That's just
+ not good. We have to make sure either that the number is not
+ negative, or that the number has an unsigned type. When the types
+ are all the same size they wind up as unsigned. When file_ptr is a
+ larger signed type, the arithmetic winds up as signed long long,
+ which is wrong.
+
+ What we're trying to say here is something like ``increase OFF by
+ the least amount that will cause it to be equal to the VMA modulo
+ the page size.'' */
+/* In other words, something like:
+
+ vma_offset = m->sections[0]->vma % bed->maxpagesize;
+ off_offset = off % bed->maxpagesize;
+ if (vma_offset < off_offset)
+ adjustment = vma_offset + bed->maxpagesize - off_offset;
+ else
+ adjustment = vma_offset - off_offset;
+
+ this can be colapsed into the expression below. */
+static file_ptr
+offset_vma_page_adjustment (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
+{
+ return ((vma - off) % maxpagesize);
+}
+
/* Assign file positions to the sections based on the mapping from
sections to segments. This function also sets up some fields in
the file header, and writes out the program headers. */
@@ -3698,7 +3726,8 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
&& (m->sections[0]->flags & SEC_ALLOC) != 0)
{
if ((abfd->flags & D_PAGED) != 0)
- off += (m->sections[0]->vma - off) % bed->maxpagesize;
+ off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+ bed->maxpagesize);
else
{
bfd_size_type align;
@@ -3713,7 +3742,8 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
align = secalign;
}
- off += (m->sections[0]->vma - off) % (1 << align);
+ off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+ 1 << align);
}
}
@@ -3875,9 +3905,11 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
not have the SEC_LOAD case just above, and then
this was necessary, but now I'm not sure. */
if ((abfd->flags & D_PAGED) != 0)
- adjust = (sec->vma - voff) % bed->maxpagesize;
+ adjust = offset_vma_page_adjustment (sec->vma, voff,
+ bed->maxpagesize);
else
- adjust = (sec->vma - voff) % align;
+ adjust = offset_vma_page_adjustment (sec->vma, voff,
+ align);
}
else
adjust = 0;
@@ -4211,9 +4243,11 @@ assign_file_positions_except_relocs (bfd *abfd,
? "*unknown*"
: hdr->bfd_section->name)));
if ((abfd->flags & D_PAGED) != 0)
- off += (hdr->sh_addr - off) % bed->maxpagesize;
+ off += offset_vma_page_adjustment (hdr->sh_addr, off,
+ bed->maxpagesize);
else
- off += (hdr->sh_addr - off) % hdr->sh_addralign;
+ off += offset_vma_page_adjustment (hdr->sh_addr, off,
+ hdr->sh_addralign);
off = _bfd_elf_assign_file_position_for_section (hdr, off,
FALSE);
}