* libbfd.c (bfd_log2): Cast to bfd_vma before shifting, not

after.  From Chris Torek <torek@bsdi.com>.
This commit is contained in:
Ian Lance Taylor 1998-09-20 03:53:05 +00:00
parent d7298d8f7e
commit 0983267416
2 changed files with 50 additions and 34 deletions

View File

@ -1,3 +1,8 @@
Sat Sep 19 23:51:47 1998 Ian Lance Taylor <ian@cygnus.com>
* libbfd.c (bfd_log2): Cast to bfd_vma before shifting, not
after. From Chris Torek <torek@bsdi.com>.
Sat Sep 19 22:42:23 1998 Doug Rabson <dfr@nlsystems.com>
* elflink.h (elf_link_add_object_symbols): Ensure that the warning

View File

@ -1,5 +1,6 @@
/* Assorted BFD support routines, only used internally.
Copyright 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
@ -22,6 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "sysdep.h"
#include "libbfd.h"
#ifndef HAVE_GETPAGESIZE
#define getpagesize() 2048
#endif
static int real_read PARAMS ((PTR, size_t, size_t, FILE *));
/*
@ -227,7 +232,13 @@ real_read (where, a,b, file)
size_t b;
FILE *file;
{
#if defined (__VAX) && defined (VMS)
/* Apparently fread on Vax VMS does not keep the record length
information. */
return read (fileno (file), where, a * b);
#else
return fread (where, a, b, file);
#endif
}
/* Return value is amount read (FIXME: how are errors and end of file dealt
@ -260,10 +271,8 @@ bfd_read (ptr, size, nitems, abfd)
}
nread = real_read (ptr, 1, (size_t)(size*nitems), bfd_cache_lookup(abfd));
#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (nread > 0)
abfd->where += nread;
#endif
/* Set bfd_error if we did not read as much data as we expected.
@ -305,11 +314,16 @@ bfd_init_window (windowp)
windowp->i = 0;
windowp->size = 0;
}
/* Currently, if USE_MMAP is undefined, none if the window stuff is
used. Okay, so it's mis-named. At least the command-line option
"--without-mmap" is more obvious than "--without-windows" or some
such. */
#ifdef USE_MMAP
#undef HAVE_MPROTECT /* code's not tested yet */
#if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
#include <sys/types.h>
#include <sys/mman.h>
#endif
@ -319,12 +333,6 @@ bfd_init_window (windowp)
static int debug_windows;
/* Currently, if USE_MMAP is undefined, none if the window stuff is
used. Okay, so it's mis-named. At least the command-line option
"--without-mmap" is more obvious than "--without-windows" or some
such. */
#ifdef USE_MMAP
void
bfd_free_window (windowp)
bfd_window *windowp;
@ -361,7 +369,6 @@ bfd_free_window (windowp)
/* There should be no more references to i at this point. */
free (i);
}
#endif
static int ok_to_map = 1;
@ -377,15 +384,11 @@ bfd_get_file_window (abfd, offset, size, windowp, writable)
bfd_window_internal *i = windowp->i;
size_t size_to_alloc = size;
#ifndef USE_MMAP
abort ();
#endif
if (debug_windows)
fprintf (stderr, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
abfd, (long) offset, (long) size,
windowp, windowp->data, windowp->size, windowp->i,
writable);
windowp, windowp->data, (unsigned long) windowp->size,
windowp->i, writable);
/* Make sure we know the page size, so we can be friendly to mmap. */
if (pagesize == 0)
@ -463,10 +466,10 @@ bfd_get_file_window (abfd, offset, size, windowp, writable)
else if (debug_windows)
{
if (ok_to_map)
fprintf (stderr, "not mapping: data=%lx mapped=%d\n",
fprintf (stderr, _("not mapping: data=%lx mapped=%d\n"),
(unsigned long) i->data, (int) i->mapped);
else
fprintf (stderr, "not mapping: env var not set\n");
fprintf (stderr, _("not mapping: env var not set\n"));
}
#else
ok_to_map = 0;
@ -513,6 +516,8 @@ bfd_get_file_window (abfd, offset, size, windowp, writable)
return true;
}
#endif /* USE_MMAP */
bfd_size_type
bfd_write (ptr, size, nitems, abfd)
CONST PTR ptr;
@ -527,10 +532,8 @@ bfd_write (ptr, size, nitems, abfd)
nwrote = fwrite (ptr, 1, (size_t) (size * nitems),
bfd_cache_lookup (abfd));
#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (nwrote > 0)
abfd->where += nwrote;
#endif
if ((bfd_size_type) nwrote != size * nitems)
{
#ifdef ENOSPC
@ -647,7 +650,6 @@ bfd_seek (abfd, position, direction)
return 0;
}
#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (abfd->format != bfd_archive && abfd->my_archive == 0)
{
#if 0
@ -681,7 +683,6 @@ bfd_seek (abfd, position, direction)
In the meantime, no optimization for archives. */
}
#endif
f = bfd_cache_lookup (abfd);
file_position = position;
@ -692,19 +693,28 @@ bfd_seek (abfd, position, direction)
if (result != 0)
{
int hold_errno = errno;
/* Force redetermination of `where' field. */
bfd_tell (abfd);
bfd_set_error (bfd_error_system_call);
/* An EINVAL error probably means that the file offset was
absurd. */
if (hold_errno == EINVAL)
bfd_set_error (bfd_error_file_truncated);
else
{
bfd_set_error (bfd_error_system_call);
errno = hold_errno;
}
}
else
{
#ifdef FILE_OFFSET_IS_CHAR_INDEX
/* Adjust `where' field. */
if (direction == SEEK_SET)
abfd->where = position;
else
abfd->where += position;
#endif
}
return result;
}
@ -1175,23 +1185,24 @@ DESCRIPTION
@var{x} of 1025 returns 11.
*/
unsigned
bfd_log2(x)
unsigned int
bfd_log2 (x)
bfd_vma x;
{
unsigned result = 0;
while ( (bfd_vma)(1<< result) < x)
result++;
unsigned int result = 0;
while ((((bfd_vma) 1) << result) < x)
++result;
return result;
}
boolean
bfd_generic_is_local_label (abfd, sym)
bfd_generic_is_local_label_name (abfd, name)
bfd *abfd;
asymbol *sym;
const char *name;
{
char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
return (sym->name[0] == locals_prefix);
return (name[0] == locals_prefix);
}