From: Ian Lance Taylor Date: Sun, 20 Sep 1998 03:53:05 +0000 (+0000) Subject: * libbfd.c (bfd_log2): Cast to bfd_vma before shifting, not X-Git-Tag: gdb-4_18~1150 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0983267416af1fc226fb5dfdd393659d41facc15;p=external%2Fbinutils.git * libbfd.c (bfd_log2): Cast to bfd_vma before shifting, not after. From Chris Torek . --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index cb3a22c..417bd33 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +Sat Sep 19 23:51:47 1998 Ian Lance Taylor + + * libbfd.c (bfd_log2): Cast to bfd_vma before shifting, not + after. From Chris Torek . + Sat Sep 19 22:42:23 1998 Doug Rabson * elflink.h (elf_link_add_object_symbols): Ensure that the warning diff --git a/bfd/libbfd.c b/bfd/libbfd.c index cd8f896..8563ed7 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -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 #include #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); }