This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch committed: Provide own version of ffsll
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Fri, 27 Mar 2009 22:23:51 -0700
- Subject: gold patch committed: Provide own version of ffsll
gold uses ffsll, particularly since gcc expands it inline when
possible. However, some systems don't have ffsll. I committed this
patch to add a version when the system does not have it. I also tweaked
the other replacement functions, adding declarations so that they would
build without warnings.
Ian
2009-03-27 Ian Lance Taylor <iant@google.com>
* ffsll.c: New file.
* configure.ac: Call AC_REPLACE_FUNCS on ffsll.
* gold.h (ffsll): Declare if HAVE_FFSLL is not defined.
* ftruncate.c (ftruncate): Declare before definition.
* mremap.c (mremap): Likewise.
* pread.c (pread): Likewise.
* configure, Makefile.in, config.in: Rebuild.
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gold/configure.ac,v
retrieving revision 1.40
diff -u -p -r1.40 configure.ac
--- configure.ac 27 Mar 2009 23:21:09 -0000 1.40
+++ configure.ac 28 Mar 2009 05:19:58 -0000
@@ -312,7 +312,7 @@ LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_
AC_SUBST(LFS_CFLAGS)
AC_CHECK_FUNCS(chsize)
-AC_REPLACE_FUNCS(pread ftruncate mremap)
+AC_REPLACE_FUNCS(pread ftruncate mremap ffsll)
# Link in zlib if we can. This allows us to write compressed sections.
AC_SEARCH_LIBS(zlibVersion, z, [AC_CHECK_HEADERS(zlib.h)])
Index: ffsll.c
===================================================================
RCS file: ffsll.c
diff -N ffsll.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ffsll.c 28 Mar 2009 05:19:58 -0000
@@ -0,0 +1,43 @@
+/* ffsll.c -- version of ffsll for gold. */
+
+/* Copyright 2009 Free Software Foundation, Inc.
+ Written by Ian Lance Taylor <iant@google.com>.
+
+ This file is part of gold.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+#include "config.h"
+
+#include <string.h>
+
+extern int ffsll (long long);
+
+/* This file implements ffsll for systems which don't have it. We use
+ ffsll if possible because gcc supports it as a builtin which will
+ use a machine instruction if there is one. */
+
+int
+ffsll (long long arg)
+{
+ unsigned long long i;
+ int ret;
+
+ ret = 0;
+ for (i = (unsigned long long) arg; i != 0; i >>= 1)
+ ++ret;
+ return ret;
+}
Index: ftruncate.c
===================================================================
RCS file: /cvs/src/src/gold/ftruncate.c,v
retrieving revision 1.1
diff -u -p -r1.1 ftruncate.c
--- ftruncate.c 17 Mar 2009 22:25:30 -0000 1.1
+++ ftruncate.c 28 Mar 2009 05:19:58 -0000
@@ -9,6 +9,8 @@
#include <sys/types.h>
#include <fcntl.h>
+extern int ftruncate (int, off_t);
+
#ifdef F_CHSIZE
int
Index: gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.33
diff -u -p -r1.33 gold.h
--- gold.h 27 Mar 2009 23:21:09 -0000 1.33
+++ gold.h 28 Mar 2009 05:19:58 -0000
@@ -127,7 +127,11 @@ extern "C" int ftruncate(int, off_t);
#ifndef HAVE_MREMAP
#define MREMAP_MAYMOVE 1
-extern "C" void *mremap (void *, size_t, size_t, int, ...);
+extern "C" void *mremap(void *, size_t, size_t, int, ...);
+#endif
+
+#ifndef HAVE_FFSLL
+extern "C" int ffsll(long long);
#endif
namespace gold
Index: mremap.c
===================================================================
RCS file: /cvs/src/src/gold/mremap.c,v
retrieving revision 1.1
diff -u -p -r1.1 mremap.c
--- mremap.c 27 Mar 2009 23:21:09 -0000 1.1
+++ mremap.c 28 Mar 2009 05:19:58 -0000
@@ -40,6 +40,8 @@
# define MAP_ANONYMOUS MAP_ANON
#endif
+extern void *mremap (void *, size_t, size_t, int, ...);
+
void *
mremap (void *old_address, size_t old_size, size_t new_size,
int flags ATTRIBUTE_UNUSED, ...)
Index: pread.c
===================================================================
RCS file: /cvs/src/src/gold/pread.c,v
retrieving revision 1.1
diff -u -p -r1.1 pread.c
--- pread.c 25 Sep 2007 06:43:17 -0000 1.1
+++ pread.c 28 Mar 2009 05:19:58 -0000
@@ -30,8 +30,10 @@
#include <sys/types.h>
#include <unistd.h>
+extern ssize_t pread (int, void *, size_t, off_t);
+
ssize_t
-pread(int fd, void* buf, size_t count, off_t offset)
+pread (int fd, void *buf, size_t count, off_t offset)
{
if (lseek(fd, offset, SEEK_SET) != offset)
return -1;