Various GCC 3.6 and clang build fixes.

Remove #error in common_test.h that fires with clang build and replace with
runtime error.
Fix bit rot caused by not compiling with Wthread-safety.
Fix clang build issues in compiler relating to missing header file definitions
in object files.
Other minor build and tidying issues.

Change-Id: Ife829ab0664581936155be524de46e6181c750b0
diff --git a/src/dex_file_test.cc b/src/dex_file_test.cc
index f075fea..e7899ec 100644
--- a/src/dex_file_test.cc
+++ b/src/dex_file_test.cc
@@ -24,6 +24,7 @@
 class DexFileTest : public CommonTest {};
 
 TEST_F(DexFileTest, Open) {
+  ScopedObjectAccess soa(Thread::Current());
   const DexFile* dex(OpenTestDexFile("Nested"));
   ASSERT_TRUE(dex != NULL);
 }
@@ -54,6 +55,29 @@
   "AAACAAAAQAEAAAEgAAACAAAAVAEAAAYgAAACAAAAiAEAAAEQAAABAAAAqAEAAAIgAAAPAAAArgEA"
   "AAMgAAACAAAAiAIAAAQgAAADAAAAlAIAAAAgAAACAAAAqwIAAAAQAAABAAAAxAIAAA==";
 
+static const DexFile* OpenDexFileBase64(const char* base64,
+                                        const std::string& location) {
+  // decode base64
+  CHECK(base64 != NULL);
+  size_t length;
+  UniquePtr<byte[]> dex_bytes(DecodeBase64(base64, &length));
+  CHECK(dex_bytes.get() != NULL);
+
+  // write to provided file
+  UniquePtr<File> file(OS::OpenFile(location.c_str(), true));
+  CHECK(file.get() != NULL);
+  if (!file->WriteFully(dex_bytes.get(), length)) {
+    PLOG(FATAL) << "Failed to write base64 as dex file";
+  }
+  file.reset();
+
+  // read dex file
+  ScopedObjectAccess soa(Thread::Current());
+  const DexFile* dex_file = DexFile::Open(location, location);
+  CHECK(dex_file != NULL);
+  return dex_file;
+}
+
 TEST_F(DexFileTest, Header) {
   ScratchFile tmp;
   UniquePtr<const DexFile> raw(OpenDexFileBase64(kRawDex, tmp.GetFilename()));
@@ -86,17 +110,20 @@
 }
 
 TEST_F(DexFileTest, GetLocationChecksum) {
+  ScopedObjectAccess soa(Thread::Current());
   const DexFile* raw(OpenTestDexFile("Main"));
   EXPECT_NE(raw->GetHeader().checksum_, raw->GetLocationChecksum());
 }
 
 TEST_F(DexFileTest, GetChecksum) {
   uint32_t checksum;
+  ScopedObjectAccess soa(Thread::Current());
   EXPECT_TRUE(DexFile::GetChecksum(GetLibCoreDexFileName(), checksum));
   EXPECT_EQ(java_lang_dex_file_->GetLocationChecksum(), checksum);
 }
 
 TEST_F(DexFileTest, ClassDefs) {
+  ScopedObjectAccess soa(Thread::Current());
   const DexFile* raw(OpenTestDexFile("Nested"));
   ASSERT_TRUE(raw != NULL);
   EXPECT_EQ(2U, raw->NumClassDefs());
@@ -109,6 +136,7 @@
 }
 
 TEST_F(DexFileTest, CreateMethodSignature) {
+  ScopedObjectAccess soa(Thread::Current());
   const DexFile* raw(OpenTestDexFile("CreateMethodSignature"));
   ASSERT_TRUE(raw != NULL);
   EXPECT_EQ(1U, raw->NumClassDefs());
@@ -164,6 +192,7 @@
 }
 
 TEST_F(DexFileTest, FindStringId) {
+  ScopedObjectAccess soa(Thread::Current());
   const DexFile* raw(OpenTestDexFile("CreateMethodSignature"));
   ASSERT_TRUE(raw != NULL);
   EXPECT_EQ(1U, raw->NumClassDefs());