From aa48d470554a0316c48a602838fe7ebc6c8d9506 Mon Sep 17 00:00:00 2001
From: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Date: Thu, 15 Nov 2012 19:31:42 +0100
Subject: [PATCH 3/6] binutils: Port to Android

Change-Id: Ib47c28cbde7a6165206675e75b52c0fdb86dff59
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
---
 bfd/archive.c           |  2 +-
 gold/Makefile.am        |  2 +-
 gold/Makefile.in        |  2 +-
 gold/archive.cc         |  2 +-
 gold/configure          |  7 +++++--
 gold/configure.ac       |  6 +++++-
 gold/gdb-index.cc       |  2 ++
 gold/stringpool.cc      |  4 ++--
 gold/symtab.cc          |  2 +-
 gold/system.h           | 22 ++++++++++++++++------
 libiberty/getpagesize.c |  2 ++
 11 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index 1ed4148..4284da8 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -1880,7 +1880,7 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
     {
       /* Assume we just "made" the member, and fake it.  */
       struct bfd_in_memory *bim = (struct bfd_in_memory *) member->iostream;
-      time (&status.st_mtime);
+      time ((time_t*)&status.st_mtime);
       status.st_uid = getuid ();
       status.st_gid = getgid ();
       status.st_mode = 0644;
diff --git a/gold/Makefile.am b/gold/Makefile.am
index f6ced44..3bb0d11 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -27,7 +27,7 @@ tooldir = $(exec_prefix)/$(target_alias)
 ACLOCAL_AMFLAGS = -I ../bfd -I ../config
 
 AM_CFLAGS = $(WARN_CFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS)
-AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS)
+AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) -Wno-error
 
 AM_CPPFLAGS = \
 	-I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \
diff --git a/gold/Makefile.in b/gold/Makefile.in
index f12832b..8b48dec 100644
--- a/gold/Makefile.in
+++ b/gold/Makefile.in
@@ -392,7 +392,7 @@ SUBDIRS = po testsuite
 tooldir = $(exec_prefix)/$(target_alias)
 ACLOCAL_AMFLAGS = -I ../bfd -I ../config
 AM_CFLAGS = $(WARN_CFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS)
-AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS)
+AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) -Wno-error
 AM_CPPFLAGS = \
 	-I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \
 	-DLOCALEDIR="\"$(datadir)/locale\"" \
diff --git a/gold/archive.cc b/gold/archive.cc
index f2cd848..753266f 100644
--- a/gold/archive.cc
+++ b/gold/archive.cc
@@ -584,7 +584,7 @@ Archive::get_file_and_offset(off_t off, Input_file** input_file, off_t* memoff,
       const char* arch_path = this->filename().c_str();
       const char* basename = lbasename(arch_path);
       if (basename > arch_path)
-        member_name->replace(0, 0,
+        member_name->replace((std::string::size_type)0, 0,
                              this->filename().substr(0, basename - arch_path));
     }
 
diff --git a/gold/configure b/gold/configure
index 7e58cdf..7ccd7db 100755
--- a/gold/configure
+++ b/gold/configure
@@ -6698,8 +6698,11 @@ else
 fi
 
 
-
-LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+# On Android, _FILE_OFFSET_BITS=64 causes unresolved
+# references to 64-bit variants of _M_seek in stlport
+if ! echo $host |grep -q android; then
+	LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+fi
 
 
 for ac_header in sys/mman.h
diff --git a/gold/configure.ac b/gold/configure.ac
index b03c09d..2168ef0 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -471,7 +471,11 @@ AC_SUBST(GOLD_LDADD)
 
 dnl Force support for large files by default.  This may need to be
 dnl host dependent.  If build == host, we can check getconf LFS_CFLAGS.
-LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+# On Android, _FILE_OFFSET_BITS=64 causes unresolved
+# references to 64-bit variants of _M_seek in stlport
+if ! echo $host |grep -q android; then
+	LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+fi
 AC_SUBST(LFS_CFLAGS)
 
 AC_CHECK_HEADERS(sys/mman.h)
diff --git a/gold/gdb-index.cc b/gold/gdb-index.cc
index 91634a4..ccbb240 100644
--- a/gold/gdb-index.cc
+++ b/gold/gdb-index.cc
@@ -29,6 +29,8 @@
 #include "output.h"
 #include "demangle.h"
 
+#include <ctype.h> // for tolower
+
 namespace gold
 {
 
diff --git a/gold/stringpool.cc b/gold/stringpool.cc
index 434b2d6..1780f64 100644
--- a/gold/stringpool.cc
+++ b/gold/stringpool.cc
@@ -76,7 +76,7 @@ Stringpool_template<Stringpool_char>::reserve(unsigned int n)
   // rehash() implementation is broken in gcc 4.0.3's stl
   //this->string_set_.rehash(this->string_set_.size() + n);
   //return;
-#elif defined(HAVE_EXT_HASH_MAP)
+#elif defined(HAVE_EXT_HASH_MAP) || defined(ANDROID)
   this->string_set_.resize(this->string_set_.size() + n);
   return;
 #endif
@@ -499,7 +499,7 @@ template<typename Stringpool_char>
 void
 Stringpool_template<Stringpool_char>::print_stats(const char* name) const
 {
-#if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP)
+#if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP) || defined(ANDROID)
   fprintf(stderr, _("%s: %s entries: %zu; buckets: %zu\n"),
 	  program_name, name, this->string_set_.size(),
 	  this->string_set_.bucket_count());
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 2e17529..e6ae14d 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -3150,7 +3150,7 @@ Symbol_table::sized_write_section_symbol(const Output_section* os,
 void
 Symbol_table::print_stats() const
 {
-#if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP)
+#if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP) || defined(ANDROID)
   fprintf(stderr, _("%s: symbol table entries: %zu; buckets: %zu\n"),
 	  program_name, this->table_.size(), this->table_.bucket_count());
 #else
diff --git a/gold/system.h b/gold/system.h
index 3e6fe1d..a9a9464 100644
--- a/gold/system.h
+++ b/gold/system.h
@@ -87,17 +87,27 @@ struct hash<off_t> : public std::unary_function<off_t, std::size_t>
 } } // Close namespaces.
 #endif // !defined(HAVE_TR1_HASH_OFF_T)
 
-#elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
-
+#elif defined(ANDROID) || (defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET))
+
+#ifdef ANDROID // STLport is a bit like libstdc++ in terms of extensions... But not quite the same
+#include <hash_map>
+#include <hash_set>
+#include <stl/_hash_fun.h>
+#define HASHMAP_NAMESPACE std
+using std::_STLP_PRIV_NAME::__stl_hash_string;
+#else
 #include <ext/hash_map>
 #include <ext/hash_set>
+#define HASHMAP_NAMESPACE __gnu_cxx
+#endif
+
 #include <string>
 
-#define Unordered_set __gnu_cxx::hash_set
-#define Unordered_map __gnu_cxx::hash_map
-#define Unordered_multimap __gnu_cxx::hash_multimap
+#define Unordered_set HASHMAP_NAMESPACE::hash_set
+#define Unordered_map HASHMAP_NAMESPACE::hash_map
+#define Unordered_multimap HASHMAP_NAMESPACE::hash_multimap
 
-namespace __gnu_cxx
+namespace HASHMAP_NAMESPACE
 {
 
 template<>
diff --git a/libiberty/getpagesize.c b/libiberty/getpagesize.c
index 1c3a263..e9d6362 100644
--- a/libiberty/getpagesize.c
+++ b/libiberty/getpagesize.c
@@ -60,11 +60,13 @@ BUGS
 # endif /* PAGESIZE */
 #endif /* GNU_OUR_PAGESIZE */
 
+#ifndef __BIONIC__ /* Bionic implements getpagesize() itself */
 int
 getpagesize (void)
 {
   return (GNU_OUR_PAGESIZE);
 }
+#endif
 
 #else /* VMS */
 
-- 
1.8.3.2

