Merge "Misc fixes for ld.mcld to build most run-tests.sh"
diff --git a/build/tools/build-llvm.sh b/build/tools/build-llvm.sh
index 44b256d..0b98c91 100755
--- a/build/tools/build-llvm.sh
+++ b/build/tools/build-llvm.sh
@@ -352,11 +352,9 @@
     rm -f $TOOLCHAIN_BUILD_PREFIX/bin/$i.exe
 done
 
-if [ -n "$KEEP_SYMBOLS" ]; then
-    # strip because /usr/bin/install wasn't called with -s
-    test -z "$STRIP" && STRIP=strip
-    $STRIP $TOOLCHAIN_BUILD_PREFIX/bin/*
-fi
+test -z "$STRIP" && STRIP=strip
+$STRIP $TOOLCHAIN_BUILD_PREFIX/bin/*
+$STRIP $TOOLCHAIN_BUILD_PREFIX/lib/*
 
 # copy to toolchain path
 run copy_directory "$TOOLCHAIN_BUILD_PREFIX" "$TOOLCHAIN_PATH"
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 ed3f915..6fb7d0e 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,41 +1,51 @@
 From bd187102557cfff78b1fe929db3466a3c775ebde Mon Sep 17 00:00:00 2001
 From: Andrew Hsieh <andrewhsieh@google.com>
 Date: Fri, 22 Feb 2013 12:30:18 +0800
-Subject: [PATCH 1/2] Add GCC/collect2 compatibility flags
+Subject: 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
 ---
- tools/llvm-mcld/llvm-mcld.cpp |   19 +++++++++++++++++++
- 1 files changed, 19 insertions(+), 0 deletions(-)
+ tools/llvm-mcld/llvm-mcld.cpp |   29 +++++++++++++++++++
+ 1 files changed, 29 insertions(+), 0 deletions(-)
 
 diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp
 index 088ba07..e478729 100644
 --- a/tools/llvm-mcld/llvm-mcld.cpp
 +++ b/tools/llvm-mcld/llvm-mcld.cpp
-@@ -792,6 +792,25 @@ ArgTextSegAddr("Ttext",
+@@ -792,6 +792,35 @@ ArgTextSegAddr("Ttext",
                 cl::init(-1U));
  
  //===----------------------------------------------------------------------===//
 +// Ignored GCC Compatibility Options
 +//===----------------------------------------------------------------------===//
 +static cl::opt<bool>
-+ArgLDgold("use-gold",
++Arguse_gold("use-gold",
 +          cl::desc("GCC/collect2 compatibility: uses ld.gold.  Ignored"),
 +          cl::init(false));
 +
 +static cl::opt<bool>
-+ArgLDmcld("use-mcld",
++Arguse_mcld("use-mcld",
 +          cl::desc("GCC/collect2 compatibility: uses ld.mcld.  Ignored"),
 +          cl::init(false));
 +
 +static cl::opt<bool>
-+ArgLDbfd("use-ld",
++Arguse_ld("use-ld",
 +          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
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 3a41d64..e34b649 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,7 +1,7 @@
 From fb2eb10813621ec22963258220abd41e592fc430 Mon Sep 17 00:00:00 2001
 From: Andrew Hsieh <andrewhsieh@google.com>
 Date: Fri, 22 Feb 2013 12:33:36 +0800
-Subject: [PATCH 2/2] Compile agsint llvm 3.2
+Subject: 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
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
new file mode 100644
index 0000000..db1722a
--- /dev/null
+++ b/build/tools/toolchain-patches/mclinker/0004-Temp-fix-to-transate-GNU-linker-emulator-to-triple.patch
@@ -0,0 +1,37 @@
+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-Ignore-empty-archive.patch b/build/tools/toolchain-patches/mclinker/0005-Ignore-empty-archive.patch
new file mode 100644
index 0000000..209515b
--- /dev/null
+++ b/build/tools/toolchain-patches/mclinker/0005-Ignore-empty-archive.patch
@@ -0,0 +1,52 @@
+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
+