Refresh mclinker local patches in NDK

against new ToT e228dc7948dc809a8b90048a24c60f2ebf4255fd
FYI, previous patches apply to 33345c102c4ab54f7e426eceab6fb7e603dca9ee
and some have been upstream'd

Change-Id: I9d5d4168190ba8a234385d24a5e1cf2ae1f9b30f
diff --git a/build/tools/toolchain-patches/mclinker/0001-Add-GCC-collect2-compatibility-flags.patch b/build/tools/toolchain-patches/mclinker/0001-Add-GCC-collect2-compatibility-flags.patch
index 6fb7d0e..90aa246 100644
--- a/build/tools/toolchain-patches/mclinker/0001-Add-GCC-collect2-compatibility-flags.patch
+++ b/build/tools/toolchain-patches/mclinker/0001-Add-GCC-collect2-compatibility-flags.patch
@@ -1,21 +1,21 @@
-From bd187102557cfff78b1fe929db3466a3c775ebde Mon Sep 17 00:00:00 2001
+From 48fca1b6f9b1f958bc524fa3d63f982a39a495ef Mon Sep 17 00:00:00 2001
 From: Andrew Hsieh <andrewhsieh@google.com>
-Date: Fri, 22 Feb 2013 12:30:18 +0800
-Subject: Add GCC/collect2 compatibility flags
+Date: Tue, 19 Mar 2013 10:33:45 -0700
+Subject: [PATCH 1/5] Add GCC/collect2 compatibility flags
 
 Add -use-gold, -use-mcld, and use-ld passed by GCC/collect2
 both ld.bfd ld.gold ignore
 
-Change-Id: Iaa1cb032c773d99bdc26ebf7335965c76e03a22d
+Change-Id: Ia64efd9ab64e06eedd720d46ef4627fae3801392
 ---
- tools/llvm-mcld/llvm-mcld.cpp |   29 +++++++++++++++++++
- 1 files changed, 29 insertions(+), 0 deletions(-)
+ tools/llvm-mcld/llvm-mcld.cpp | 17 +++++++++++++++++
+ 1 file changed, 17 insertions(+)
 
 diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
-index 088ba07..e478729 100644
+index 92dec92..7a3a0c4 100644
 --- a/tools/llvm-mcld/llvm-mcld.cpp
 +++ b/tools/llvm-mcld/llvm-mcld.cpp
-@@ -792,6 +792,35 @@ ArgTextSegAddr("Ttext",
+@@ -799,6 +799,23 @@ ArgTextSegAddr("Ttext",
                 cl::init(-1U));
  
  //===----------------------------------------------------------------------===//
@@ -36,21 +36,9 @@
 +          cl::desc("GCC/collect2 compatibility: uses ld.bfd.  Ignored"),
 +          cl::init(false));
 +
-+static cl::opt<bool>
-+ArgEL("EL",
-+          cl::desc("GCC/collect2 compatibility: MIPS little endian.  Ignored"),
-+          cl::init(false));
-+
-+static cl::opt<bool>
-+ArgEB("EB",
-+          cl::desc("GCC/collect2 compatibility: MIPS big endian.  Ignored"),
-+          cl::init(false));
-+
-+
-+//===----------------------------------------------------------------------===//
  // non-member functions
  //===----------------------------------------------------------------------===//
  /// GetOutputStream - get the output stream.
 -- 
-1.7.7.3
+1.8.1.3
 
diff --git a/build/tools/toolchain-patches/mclinker/0002-Compile-agsint-llvm-3.2.patch b/build/tools/toolchain-patches/mclinker/0002-Compile-agsint-llvm-3.2.patch
index e34b649..34edf22 100644
--- a/build/tools/toolchain-patches/mclinker/0002-Compile-agsint-llvm-3.2.patch
+++ b/build/tools/toolchain-patches/mclinker/0002-Compile-agsint-llvm-3.2.patch
@@ -1,23 +1,37 @@
-From fb2eb10813621ec22963258220abd41e592fc430 Mon Sep 17 00:00:00 2001
+From 21b4a36988a3cd59fb40615eaec6d468d5045a1f Mon Sep 17 00:00:00 2001
 From: Andrew Hsieh <andrewhsieh@google.com>
-Date: Fri, 22 Feb 2013 12:33:36 +0800
-Subject: Compile agsint llvm 3.2
+Date: Tue, 19 Mar 2013 10:35:10 -0700
+Subject: [PATCH 2/5] Compile agsint llvm 3.2
 
 Current mclinker needs LLVM -r 173175 which contains re-org of
 some headers from since LLVM 3.2.  This patch is to roll back
 so we can build from LLVM 3.2
 
-Change-Id: I634b7b0fa085e5bdb7a0a2861c47d6063bf36d25
+Change-Id: Iea929ae893269a6f7d5293e20b9641c917ec920b
 ---
- lib/CodeGen/MCLDTargetMachine.cpp |    2 +-
- lib/CodeGen/MCLinker.cpp          |    2 +-
- lib/Target/X86/X86Emulation.cpp   |    3 +--
- lib/Target/X86/X86LDBackend.cpp   |    3 +--
- tools/llvm-mcld/llvm-mcld.cpp     |    6 +++---
- 5 files changed, 7 insertions(+), 9 deletions(-)
+ configure.ac                      | 2 +-
+ lib/CodeGen/MCLDTargetMachine.cpp | 2 +-
+ lib/CodeGen/MCLinker.cpp          | 2 +-
+ lib/Target/X86/X86Emulation.cpp   | 3 +--
+ lib/Target/X86/X86LDBackend.cpp   | 3 +--
+ tools/llvm-mcld/llvm-mcld.cpp     | 6 +++---
+ 6 files changed, 8 insertions(+), 10 deletions(-)
 
+diff --git a/configure.ac b/configure.ac
+index c56d333..70fecd4 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -101,7 +101,7 @@ AC_CHECK_HEADERS([sys/mman.h])
+ 
+ ####################
+ # Configure LLVM
+-CHECK_LLVM([3.3])
++CHECK_LLVM([3.2])
+ ENUM_MCLD_TARGETS
+ CHECK_ALONE_TARGET
+ 
 diff --git a/lib/CodeGen/MCLDTargetMachine.cpp b/lib/CodeGen/MCLDTargetMachine.cpp
-index 785ef1f..8f5d998 100644
+index 57da5b5..9afadad 100644
 --- a/lib/CodeGen/MCLDTargetMachine.cpp
 +++ b/lib/CodeGen/MCLDTargetMachine.cpp
 @@ -26,7 +26,7 @@
@@ -57,7 +71,7 @@
    }
    else {
 diff --git a/lib/Target/X86/X86LDBackend.cpp b/lib/Target/X86/X86LDBackend.cpp
-index 85c80a7..2203499 100644
+index 87c1192..4001170 100644
 --- a/lib/Target/X86/X86LDBackend.cpp
 +++ b/lib/Target/X86/X86LDBackend.cpp
 @@ -46,8 +46,7 @@ X86GNULDBackend::X86GNULDBackend(const LinkerConfig& pConfig,
@@ -71,10 +85,10 @@
      m_RelaEntrySize = 12;
      if (arch == Triple::x86)
 diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
-index e478729..1f77ed1 100644
+index 7a3a0c4..98bdcad 100644
 --- a/tools/llvm-mcld/llvm-mcld.cpp
 +++ b/tools/llvm-mcld/llvm-mcld.cpp
-@@ -24,9 +24,9 @@
+@@ -25,9 +25,9 @@
  
  #include <llvm/PassManager.h>
  #include <llvm/Pass.h>
@@ -85,8 +99,8 @@
 +#include <llvm/DataLayout.h>
 +#include <llvm/LLVMContext.h>
  #include <llvm/ADT/Triple.h>
+ #include <llvm/ADT/StringSwitch.h>
  #include <llvm/MC/SubtargetFeature.h>
- #include <llvm/Support/CommandLine.h>
 -- 
-1.7.7.3
+1.8.1.3
 
diff --git a/build/tools/toolchain-patches/mclinker/0003-Fix-mingw-build.patch b/build/tools/toolchain-patches/mclinker/0003-Fix-mingw-build.patch
index 03e71c6..351bdc7 100644
--- a/build/tools/toolchain-patches/mclinker/0003-Fix-mingw-build.patch
+++ b/build/tools/toolchain-patches/mclinker/0003-Fix-mingw-build.patch
@@ -1,549 +1,230 @@
-From 9a50212671d7df41e624421c16ff67c5ebff1062 Mon Sep 17 00:00:00 2001
+From 3157e53522e3fa5232c56fdbba378ebdf2f3ef4f Mon Sep 17 00:00:00 2001
 From: Andrew Hsieh <andrewhsieh@google.com>
-Date: Wed, 27 Feb 2013 16:34:52 +0800
-Subject: [PATCH] Fix mingw build
+Date: Tue, 19 Mar 2013 10:38:57 -0700
+Subject: [PATCH 3/5] Fix mingw build
 
-Change-Id: I11f3ac34154aa5cd1f2d4f9630f877e5bf0e5f6a
+Change-Id: I8d1669bf1d89cad60e8b49a946feee52734c4a23
 ---
- debug/Makefile.am                  |    1 +
- include/mcld/LD/Diagnostic.h       |    6 +
- include/mcld/LD/DiagnosticEngine.h |    1 +
- include/mcld/LD/MsgHandler.h       |    7 ++
- include/mcld/Support/FileHandle.h  |    2 +
- include/mcld/Support/mingw/mman.h  |   55 +++++++++++
- lib/LD/Diagnostic.cpp              |    5 +
- lib/Support/FileHandle.cpp         |    4 +
- lib/Support/FileSystem.cpp         |    3 +
- lib/Support/Path.cpp               |   10 ++-
- lib/Support/Space.cpp              |   14 +++
- lib/Support/Unix/FileSystem.inc    |   20 ++++
- lib/Support/Unix/PathV3.inc        |   10 ++
- lib/Support/mingw/mman.inc         |  180 ++++++++++++++++++++++++++++++++++++
- lib/Support/raw_ostream.cpp        |    2 +-
- lib/Target/GNULDBackend.cpp        |    4 +
- lib/Target/Mips/MipsLDBackend.cpp  |    4 +
- m4/llvm.m4                         |    2 +-
- optimized/Makefile.am              |    1 +
- tools/llvm-mcld/llvm-mcld.cpp      |    2 +-
- 20 files changed, 329 insertions(+), 4 deletions(-)
- create mode 100644 include/mcld/Support/mingw/mman.h
- create mode 100644 lib/Support/mingw/mman.inc
+ include/mcld/Support/Path.h        |  6 ++++--
+ lib/Support/Directory.cpp          |  2 +-
+ lib/Support/Path.cpp               |  4 ++--
+ lib/Support/Windows/FileSystem.inc | 19 +++++++++++++++++++
+ lib/Support/Windows/PathV3.inc     | 15 +++++++++++++--
+ lib/Support/Windows/System.inc     |  5 +++++
+ lib/Support/raw_ostream.cpp        |  2 +-
+ lib/Target/GNULDBackend.cpp        |  4 ++++
+ lib/Target/Mips/MipsLDBackend.cpp  |  4 ++++
+ tools/llvm-mcld/llvm-mcld.cpp      | 13 +++++++++++++
+ 10 files changed, 66 insertions(+), 8 deletions(-)
 
-diff --git a/debug/Makefile.am b/debug/Makefile.am
-index e41d1aa..cf8442a 100644
---- a/debug/Makefile.am
-+++ b/debug/Makefile.am
-@@ -174,6 +174,7 @@ SOURCE = ${LIBDIR}/ADT/StringEntry.cpp \
- 	${LIBDIR}/Support/Windows/FileSystem.inc \
- 	${LIBDIR}/Support/Windows/PathV3.inc \
- 	${LIBDIR}/Support/Windows/System.inc \
-+	${LIBDIR}/Support/mingw/mman.inc \
- 	${LIBDIR}/CodeGen/MCLDTargetMachine.cpp \
- 	${LIBDIR}/CodeGen/MCLinker.cpp \
- 	${LIBDIR}/Object/ObjectLinker.cpp \
-diff --git a/include/mcld/LD/Diagnostic.h b/include/mcld/LD/Diagnostic.h
-index 5e7d436..2b125db 100644
---- a/include/mcld/LD/Diagnostic.h
-+++ b/include/mcld/LD/Diagnostic.h
-@@ -64,6 +64,12 @@ public:
-     return (unsigned int)m_Engine.state().ArgumentVals[pIdx];
-   }
+diff --git a/include/mcld/Support/Path.h b/include/mcld/Support/Path.h
+index 399c56d..b84d55a 100644
+--- a/include/mcld/Support/Path.h
++++ b/include/mcld/Support/Path.h
+@@ -28,7 +28,7 @@ namespace mcld {
+ namespace sys  {
+ namespace fs   {
  
-+  unsigned long long getArgULongLong(unsigned int pIdx) const {
-+    assert(getArgKind(pIdx) == DiagnosticEngine::ak_ulonglong &&
-+           "Invalid argument accessor!");
-+    return (unsigned long long)m_Engine.state().ArgumentVals[pIdx];
-+  }
-+
-   bool getArgBool(unsigned int pIdx) const {
-     assert(getArgKind(pIdx) == DiagnosticEngine::ak_bool &&
-            "Invalid argument accessor!");
-diff --git a/include/mcld/LD/DiagnosticEngine.h b/include/mcld/LD/DiagnosticEngine.h
-index 9d24c7a..f3d3b3c 100644
---- a/include/mcld/LD/DiagnosticEngine.h
-+++ b/include/mcld/LD/DiagnosticEngine.h
-@@ -53,6 +53,7 @@ public:
-     ak_c_string,    // const char *
-     ak_sint,        // int
-     ak_uint,        // unsigned int
-+    ak_ulonglong,   // unsigned long long, (eg. size_t in 64-bit)
-     ak_bool         // bool
-   };
+-#if defined(MCLD_ON_WIN32)
++#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__)
+ const wchar_t preferred_separator = L'\\';
+ const wchar_t separator = L'\\';
+ const wchar_t colon = L':';
+@@ -50,7 +50,7 @@ const char    dot = L'.';
+ class Path
+ {
+ public:
+-#if defined(MCLD_ON_WIN32)
++#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__)
+   typedef wchar_t                            ValueType;
+   typedef std::wstring                       StringType;
+ #else
+@@ -93,7 +93,9 @@ public:
+   { return m_PathName.c_str(); }
  
-diff --git a/include/mcld/LD/MsgHandler.h b/include/mcld/LD/MsgHandler.h
-index c89f744..9b1ed80 100644
---- a/include/mcld/LD/MsgHandler.h
-+++ b/include/mcld/LD/MsgHandler.h
-@@ -103,6 +103,13 @@ operator<<(const MsgHandler& pHandler, unsigned long pValue)
+   std::string string() const;
++#if !defined(__MINGW32__)
+   std::wstring wstring() const;
++#endif
+ 
+   // -----  decomposition  ----- //
+   Path parent_path() const;
+diff --git a/lib/Support/Directory.cpp b/lib/Support/Directory.cpp
+index 827df59..d19d6a0 100644
+--- a/lib/Support/Directory.cpp
++++ b/lib/Support/Directory.cpp
+@@ -24,7 +24,7 @@ bool is_symlink(FileStatus f)
+   return f.type() == SymlinkFile;
  }
  
- inline const MsgHandler &
-+operator<<(const MsgHandler& pHandler, unsigned long long pValue)
-+{
-+  pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_ulonglong);
-+  return pHandler;
-+}
-+
-+inline const MsgHandler &
- operator<<(const MsgHandler& pHandler, bool pValue)
- {
-   pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool);
-diff --git a/include/mcld/Support/FileHandle.h b/include/mcld/Support/FileHandle.h
-index ce43e0f..4130c7a 100644
---- a/include/mcld/Support/FileHandle.h
-+++ b/include/mcld/Support/FileHandle.h
-@@ -58,12 +58,14 @@ public:
-     ReadOwner   = S_IRUSR,
-     WriteOwner  = S_IWUSR,
-     ExeOwner    = S_IXUSR,
-+#if !defined(_WIN32)
-     ReadGroup   = S_IRGRP,
-     WriteGroup  = S_IWGRP,
-     ExeGroup    = S_IXGRP,
-     ReadOther   = S_IROTH,
-     WriteOther  = S_IWOTH,
-     ExeOther    = S_IXOTH,
-+#endif
-     System      = 0xFFFFFFFF
-   };
+-#if defined(MCLD_ON_WIN32)
++#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__)
+ const Path dot_path(L".");
+ const Path dot_dot_path(L"..");
  
-diff --git a/include/mcld/Support/mingw/mman.h b/include/mcld/Support/mingw/mman.h
-new file mode 100644
-index 0000000..96f68b2
---- /dev/null
-+++ b/include/mcld/Support/mingw/mman.h
-@@ -0,0 +1,55 @@
-+/*
-+ * sys/mman.h
-+ * mman-win32
-+ */
-+
-+#ifndef _SYS_MMAN_H_
-+#define _SYS_MMAN_H_
-+
-+#ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   

-+#define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.

-+#endif						

-+
-+/* All the headers include this file. */
-+#ifndef _MSC_VER
-+#include <_mingw.h>
-+#endif
-+
-+#include <sys/types.h>
-+
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
-+#define PROT_NONE       0
-+#define PROT_READ       1
-+#define PROT_WRITE      2
-+#define PROT_EXEC       4
-+
-+#define MAP_FILE        0
-+#define MAP_SHARED      1
-+#define MAP_PRIVATE     2
-+#define MAP_TYPE        0xf
-+#define MAP_FIXED       0x10
-+#define MAP_ANONYMOUS   0x20
-+#define MAP_ANON        MAP_ANONYMOUS
-+
-+#define MAP_FAILED      ((void *)-1)
-+
-+/* Flags for msync. */
-+#define MS_ASYNC        1
-+#define MS_SYNC         2
-+#define MS_INVALIDATE   4
-+
-+void*   mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
-+int     munmap(void *addr, size_t len);
-+int     mprotect(void *addr, size_t len, int prot);
-+int     msync(void *addr, size_t len, int flags);
-+int     mlock(const void *addr, size_t len);
-+int     munlock(const void *addr, size_t len);
-+
-+#ifdef __cplusplus
-+};
-+#endif
-+
-+#endif /*  _SYS_MMAN_H_ */
-diff --git a/lib/LD/Diagnostic.cpp b/lib/LD/Diagnostic.cpp
-index 786a68b..b596a94 100644
---- a/lib/LD/Diagnostic.cpp
-+++ b/lib/LD/Diagnostic.cpp
-@@ -157,6 +157,11 @@ void Diagnostic::format(const char* pBegin, const char* pEnd,
-         llvm::raw_string_ostream(pOutStr) << val;
-         break;
-       }
-+      case DiagnosticEngine::ak_ulonglong: {
-+        unsigned long long val = getArgULongLong(arg_no);
-+        llvm::raw_string_ostream(pOutStr) << val;
-+        break;
-+      }
-       case DiagnosticEngine::ak_bool: {
-         bool val = getArgBool(arg_no);
-         if (val)
-diff --git a/lib/Support/FileHandle.cpp b/lib/Support/FileHandle.cpp
-index 437e741..52c68a3 100644
---- a/lib/Support/FileHandle.cpp
-+++ b/lib/Support/FileHandle.cpp
-@@ -18,7 +18,11 @@
- #endif
- 
- #include <sys/stat.h>
-+#if defined(HAVE_SYS_MMAN_H)
- #include <sys/mman.h>
-+#elif defined(_WIN32)
-+#include <mcld/Support/mingw/mman.h>
-+#endif
- 
- #if defined(_MSC_VER)
- #include <io.h>
-diff --git a/lib/Support/FileSystem.cpp b/lib/Support/FileSystem.cpp
-index fb2633d..7084a9a 100644
---- a/lib/Support/FileSystem.cpp
-+++ b/lib/Support/FileSystem.cpp
-@@ -27,3 +27,6 @@ using namespace mcld::sys::fs;
- #include "Windows/FileSystem.inc"
- #include "Windows/PathV3.inc" 
- #endif 
-+#if defined(_WIN32)
-+#include "mingw/mman.inc"
-+#endif
-\ No newline at end of file
 diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
-index d359162..2f439de 100644
+index 9989c1a..4a2e28e 100644
 --- a/lib/Support/Path.cpp
 +++ b/lib/Support/Path.cpp
-@@ -78,12 +78,20 @@ Path& Path::append(const Path& pPath)
+@@ -23,7 +23,7 @@ using namespace mcld::sys::fs;
+ // Helper
+ //===--------------------------------------------------------------------===//
+ namespace {
+-#if defined(MCLD_ON_WIN32)
++#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__)
+ bool is_separator(wchar_t value)
+ {
+   return (value == separator || value == preferred_separator);
+@@ -104,7 +104,7 @@ Path& Path::append(const Path& pPath)
      unsigned int new_size = old_size + pPath.native().size();
  
      m_PathName.resize(new_size);
--    strcpy(const_cast<char*>(m_PathName.data()+old_size), pPath.native().data());
-+#if defined(MCLD_ON_WIN32)
-+    wcscpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
-+#else
-+    strcpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
-+#endif
-   }
-   //first path is a,second path is b
-   else if(this->string()[this->native().size()-1] != separator &&
-           pPath.string()[0] != separator) {
-+#if defined(MCLD_ON_WIN32)
-+    m_PathName.append(L"\\");
-+#else
-     m_PathName.append("/");
-+#endif
-     m_PathName.append(pPath.native());
-   }
-   // a/,b or a,/b just append
-diff --git a/lib/Support/Space.cpp b/lib/Support/Space.cpp
-index 6ec2c53..db5ad03 100644
---- a/lib/Support/Space.cpp
-+++ b/lib/Support/Space.cpp
-@@ -16,6 +16,20 @@ using namespace mcld;
- 
+-#if defined(MCLD_ON_WIN32)
++#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__)
+     wcscpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
+ #else
+     strcpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data());
+diff --git a/lib/Support/Windows/FileSystem.inc b/lib/Support/Windows/FileSystem.inc
+index 7ccb958..0708aff 100644
+--- a/lib/Support/Windows/FileSystem.inc
++++ b/lib/Support/Windows/FileSystem.inc
+@@ -8,8 +8,10 @@
  //===----------------------------------------------------------------------===//
- // constant data
-+#if defined(_WIN32)
-+#include <windows.h>
-+int getpagesize (void) 
-+{
-+  static int _pagesize = 0;
-+  if (! _pagesize) 
-+  {
-+    SYSTEM_INFO sysinfo;
-+    GetSystemInfo (&sysinfo);
-+    _pagesize = sysinfo.dwPageSize;
-+  }
-+  return _pagesize;
-+}
-+#endif
- static const off_t PageSize = getpagesize();
+ #include <string>
+ #include <io.h>
++#include <stdio.h>
+ #include <fcntl.h>
+ #include <cstdlib>
++#include <sys/stat.h>
+ #include <mcld/Support/FileHandle.h>
  
- //===----------------------------------------------------------------------===//
-diff --git a/lib/Support/Unix/FileSystem.inc b/lib/Support/Unix/FileSystem.inc
-index ce6d0df..96d1e10 100644
---- a/lib/Support/Unix/FileSystem.inc
-+++ b/lib/Support/Unix/FileSystem.inc
-@@ -36,12 +36,32 @@ int open(const Path& pPath, int pOFlag, int pPerm)
+ #ifndef STDIN_FILENO
+@@ -27,16 +29,29 @@ namespace sys{
+ namespace fs{
+ namespace detail{
+ 
++#if !defined(__MINGW32__)
+ Path::StringType static_library_extension = L".lib";
+ Path::StringType shared_library_extension = L".dll";
+ Path::StringType executable_extension     = L".exe";
+ Path::StringType relocatable_extension    = L".obj";
+ Path::StringType assembly_extension       = L".s";
+ Path::StringType bitcode_extension        = L".bc";
++#else
++Path::StringType static_library_extension = ".lib";
++Path::StringType shared_library_extension = ".dll";
++Path::StringType executable_extension     = ".exe";
++Path::StringType relocatable_extension    = ".obj";
++Path::StringType assembly_extension       = ".s";
++Path::StringType bitcode_extension        = ".bc";
++#endif
+ 
+ int open(const Path& pPath, int pOFlag)
+ {
++#if !defined(__MINGW32__)
+   return ::_wopen(pPath.native().c_str(), pOFlag);
++#else
++  return ::open(pPath.native().c_str(), pOFlag);
++#endif
+ }
+ 
+ int open(const Path& pPath, int pOFlag, int pPerm)
+@@ -52,7 +67,11 @@ int open(const Path& pPath, int pOFlag, int pPerm)
+       pPerm & FileHandle::WriteOther)
+     perm |= _S_IWRITE;
+ 
++#if !defined(__MINGW32__)
+   return ::_wopen(pPath.native().c_str(), pOFlag, perm);
++#else
++  return ::open(pPath.native().c_str(), pOFlag, perm);
++#endif
+ }
  
  ssize_t pread(int pFD, void* pBuf, size_t pCount, size_t pOffset)
- {
-+#if !defined(_WIN32)
-   return ::pread(pFD, pBuf, pCount, pOffset);
-+#else
-+  off_t curr_pos = lseek (pFD, 0, SEEK_CUR);
-+  if (lseek (pFD, pOffset, SEEK_SET) != pOffset)
-+    return -1;
-+  ssize_t retval = read (pFD, pBuf, pCount);
-+  if (lseek (pFD, curr_pos, SEEK_SET) != curr_pos)
-+    return -1;
-+  return retval;    
-+#endif
+diff --git a/lib/Support/Windows/PathV3.inc b/lib/Support/Windows/PathV3.inc
+index db577c0..ed0e712 100644
+--- a/lib/Support/Windows/PathV3.inc
++++ b/lib/Support/Windows/PathV3.inc
+@@ -8,7 +8,7 @@
+ //===----------------------------------------------------------------------===//
+ #include <mcld/Support/Path.h>
+ #include <mcld/Support/Directory.h>
+-#include <Windows.h>
++#include <windows.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <limits.h>
+@@ -30,10 +30,12 @@ std::string Path::string() const
+   return result;
  }
  
- ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, size_t pOffset)
++#if !defined(__MINGW32__)
+ std::wstring Path::wstring() const
  {
-+#if !defined(_WIN32)
-   return ::pwrite(pFD, pBuf, pCount, pOffset);
-+#else
-+  off_t curr_pos = lseek (pFD, 0, SEEK_CUR);
-+  if (lseek (pFD, pOffset, SEEK_SET) != pOffset)
-+    return -1;
-+  ssize_t retval = write (pFD, pBuf, pCount);
-+  if (lseek (pFD, curr_pos, SEEK_SET) != curr_pos)
-+    return -1;
-+  return retval;    
+   return m_PathName;
+ }
 +#endif
+ 
+ //===----------------------------------------------------------------------===//
+ // mcld::sys::fs::detail
+@@ -150,7 +152,11 @@ bool not_found_error(int perrno)
+ void status(const Path& p, FileStatus& pFileStatus)
+ {
+   struct ::_stat path_stat;
++#if !defined(__MINGW32__)
+   if(::_wstat(p.c_str(), &path_stat)!= 0)
++#else
++  if(::_stat(p.c_str(), &path_stat)!= 0)
++#endif
+   {
+     if(not_found_error(errno))
+     {
+@@ -200,8 +206,13 @@ void close_dir(Directory& pDir)
+ 
+ void get_pwd(Path& pPWD)
+ {
+-  wchar_t* pwd = (wchar_t*)malloc(PATH_MAX);
++#if !defined(__MINGW32__)
++  wchar_t* pwd = (wchar_t*)malloc(PATH_MAX*sizeof(wchar_t));
+   pPWD.assign(_wgetcwd(pwd, PATH_MAX));
++#else
++  char* pwd = (char*)malloc(PATH_MAX);
++  pPWD.assign(pwd);
++#endif
+   free(pwd);
  }
  
- int ftruncate(int pFD, size_t pLength)
-diff --git a/lib/Support/Unix/PathV3.inc b/lib/Support/Unix/PathV3.inc
-index 1506e94..65ba267 100644
---- a/lib/Support/Unix/PathV3.inc
-+++ b/lib/Support/Unix/PathV3.inc
-@@ -20,6 +20,10 @@
- #include <stack>
- #include <unistd.h>
- 
-+#if defined(_WIN32)
-+#include <limits.h>
-+#endif
-+
+diff --git a/lib/Support/Windows/System.inc b/lib/Support/Windows/System.inc
+index 8b64c40..ba91105 100644
+--- a/lib/Support/Windows/System.inc
++++ b/lib/Support/Windows/System.inc
+@@ -16,6 +16,11 @@
  namespace mcld{
  namespace sys{
- namespace fs{
-@@ -154,14 +158,19 @@ void status(const Path& p, FileStatus& pFileStatus)
-     pFileStatus.setType(CharacterFile);
-   else if(S_ISFIFO(path_stat.st_mode))
-     pFileStatus.setType(FifoFile);
-+#if !defined(_WIN32)
-   else if(S_ISSOCK(path_stat.st_mode))
-     pFileStatus.setType(SocketFile);
-+#endif    
-   else
-     pFileStatus.setType(TypeUnknown);
- }
  
- void symlink_status(const Path& p, FileStatus& pFileStatus)
++char *strerror(int errnum)
++{
++  return strerror(errnum);
++}
++
+ std::string getDefaultTargetTriple()
  {
-+#if defined(_WIN32)
-+  pFileStatus.setType(FileNotFound);
-+#else
-   struct stat path_stat;
-   if(lstat(p.c_str(), &path_stat)!= 0)
-   {
-@@ -188,6 +197,7 @@ void symlink_status(const Path& p, FileStatus& pFileStatus)
-     pFileStatus.setType(SocketFile);
-   else
-     pFileStatus.setType(TypeUnknown);
-+#endif
- }
- 
- /// read_dir - return true if we read one entry
-diff --git a/lib/Support/mingw/mman.inc b/lib/Support/mingw/mman.inc
-new file mode 100644
-index 0000000..be4be5b
---- /dev/null
-+++ b/lib/Support/mingw/mman.inc
-@@ -0,0 +1,180 @@
-+

-+#include <windows.h>

-+#include <errno.h>

-+#include <io.h>

-+

-+#include "mcld/Support/mingw/mman.h"

-+

-+#ifndef FILE_MAP_EXECUTE

-+#define FILE_MAP_EXECUTE    0x0020

-+#endif /* FILE_MAP_EXECUTE */

-+

-+static int __map_mman_error(const DWORD err, const int deferr)

-+{

-+    if (err == 0)

-+        return 0;

-+    //TODO: implement

-+    return err;

-+}

-+

-+static DWORD __map_mmap_prot_page(const int prot)

-+{

-+    DWORD protect = 0;

-+    

-+    if (prot == PROT_NONE)

-+        return protect;

-+        

-+    if ((prot & PROT_EXEC) != 0)

-+    {

-+        protect = ((prot & PROT_WRITE) != 0) ? 

-+                    PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;

-+    }

-+    else

-+    {

-+        protect = ((prot & PROT_WRITE) != 0) ?

-+                    PAGE_READWRITE : PAGE_READONLY;

-+    }

-+    

-+    return protect;

-+}

-+

-+static DWORD __map_mmap_prot_file(const int prot)

-+{

-+    DWORD desiredAccess = 0;

-+    

-+    if (prot == PROT_NONE)

-+        return desiredAccess;

-+        

-+    if ((prot & PROT_READ) != 0)

-+        desiredAccess |= FILE_MAP_READ;

-+    if ((prot & PROT_WRITE) != 0)

-+        desiredAccess |= FILE_MAP_WRITE;

-+    if ((prot & PROT_EXEC) != 0)

-+        desiredAccess |= FILE_MAP_EXECUTE;

-+    

-+    return desiredAccess;

-+}

-+

-+void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)

-+{

-+    HANDLE fm, h;

-+    

-+    void * map = MAP_FAILED;

-+    

-+#ifdef _MSC_VER

-+#pragma warning(push)

-+#pragma warning(disable: 4293)

-+#endif

-+

-+    const DWORD dwFileOffsetLow = (sizeof(off_t) <= sizeof(DWORD)) ? 

-+                    (DWORD)off : (DWORD)(off & 0xFFFFFFFFL);

-+    const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ?

-+                    (DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL);

-+    const DWORD protect = __map_mmap_prot_page(prot);

-+    const DWORD desiredAccess = __map_mmap_prot_file(prot);

-+

-+    const off_t maxSize = off + (off_t)len;

-+

-+    const DWORD dwMaxSizeLow = (sizeof(off_t) <= sizeof(DWORD)) ? 

-+                    (DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL);

-+    const DWORD dwMaxSizeHigh = (sizeof(off_t) <= sizeof(DWORD)) ?

-+                    (DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL);

-+

-+#ifdef _MSC_VER

-+#pragma warning(pop)

-+#endif

-+

-+    errno = 0;

-+    

-+    if (len == 0 

-+        /* Unsupported flag combinations */

-+        || (flags & MAP_FIXED) != 0

-+        /* Usupported protection combinations */

-+        || prot == PROT_EXEC)

-+    {

-+        errno = EINVAL;

-+        return MAP_FAILED;

-+    }

-+    

-+    h = ((flags & MAP_ANONYMOUS) == 0) ? 

-+                    (HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE;

-+

-+    if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE)

-+    {

-+        errno = EBADF;

-+        return MAP_FAILED;

-+    }

-+

-+    fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL);

-+

-+    if (fm == NULL)

-+    {

-+        errno = __map_mman_error(GetLastError(), EPERM);

-+        return MAP_FAILED;

-+    }

-+  

-+    map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len);

-+

-+    CloseHandle(fm);

-+  

-+    if (map == NULL)

-+    {

-+        errno = __map_mman_error(GetLastError(), EPERM);

-+        return MAP_FAILED;

-+    }

-+

-+    return map;

-+}

-+

-+int munmap(void *addr, size_t len)

-+{

-+    if (UnmapViewOfFile(addr))

-+        return 0;

-+        

-+    errno =  __map_mman_error(GetLastError(), EPERM);

-+    

-+    return -1;

-+}

-+

-+int mprotect(void *addr, size_t len, int prot)

-+{

-+    DWORD newProtect = __map_mmap_prot_page(prot);

-+    DWORD oldProtect = 0;

-+    

-+    if (VirtualProtect(addr, len, newProtect, &oldProtect))

-+        return 0;

-+    

-+    errno =  __map_mman_error(GetLastError(), EPERM);

-+    

-+    return -1;

-+}

-+

-+int msync(void *addr, size_t len, int flags)

-+{

-+    if (FlushViewOfFile(addr, len))

-+        return 0;

-+    

-+    errno =  __map_mman_error(GetLastError(), EPERM);

-+    

-+    return -1;

-+}

-+

-+int mlock(const void *addr, size_t len)

-+{

-+    if (VirtualLock((LPVOID)addr, len))

-+        return 0;

-+        

-+    errno =  __map_mman_error(GetLastError(), EPERM);

-+    

-+    return -1;

-+}

-+

-+int munlock(const void *addr, size_t len)

-+{

-+    if (VirtualUnlock((LPVOID)addr, len))

-+        return 0;

-+        

-+    errno =  __map_mman_error(GetLastError(), EPERM);

-+    

-+    return -1;

-+}

+   return MCLD_DEFAULT_TARGET_TRIPLE;
 diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
-index e294bc3..836438b 100644
+index 57213ed..4797245 100644
 --- a/lib/Support/raw_ostream.cpp
 +++ b/lib/Support/raw_ostream.cpp
-@@ -12,7 +12,7 @@
- # include <unistd.h>
+@@ -17,7 +17,7 @@
+ #include <io.h>
  #endif
  
 -#if defined(_MSC_VER)
-+#if defined(_WIN32)
++#if defined(_MSC_VER) || defined(__MINGW32__)
  #include <io.h>
  #ifndef STDIN_FILENO
  # define STDIN_FILENO 0
 diff --git a/lib/Target/GNULDBackend.cpp b/lib/Target/GNULDBackend.cpp
-index 3e8915d..67c28cf 100644
+index 12a2100..3e00c12 100644
 --- a/lib/Target/GNULDBackend.cpp
 +++ b/lib/Target/GNULDBackend.cpp
 @@ -37,6 +37,10 @@
@@ -558,7 +239,7 @@
  
  //===--------------------------------------------------------------------===//
 diff --git a/lib/Target/Mips/MipsLDBackend.cpp b/lib/Target/Mips/MipsLDBackend.cpp
-index 8a62bd3..2f8f2fa 100644
+index 3db1c47..ae34f50 100644
 --- a/lib/Target/Mips/MipsLDBackend.cpp
 +++ b/lib/Target/Mips/MipsLDBackend.cpp
 @@ -27,6 +27,10 @@
@@ -572,44 +253,30 @@
  using namespace mcld;
  
  //===----------------------------------------------------------------------===//
-diff --git a/m4/llvm.m4 b/m4/llvm.m4
-index 42c9f58..a8732ad 100644
---- a/m4/llvm.m4
-+++ b/m4/llvm.m4
-@@ -111,7 +111,7 @@ AC_DEFUN([CHECK_LLVM],
- 			*-*-win32*)
- 				llvm_cv_platform_type="Win32" ;;
- 			*-*-mingw*)
--				llvm_cv_platform_type="Win32" ;;
-+				llvm_cv_platform_type="Unix" ;;
- 			*-*-haiku*)
- 				llvm_cv_platform_type="Unix" ;;
- 			*-unknown-eabi*)
-diff --git a/optimized/Makefile.am b/optimized/Makefile.am
-index 2e5df69..efd46dc 100644
---- a/optimized/Makefile.am
-+++ b/optimized/Makefile.am
-@@ -173,6 +173,7 @@ SOURCE = ${LIBDIR}/ADT/StringEntry.cpp \
- 	${LIBDIR}/Support/Windows/FileSystem.inc \
- 	${LIBDIR}/Support/Windows/PathV3.inc \
- 	${LIBDIR}/Support/Windows/System.inc \
-+	${LIBDIR}/Support/mingw/mman.inc \
- 	${LIBDIR}/CodeGen/MCLDTargetMachine.cpp \
- 	${LIBDIR}/CodeGen/MCLinker.cpp \
- 	${LIBDIR}/Object/ObjectLinker.cpp \
 diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
-index 1f77ed1..68eebf0 100644
+index 98bdcad..81a7f55 100644
 --- a/tools/llvm-mcld/llvm-mcld.cpp
 +++ b/tools/llvm-mcld/llvm-mcld.cpp
-@@ -45,7 +45,7 @@
+@@ -47,6 +47,19 @@
  # include <unistd.h>
  #endif
  
--#if defined(_MSC_VER)
-+#if defined(_WIN32)
- #include <io.h>
- #ifndef STDIN_FILENO
- # define STDIN_FILENO 0
++#if defined(_MSC_VER) || defined(__MINGW32__)
++#include <io.h>
++#ifndef STDIN_FILENO
++# define STDIN_FILENO 0
++#endif
++#ifndef STDOUT_FILENO
++# define STDOUT_FILENO 1
++#endif
++#ifndef STDERR_FILENO
++# define STDERR_FILENO 2
++#endif
++#endif
++
+ using namespace llvm;
+ 
+ #ifdef ENABLE_UNITTEST
 -- 
-1.7.7.3
+1.8.1.3
 
diff --git a/build/tools/toolchain-patches/mclinker/0004-Fix-build-id-to-not-accept-next-arg.patch b/build/tools/toolchain-patches/mclinker/0004-Fix-build-id-to-not-accept-next-arg.patch
new file mode 100644
index 0000000..4d7effd
--- /dev/null
+++ b/build/tools/toolchain-patches/mclinker/0004-Fix-build-id-to-not-accept-next-arg.patch
@@ -0,0 +1,38 @@
+From 695734ad55d58ac27b2e0e53ab039834a07b7432 Mon Sep 17 00:00:00 2001
+From: Andrew Hsieh <andrewhsieh@google.com>
+Date: Tue, 19 Mar 2013 10:39:35 -0700
+Subject: [PATCH 4/5] Fix --build-id to not accept next arg
+
+Only the following two forms are allowed
+  --build-id             # default to sha1
+  --build-id=style       # choose style
+
+Neither swallow next arg, which happen to be "-m" when ld.mcld is invoked
+from clang, and cause GNU linker emulation fail
+
+Change-Id: Ib7ea2da8fdca2cb028d3c6be0204fdfe5fa4ccc6
+---
+ tools/llvm-mcld/llvm-mcld.cpp | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
+index 81a7f55..207f4bb 100644
+--- a/tools/llvm-mcld/llvm-mcld.cpp
++++ b/tools/llvm-mcld/llvm-mcld.cpp
+@@ -590,8 +590,12 @@ ArgExcludeLIBS("exclude-libs",
+                cl::desc("Exclude libraries from automatic export"),
+                cl::value_desc("lib1,lib2,..."));
+ 
++static cl::opt<bool>
++ArgBuildIDDefault("build-id",
++           cl::desc("Request creation of \".note.gnu.build-id\" ELF note section in sha1."));
++
+ static cl::opt<std::string>
+-ArgBuildID("build-id",
++ArgBuildID("build-id=",
+            cl::desc("Request creation of \".note.gnu.build-id\" ELF note section."),
+            cl::value_desc("style"));
+ 
+-- 
+1.8.1.3
+
diff --git a/build/tools/toolchain-patches/mclinker/0004-Temp-fix-to-transate-GNU-linker-emulator-to-triple.patch b/build/tools/toolchain-patches/mclinker/0004-Temp-fix-to-transate-GNU-linker-emulator-to-triple.patch
deleted file mode 100644
index db1722a..0000000
--- a/build/tools/toolchain-patches/mclinker/0004-Temp-fix-to-transate-GNU-linker-emulator-to-triple.patch
+++ /dev/null
@@ -1,37 +0,0 @@
-From eed8238837232a0e58ede4cfeca177eb6f53c28d Mon Sep 17 00:00:00 2001
-From: Andrew Hsieh <andrewhsieh@google.com>
-Date: Thu, 28 Feb 2013 12:48:48 +0800
-Subject: [PATCH] Temp fix to transate GNU linker emulator to triple
-
-Change-Id: I847f571422d72fe6607a54f482a5e772e8f585bc
----
- tools/llvm-mcld/llvm-mcld.cpp |   13 +++++++++++++
- 1 files changed, 13 insertions(+), 0 deletions(-)
-
-diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
-index 088ba07..4a407be 100644
---- a/tools/llvm-mcld/llvm-mcld.cpp
-+++ b/tools/llvm-mcld/llvm-mcld.cpp
-@@ -1281,6 +1281,19 @@ int main(int argc, char* argv[])
-   }
-   Module &mod = *M.get();
- 
-+  if (TargetTriple.empty()) {
-+    if (!ArgEmulation.empty()) {
-+      if (ArgEmulation.find("arm") != std::string::npos)
-+        TargetTriple = "arm-linux-androideabi";
-+      else if (ArgEmulation.find("i386") != std::string::npos)
-+        TargetTriple = "i686-linux-android";
-+      else if (ArgEmulation.find("ltsmip") != std::string::npos)
-+        TargetTriple = "mipsel-linux-android";
-+      else
-+        errs() << "** Unknown -m option " << ArgEmulation << " **\n";
-+    }
-+  }
-+   
-   // If we are supposed to override the target triple, do so now.
-   Triple TheTriple;
-   if (!TargetTriple.empty()) {
--- 
-1.7.7.3
-
diff --git a/build/tools/toolchain-patches/mclinker/0005-Fixed-darwin-ld.mcld-GNU-m-emulation-fail.patch b/build/tools/toolchain-patches/mclinker/0005-Fixed-darwin-ld.mcld-GNU-m-emulation-fail.patch
new file mode 100644
index 0000000..75d9530
--- /dev/null
+++ b/build/tools/toolchain-patches/mclinker/0005-Fixed-darwin-ld.mcld-GNU-m-emulation-fail.patch
@@ -0,0 +1,35 @@
+From a414ed878190c6fc68f0b1362223558130c0fca6 Mon Sep 17 00:00:00 2001
+From: Andrew Hsieh <andrewhsieh@google.com>
+Date: Tue, 19 Mar 2013 10:42:09 -0700
+Subject: [PATCH 5/5] Fixed darwin ld.mcld GNU -m emulation fail
+
+GNU -m emulation doesn't provide OS.  If ld.mcld is built on darwin
+the OS is incorrectly set to darwin.  Force to "linux" for Android.
+
+Change-Id: Ibb394fc90f938247643f4b7ef8c02460bd175e9e
+---
+ tools/llvm-mcld/llvm-mcld.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
+index 207f4bb..49fe328 100644
+--- a/tools/llvm-mcld/llvm-mcld.cpp
++++ b/tools/llvm-mcld/llvm-mcld.cpp
+@@ -991,12 +991,12 @@ static Triple ParseEmulation(const std::string& pEmulation)
+ {
+   Triple result = StringSwitch<Triple>(pEmulation)
+     .Case("armelf_linux_eabi", Triple("arm", "", "linux", "gnueabi"))
+-    .Case("elf_i386",          Triple("i386", "", "", "gnu"))
++    .Case("elf_i386",          Triple("i386", "", "linux", "gnu"))
+     .Case("elf_x86_64",        Triple("x86_64", "", "", "gnu"))
+     .Case("elf32_x86_64",      Triple("x86_64", "", "", "gnux32"))
+     .Case("elf_i386_fbsd",     Triple("i386", "", "freebsd", "gnu"))
+     .Case("elf_x86_64_fbsd",   Triple("x86_64", "", "freebsd", "gnu"))
+-    .Case("elf32ltsmip",       Triple("mipsel", "", "", "gnu"))
++    .Case("elf32ltsmip",       Triple("mipsel", "", "linux", "gnu"))
+     .Default(Triple());
+ 
+   if (result.getArch()        == Triple::UnknownArch &&
+-- 
+1.8.1.3
+
diff --git a/build/tools/toolchain-patches/mclinker/0005-Ignore-empty-archive.patch b/build/tools/toolchain-patches/mclinker/0005-Ignore-empty-archive.patch
deleted file mode 100644
index 209515b..0000000
--- a/build/tools/toolchain-patches/mclinker/0005-Ignore-empty-archive.patch
+++ /dev/null
@@ -1,52 +0,0 @@
-From 0b01edd242c89bf970f4604894c09d7545372bc0 Mon Sep 17 00:00:00 2001
-From: Andrew Hsieh <andrewhsieh@google.com>
-Date: Fri, 1 Mar 2013 18:24:12 +0800
-Subject: [PATCH] Ignore empty archive
-
-Change-Id: If0f144cc847790fdc77e997fda455bcaa3ab0b7d
----
- lib/LD/GNUArchiveReader.cpp |   14 ++++++++++++--
- 1 files changed, 12 insertions(+), 2 deletions(-)
-
-diff --git a/lib/LD/GNUArchiveReader.cpp b/lib/LD/GNUArchiveReader.cpp
-index 82e4fec..70a9289 100644
---- a/lib/LD/GNUArchiveReader.cpp
-+++ b/lib/LD/GNUArchiveReader.cpp
-@@ -237,6 +237,11 @@ Input* GNUArchiveReader::readMemberHeader(Archive& pArchiveRoot,
- bool GNUArchiveReader::readSymbolTable(Archive& pArchive)
- {
-   assert(pArchive.getARFile().hasMemArea());
-+  FileHandle *handler = pArchive.getARFile().memArea()->handler();
-+  if (handler->size() == Archive::MAGIC_LEN) {
-+    pArchive.setSymTabSize(0);
-+    return true;
-+  }
- 
-   MemoryRegion* header_region =
-     pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
-@@ -288,6 +293,13 @@ bool GNUArchiveReader::readSymbolTable(Archive& pArchive)
- /// readStringTable - read the strtab for long file name of the archive
- bool GNUArchiveReader::readStringTable(Archive& pArchive)
- {
-+  assert(pArchive.getARFile().hasMemArea());
-+
-+  FileHandle *handler = pArchive.getARFile().memArea()->handler();
-+  if (handler->size() == Archive::MAGIC_LEN) {
-+    return true;
-+  }
-+
-   size_t offset = Archive::MAGIC_LEN +
-                   sizeof(Archive::MemberHeader) +
-                   pArchive.getSymTabSize();
-@@ -295,8 +307,6 @@ bool GNUArchiveReader::readStringTable(Archive& pArchive)
-   if (0x0 != (offset & 1))
-     ++offset;
- 
--  assert(pArchive.getARFile().hasMemArea());
--
-   MemoryRegion* header_region =
-     pArchive.getARFile().memArea()->request((pArchive.getARFile().fileOffset() +
-                                              offset),
--- 
-1.7.7.3
-