Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py	(revision 174335)
+++ utils/lit/lit/TestRunner.py	(working copy)
@@ -383,7 +383,8 @@
             if script and script[-1][-1] == '\\':
                 script[-1] = script[-1][:-1] + ln
             else:
-                script.append(ln)
+                script.append('gtimeout 5m ' +ln)
+		# do not commit this patch
         elif 'XFAIL:' in ln:
             items = ln[ln.index('XFAIL:') + 6:].split(',')
             xfails.extend([s.strip() for s in items])
Index: utils/lit/lit/LitConfig.py
===================================================================
--- utils/lit/lit/LitConfig.py	(revision 174335)
+++ utils/lit/lit/LitConfig.py	(working copy)
@@ -34,7 +34,8 @@
         self.debug = debug
         self.isWindows = bool(isWindows)
         self.params = dict(params)
-        self.bashPath = None
+	# local hack only, don't commit this patch
+        self.bashPath = '/sw/bin/bash'
 
         # Configuration files to look for when discovering test suites.
         self.config_prefix = config_prefix or 'lit'
Index: tools/bugpoint-passes/CMakeLists.txt
===================================================================
--- tools/bugpoint-passes/CMakeLists.txt	(revision 174335)
+++ tools/bugpoint-passes/CMakeLists.txt	(working copy)
@@ -1,3 +1,6 @@
+# patch: this should be built as a bundle/module/plug-in
+set(MODULE TRUE)
+
 if( NOT LLVM_BUILD_TOOLS )
   set(EXCLUDE_FROM_ALL ON)
 endif()
Index: lib/Transforms/Hello/CMakeLists.txt
===================================================================
--- lib/Transforms/Hello/CMakeLists.txt	(revision 174335)
+++ lib/Transforms/Hello/CMakeLists.txt	(working copy)
@@ -1,3 +1,5 @@
+# patch: this should be built as a bundle/module/plug-in
+set(MODULE TRUE)
 add_llvm_loadable_module( LLVMHello
   Hello.cpp
   )
Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/MemorySanitizer.cpp	(revision 174335)
+++ lib/Transforms/Instrumentation/MemorySanitizer.cpp	(working copy)
@@ -178,8 +178,15 @@
  private:
   void initializeCallbacks(Module &M);
 
+// workaround accessibility bug in g++-4.0
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+ public:
+#endif
   /// \brief Track origins (allocation points) of uninitialized values.
   bool TrackOrigins;
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+ private:
+#endif
 
   DataLayout *TD;
   LLVMContext *C;
Index: lib/MC/MCDisassembler/CMakeLists.txt
===================================================================
--- lib/MC/MCDisassembler/CMakeLists.txt	(revision 174335)
+++ lib/MC/MCDisassembler/CMakeLists.txt	(working copy)
@@ -1,3 +1,27 @@
 add_llvm_library(LLVMMCDisassembler
   Disassembler.cpp
   )
+
+target_link_libraries(LLVMMCDisassembler
+  LLVMMC
+  LLVMMCParser
+  LLVMSupport
+  LLVMTarget
+  )
+
+foreach(t ${LLVM_TARGETS_TO_BUILD})
+  set(td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t})
+  if(EXISTS ${td}/TargetInfo/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Info")
+  endif()
+  if(EXISTS ${td}/MCTargetDesc/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Desc")
+  endif()
+  if(EXISTS ${td}/AsmParser/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}AsmParser")
+  endif()
+  if(EXISTS ${td}/Disassembler/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Disassembler")
+  endif()
+endforeach(t)
+
Index: lib/CodeGen/MachineFunction.cpp
===================================================================
--- lib/CodeGen/MachineFunction.cpp	(revision 174335)
+++ lib/CodeGen/MachineFunction.cpp	(working copy)
@@ -166,8 +166,10 @@
 MachineInstr *
 MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID,
                                     DebugLoc DL, bool NoImp) {
-  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
-    MachineInstr(*this, MCID, DL, NoImp);
+  MachineInstr * ret = InstructionRecycler.Allocate<MachineInstr>(Allocator);
+    new (ret) MachineInstr(*this, MCID, DL, NoImp);
+  ret->getFlags();	// assertion check
+  return ret;
 }
 
 /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
@@ -176,8 +178,10 @@
 ///
 MachineInstr *
 MachineFunction::CloneMachineInstr(const MachineInstr *Orig) {
-  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
-             MachineInstr(*this, *Orig);
+  MachineInstr * ret = InstructionRecycler.Allocate<MachineInstr>(Allocator);
+    new (ret) MachineInstr(*this, *Orig);
+  ret->getFlags();	// assertion check
+  return ret;
 }
 
 /// DeleteMachineInstr - Delete the given MachineInstr.
@@ -186,6 +190,7 @@
 /// ~MachineInstr() destructor must be empty.
 void
 MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
+  MI->getFlags();	// assertion check
   // Strip it for parts. The operand array and the MI object itself are
   // independently recyclable.
   if (MI->Operands)
Index: lib/Support/Unix/Memory.inc
===================================================================
--- lib/Support/Unix/Memory.inc	(revision 174335)
+++ lib/Support/Unix/Memory.inc	(working copy)
@@ -51,7 +51,7 @@
 	 llvm::sys::Memory::MF_EXEC:
     return PROT_READ | PROT_WRITE | PROT_EXEC;
   case llvm::sys::Memory::MF_EXEC:
-    return PROT_EXEC;
+    return PROT_EXEC | PROT_READ;	// patch from Roman Divacky, bug 14278
   default:
     llvm_unreachable("Illegal memory protection flag specified!");
   }
Index: lib/Support/Unix/Signals.inc
===================================================================
--- lib/Support/Unix/Signals.inc	(revision 174335)
+++ lib/Support/Unix/Signals.inc	(working copy)
@@ -318,7 +318,7 @@
 void llvm::sys::PrintStackTraceOnErrorSignal() {
   AddSignalHandler(PrintStackTraceSignalHandler, 0);
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && defined(MACH_EXCEPTION_CODES) && defined(EXC_MASK_CRASH)
   // Environment variable to disable any kind of crash dialog.
   if (getenv("LLVM_DISABLE_CRASH_REPORT")) {
     mach_port_t self = mach_task_self();
Index: lib/Support/stacktrace.cc
===================================================================
--- lib/Support/stacktrace.cc	(revision 0)
+++ lib/Support/stacktrace.cc	(revision 0)
@@ -0,0 +1,183 @@
+/**
+	\file "util/stacktrace.cc"
+	Implementation of stacktrace class.
+	$Id: stacktrace.cc,v 1.1 2010/03/14 22:25:17 fang Exp $
+ */
+
+// ENABLE_STACKTRACE is forced for this module, regardless of pre-definitions!
+#define	ENABLE_STACKTRACE	1
+
+#include "llvm/Support/stacktrace.h"
+#include <iostream>
+#include <iterator>
+
+namespace util {
+using std::list;
+using std::ostream;
+using std::stack;
+using std::ostream_iterator;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+/**
+	Guarantee that ios is initialized.  
+ */
+static const std::ios_base::Init ios_init;
+
+//=============================================================================
+/**
+	Private implementation class, not visible to other modules.  
+	Only written as a class for convenient static initialization.  
+	To be able to trace function calls that occur during static 
+	initialization, we must guarantee that the manager's static 
+	objects are initialized first!  Global initialization ordering is
+	generally non-trivial, so resort to the techinique of 
+	interfacing through reference functions which will guarantee 
+	a one-time initialization upon first invocation.  
+	(This technique is also used in util::persistent_object_manager.)
+ */
+class stacktrace::manager {
+public:
+	typedef	stacktrace::stack_text_type	stack_text_type;
+	typedef	stacktrace::stack_echo_type	stack_echo_type;
+	typedef	stacktrace::stack_streams_type	stack_streams_type;
+
+	static stack_text_type		stack_text;
+	static stack_text_type		stack_indent;
+	static stack_echo_type		stack_echo;
+	static stack_streams_type	stack_streams;
+
+private:
+	manager() {
+		// initialization moved to static initialization below.
+	}
+
+	~manager() { }
+
+public:
+	static
+	ostream&
+	print_auto_indent(ostream& o) {
+		// guarantee iostream initialized before first used.  
+		static const std::ios_base::Init ios_init;
+		static const stack_text_type& si(manager::stack_indent);
+		// INVARIANT(o.good());
+		ostream_iterator<string> osi(o);
+		copy(si.begin(), si.end(), osi);
+		return o;
+	}
+
+};	// end class stacktrace::manager
+
+//-----------------------------------------------------------------------------
+// static construction
+
+stacktrace::manager::stack_text_type
+stacktrace::manager::stack_text;
+
+stacktrace::manager::stack_text_type
+stacktrace::manager::stack_indent;
+
+stacktrace::manager::stack_echo_type
+stacktrace::manager::stack_echo;
+
+stacktrace::manager::stack_streams_type
+stacktrace::manager::stack_streams;
+
+static const int stack_echo_init =
+(stacktrace::manager::stack_echo.push(1), 1);
+
+static const int stack_stream_init =
+(stacktrace::manager::stack_streams.push(&cerr), 1);
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Stacktrace stream manipulator.  
+ */
+const stacktrace::indent
+stacktrace_auto_indent = stacktrace::indent();
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Uses the stacktrace's position to automatically indent.  
+ */
+ostream&
+operator << (ostream& o, const stacktrace::indent&) {
+	// need static initializers?
+	return stacktrace::manager::print_auto_indent(o) << ":  ";
+}
+
+//=============================================================================
+// class stacktrace method definitions
+
+stacktrace::stacktrace(const string& s) {
+	// cannot use string (without ref-count) because it may be destroyed
+	// prematurely during static destruction, char* is robust and permanent.
+	static const char* const
+		default_stack_indent_string = "| ";	// permanent
+	// must be static or else, new ref_counts will be locally released
+	manager::stack_text.push_back(s);
+	if (manager::stack_echo.top()) {
+		ostream& os(*manager::stack_streams.top());
+			manager::print_auto_indent(os) << "\\-{ " <<
+				manager::stack_text.back() << endl;
+	}
+	manager::stack_indent.push_back(default_stack_indent_string);
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+stacktrace::~stacktrace() {
+	manager::stack_indent.pop_back();
+	if (manager::stack_echo.top()) {
+		ostream& os(*manager::stack_streams.top());
+			manager::print_auto_indent(os) << "/-} " <<
+				manager::stack_text.back() << endl;
+	}
+	manager::stack_text.pop_back();
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Returns reference to the current stacktrace output stream.
+ */
+ostream&
+stacktrace::stream(void) {
+	return *manager::stack_streams.top();
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+void
+stacktrace::full_dump(void) {
+	ostream& current_stream(stream());
+	ostream_iterator<string> osi(current_stream, "\n");
+	copy(manager::stack_text.begin(), manager::stack_text.end(), osi);
+	current_stream << endl;
+}
+
+//=============================================================================
+// struct stacktrace::echo method definitions
+
+stacktrace::echo::echo(const int i) {
+	manager::stack_echo.push(i);
+}
+
+stacktrace::echo::~echo() {
+	manager::stack_echo.pop();
+}
+
+//=============================================================================
+// struct redirect_stacktrace method definitions
+
+stacktrace::redirect::redirect(ostream& o) {
+	manager::stack_streams.push(&o);
+}
+
+stacktrace::redirect::~redirect() {
+	manager::stack_streams.pop();
+}
+
+//=============================================================================
+}	// end namespace util
+
+
Index: lib/Support/CMakeLists.txt
===================================================================
--- lib/Support/CMakeLists.txt	(revision 174335)
+++ lib/Support/CMakeLists.txt	(working copy)
@@ -108,4 +108,7 @@
   Windows/system_error.inc
   Windows/ThreadLocal.inc
   Windows/TimeValue.inc
+
+# fang's debugging tools
+  stacktrace.cc
   )
Index: lib/Support/APInt.cpp
===================================================================
--- lib/Support/APInt.cpp	(revision 174335)
+++ lib/Support/APInt.cpp	(working copy)
@@ -79,6 +79,7 @@
   if (isSigned && int64_t(val) < 0)
     for (unsigned i = 1; i < getNumWords(); ++i)
       pVal[i] = -1ULL;
+  sane_BitWidth();
 }
 
 void APInt::initSlowCase(const APInt& that) {
@@ -158,6 +159,7 @@
     pVal[0] = RHS;
     memset(pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
   }
+  sane_BitWidth();
   return clearUnusedBits();
 }
 
Index: lib/Support/Atomic.cpp
===================================================================
--- lib/Support/Atomic.cpp	(revision 174335)
+++ lib/Support/Atomic.cpp	(working copy)
@@ -21,6 +21,16 @@
 #undef MemoryFence
 #endif
 
+#if defined(__APPLE__) && 0
+#include <libkern/OSAtomic.h>
+// __APPLE__ should take precedence over __GNUC__
+// sys::cas_flag is int32_t from Support/Atomic.h, so use '32' variants
+// prototypes lack the 'volatile' qualifier, so we need to cast them away
+template <class T>
+static inline
+T* vcast(volatile T* ptr) { return const_cast<T*>(ptr); }
+#endif
+
 #if defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
 #define GNU_ATOMICS
 #endif
@@ -28,14 +38,16 @@
 void sys::MemoryFence() {
 #if LLVM_HAS_ATOMICS == 0
   return;
-#else
-#  if defined(GNU_ATOMICS)
+/**
+#elif defined(__APPLE__)
+  OSMemoryBarrier();
+**/
+#elif defined(GNU_ATOMICS)
   __sync_synchronize();
-#  elif defined(_MSC_VER)
+#elif defined(_MSC_VER)
   MemoryBarrier();
-#  else
+#else
 # error No memory fence implementation for your platform!
-#  endif
 #endif
 }
 
@@ -47,6 +59,10 @@
   if (result == old_value)
     *ptr = new_value;
   return result;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicCompareAndSwap32(old_value, new_value, vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_val_compare_and_swap(ptr, old_value, new_value);
 #elif defined(_MSC_VER)
@@ -60,6 +76,10 @@
 #if LLVM_HAS_ATOMICS == 0
   ++(*ptr);
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicIncrement32(vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_add_and_fetch(ptr, 1);
 #elif defined(_MSC_VER)
@@ -73,6 +93,10 @@
 #if LLVM_HAS_ATOMICS == 0
   --(*ptr);
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicDecrement32(vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_sub_and_fetch(ptr, 1);
 #elif defined(_MSC_VER)
@@ -86,6 +110,10 @@
 #if LLVM_HAS_ATOMICS == 0
   *ptr += val;
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicAdd32(val, vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_add_and_fetch(ptr, val);
 #elif defined(_MSC_VER)
Index: lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
===================================================================
--- lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp	(revision 174335)
+++ lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp	(working copy)
@@ -54,6 +54,7 @@
 }
 
 namespace {
+#if 0
 class PPCMachObjectWriter : public MCMachObjectTargetWriter {
 public:
   PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType,
@@ -67,6 +68,9 @@
     llvm_unreachable("Relocation emission for MachO/PPC unimplemented!");
   }
 };
+#else
+// not anymore!
+#endif
 
 class PPCAsmBackend : public MCAsmBackend {
 const Target &TheTarget;
@@ -157,12 +161,20 @@
 
     MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
       bool is64 = getPointerSize() == 8;
+#if 0
       return createMachObjectWriter(new PPCMachObjectWriter(
                                       /*Is64Bit=*/is64,
                                       (is64 ? object::mach::CTM_PowerPC64 :
                                        object::mach::CTM_PowerPC),
                                       object::mach::CSPPC_ALL),
                                     OS, /*IsLittleEndian=*/false);
+#else
+      return createPPCMachObjectWriter(OS, 
+                                      /*Is64Bit=*/is64,
+                                      (is64 ? object::mach::CTM_PowerPC64 :
+                                       object::mach::CTM_PowerPC),
+                                      object::mach::CSPPC_ALL);
+#endif
     }
 
     virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
Index: lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt
===================================================================
--- lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt	(revision 174335)
+++ lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt	(working copy)
@@ -4,6 +4,7 @@
   PPCMCAsmInfo.cpp
   PPCMCCodeEmitter.cpp
   PPCPredicates.cpp
+  PPCMachObjectWriter.cpp
   PPCELFObjectWriter.cpp
   )
 
Index: lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
===================================================================
--- lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp	(revision 0)
+++ lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp	(revision 0)
@@ -0,0 +1,803 @@
+//===-- PPCMachObjectWriter.cpp - PPC Mach-O Writer -----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+/**
+The skeleton of this file was ripped from X86MachObjectWriter.cpp.
+NB: I have little clue what I'm doing. -- fangism
+note to self: some clues might be found in gcc/config/{rs6000.c,darwin.h},
+if I can ever decipher it. 
+This file once existed before MC:
+https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_19/lib/Target/PowerPC/PPCMachOWriter.cpp
+	authors: Nate Begeman, Louis Gerbarg, ...?
+other references:
+http://opensource.apple.com/source/cctools/cctools-809/as/ppc.c
+**/
+
+#include "MCTargetDesc/PPCMCTargetDesc.h"
+#include "MCTargetDesc/PPCFixupKinds.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/MC/MCAsmLayout.h"
+#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCMachObjectWriter.h"
+#include "llvm/MC/MCSectionMachO.h"
+#include "llvm/MC/MCValue.h"
+#include "llvm/Object/MachOFormat.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Format.h"
+
+#define	ENABLE_STACKTRACE		1
+
+#include "llvm/Support/stacktrace.h"	// for debugging
+
+using namespace llvm;
+using namespace llvm::object;
+
+/// don't know if this is needed for ppc64/mach-o
+#define	IMPL_SEPARATE_PPC64_RELOCATION		0
+/// no idea what this is
+#define	IMPL_SEPARATE_TLV_RELOCATION		0
+
+namespace {
+class PPCMachObjectWriter : public MCMachObjectTargetWriter {
+  bool RecordScatteredRelocation(MachObjectWriter *Writer,
+                                 const MCAssembler &Asm,
+                                 const MCAsmLayout &Layout,
+                                 const MCFragment *Fragment,
+                                 const MCFixup &Fixup,
+                                 MCValue Target,
+                                 unsigned Log2Size,
+                                 uint64_t &FixedValue);
+#if IMPL_SEPARATE_TLV_RELOCATION
+  void RecordTLVPRelocation(MachObjectWriter *Writer,
+                            const MCAssembler &Asm,
+                            const MCAsmLayout &Layout,
+                            const MCFragment *Fragment,
+                            const MCFixup &Fixup,
+                            MCValue Target,
+                            uint64_t &FixedValue);
+#endif
+
+  void RecordPPCRelocation(MachObjectWriter *Writer,
+                              const MCAssembler &Asm,
+                              const MCAsmLayout &Layout,
+                              const MCFragment *Fragment,
+                              const MCFixup &Fixup,
+                              MCValue Target,
+                              uint64_t &FixedValue);
+#if IMPL_SEPARATE_PPC64_RELOCATION
+  void RecordPPC64Relocation(MachObjectWriter *Writer,
+                              const MCAssembler &Asm,
+                              const MCAsmLayout &Layout,
+                              const MCFragment *Fragment,
+                              const MCFixup &Fixup,
+                              MCValue Target,
+                              uint64_t &FixedValue);
+#endif
+public:
+  PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType,
+                      uint32_t CPUSubtype)
+    : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype,
+                               /*UseAggressiveSymbolFolding=*/Is64Bit) {}
+
+  void RecordRelocation(MachObjectWriter *Writer,
+                        const MCAssembler &Asm, const MCAsmLayout &Layout,
+                        const MCFragment *Fragment, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) {
+    llvm_unreachable("Relocation emission for MachO/PPC unimplemented, until Fang gets around to hacking...");
+#if IMPL_SEPARATE_PPC64_RELOCATION
+    if (Writer->is64Bit())
+      RecordPPC64Relocation(Writer, Asm, Layout, Fragment, Fixup, Target,
+                             FixedValue);
+    else
+#endif
+      RecordPPCRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
+                          FixedValue);
+  }
+};
+}
+
+#if IMPL_SEPARATE_PPC64_RELOCATION
+static bool isFixupKindRIPRel(unsigned Kind) {
+  return Kind == PPC::reloc_riprel_4byte ||
+    Kind == PPC::reloc_riprel_4byte_movq_load;
+}
+#endif
+
+#if 0
+static unsigned getFixupKindLog2Size(unsigned Kind) {
+  switch (Kind) {
+  default:
+    llvm_unreachable("invalid fixup kind!");
+  case FK_PCRel_1:
+  case FK_Data_1: return 0;
+  case FK_PCRel_2:
+  case FK_Data_2: return 1;
+  case FK_PCRel_4:
+    // FIXME: Remove these!!!
+  case PPC::reloc_riprel_4byte:
+  case PPC::reloc_riprel_4byte_movq_load:
+  case PPC::reloc_signed_4byte:
+  case FK_Data_4: return 2;
+  case FK_Data_8: return 3;
+  }
+}
+#else
+/**
+	Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
+	Outline based on PPCELFObjectWriter::getRelocTypeInner().
+ */
+static
+unsigned
+getRelocType(
+	const MCValue &Target,
+	const unsigned FixupKind,	// from Fixup.getKind()
+	const bool IsPCRel) {
+  const MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
+    MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
+  // determine the type of the relocation
+  unsigned Type;
+  if (IsPCRel) {			// relative to PC
+    switch (FixupKind) {
+    default:
+      llvm_unreachable("Unimplemented (relative)");
+    case PPC::fixup_ppc_br24:
+      Type = macho::RIT_PPC_BR24;	// R_PPC_REL24
+      break;
+    case PPC::fixup_ppc_brcond14:
+      Type = macho::RIT_PPC_BR14;
+      break;
+    case PPC::fixup_ppc_lo16:
+      Type = macho::RIT_PPC_LO16;
+      break;
+    case PPC::fixup_ppc_ha16:
+      Type = macho::RIT_PPC_HA16;
+      break;
+    case PPC::fixup_ppc_lo14:
+      Type = macho::RIT_PPC_LO14;
+      break;
+#if 0
+    case FK_Data_4:
+    case FK_PCRel_4:
+      Type = macho::RIT_PPC_REL32;
+      break;
+    case FK_Data_8:
+    case FK_PCRel_8:
+      Type = macho::RIT_PPC64_REL64;
+      break;
+#endif
+    }
+  } else {
+    switch (FixupKind) {
+      default: llvm_unreachable("invalid fixup kind (absolute)!");
+#if 0
+#if 0
+    case PPC::fixup_ppc_br24:
+      Type = macho::RIT_PPC_ADDR24;		// RIT_PPC_BR24?
+      break;
+    case PPC::fixup_ppc_brcond14:
+      Type = macho::RIT_PPC_ADDR14;		// RIT_PPC_BR14?
+      break;
+#endif
+    case PPC::fixup_ppc_ha16:
+      switch (Modifier) {
+      default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TPREL16_HA:
+        Type = macho::RIT_PPC_HA16;		// RIT_PPC_TPREL16_HA;
+        break;
+#if 0
+      case MCSymbolRefExpr::VK_PPC_DTPREL16_HA:
+        Type = macho::RIT_PPC64_DTPREL16_HA;
+        break;
+#endif
+      case MCSymbolRefExpr::VK_None:
+        Type = macho::RIT_PPC_HA16;		// RIT_PPC_ADDR16_HA;
+	break;
+#if 0
+      case MCSymbolRefExpr::VK_PPC_TOC16_HA:
+        Type = macho::RIT_PPC64_TOC16_HA;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TPREL16_HA:
+        Type = macho::RIT_PPC64_GOT_TPREL16_HA;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD16_HA:
+        Type = macho::RIT_PPC64_GOT_TLSGD16_HA;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD16_HA:
+        Type = macho::RIT_PPC64_GOT_TLSLD16_HA;
+        break;
+#endif
+      }
+      break;
+    case PPC::fixup_ppc_lo16:
+      switch (Modifier) {
+      default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TPREL16_LO:
+        Type = macho::RIT_PPC_LO16;		// RIT_PPC_TPREL16_LO;
+        break;
+      case MCSymbolRefExpr::VK_PPC_DTPREL16_LO:
+        Type = macho::RIT_PPC64_DTPREL16_LO;
+        break;
+      case MCSymbolRefExpr::VK_None:
+        Type = macho::RIT_PPC_ADDR16_LO;
+	break;
+      case MCSymbolRefExpr::VK_PPC_TOC16_LO:
+        Type = macho::RIT_PPC64_TOC16_LO;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TLSGD16_LO:
+        Type = macho::RIT_PPC64_GOT_TLSGD16_LO;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD16_LO:
+        Type = macho::RIT_PPC64_GOT_TLSLD16_LO;
+        break;
+      }
+      break;
+    case PPC::fixup_ppc_lo14:
+      Type = macho::RIT_PPC_ADDR14;
+      break;
+    case PPC::fixup_ppc_toc:
+      Type = macho::RIT_PPC64_TOC;
+      break;
+    case PPC::fixup_ppc_toc16:
+      Type = macho::RIT_PPC64_TOC16;
+      break;
+    case PPC::fixup_ppc_toc16_ds:
+      switch (Modifier) {
+      default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TOC_ENTRY:
+        Type = macho::RIT_PPC64_TOC16_DS;
+	break;
+      case MCSymbolRefExpr::VK_PPC_TOC16_LO:
+        Type = macho::RIT_PPC64_TOC16_LO_DS;
+        break;
+      case MCSymbolRefExpr::VK_PPC_GOT_TPREL16_LO:
+        Type = macho::RIT_PPC64_GOT_TPREL16_LO_DS;
+        break;
+      }
+      break;
+    case PPC::fixup_ppc_tlsreg:
+      Type = macho::RIT_PPC64_TLS;
+      break;
+    case PPC::fixup_ppc_nofixup:
+      switch (Modifier) {
+      default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TLSGD:
+        Type = macho::RIT_PPC64_TLSGD;
+        break;
+      case MCSymbolRefExpr::VK_PPC_TLSLD:
+        Type = macho::RIT_PPC64_TLSLD;
+        break;
+      }
+      break;
+    case FK_Data_8:
+      switch (Modifier) {
+      default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TOC:
+        Type = macho::RIT_PPC64_TOC;
+        break;
+      case MCSymbolRefExpr::VK_None:
+        Type = macho::RIT_PPC64_ADDR64;
+	break;
+      }
+      break;
+    case FK_Data_4:
+      Type = macho::RIT_PPC_ADDR32;
+      break;
+    case FK_Data_2:
+      Type = macho::RIT_PPC_ADDR16;
+      break;
+#endif
+    }
+  }
+  return Type;
+}
+#endif
+
+#if IMPL_SEPARATE_PPC64_RELOCATION
+void PPCMachObjectWriter::RecordPPC64Relocation(MachObjectWriter *Writer,
+                                                 const MCAssembler &Asm,
+                                                 const MCAsmLayout &Layout,
+                                                 const MCFragment *Fragment,
+                                                 const MCFixup &Fixup,
+                                                 MCValue Target,
+                                                 uint64_t &FixedValue) {
+/***
+  unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
+  unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind());
+  unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
+
+  // See <reloc.h>.
+  uint32_t FixupOffset =
+    Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
+  uint32_t FixupAddress =
+    Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
+  int64_t Value = 0;
+  unsigned Index = 0;
+  unsigned IsExtern = 0;
+  unsigned Type = 0;
+
+  Value = Target.getConstant();
+
+  if (IsPCRel) {
+    // Compensate for the relocation offset, Darwin x86_64 relocations only have
+    // the addend and appear to have attempted to define it to be the actual
+    // expression addend without the PCrel bias. However, instructions with data
+    // following the relocation are not accommodated for (see comment below
+    // regarding SIGNED{1,2,4}), so it isn't exactly that either.
+    Value += 1LL << Log2Size;
+  }
+
+  if (Target.isAbsolute()) { // constant
+    // SymbolNum of 0 indicates the absolute section.
+    Type = macho::RIT_PPC_64_Unsigned;
+    Index = 0;
+
+    // FIXME: I believe this is broken, I don't think the linker can understand
+    // it. I think it would require a local relocation, but I'm not sure if that
+    // would work either. The official way to get an absolute PCrel relocation
+    // is to use an absolute symbol (which we don't support yet).
+    if (IsPCRel) {
+      IsExtern = 1;
+      Type = macho::RIT_PPC_64_Branch;
+    }
+  } else if (Target.getSymB()) { // A - B + constant
+    const MCSymbol *A = &Target.getSymA()->getSymbol();
+    MCSymbolData &A_SD = Asm.getSymbolData(*A);
+    const MCSymbolData *A_Base = Asm.getAtom(&A_SD);
+
+    const MCSymbol *B = &Target.getSymB()->getSymbol();
+    MCSymbolData &B_SD = Asm.getSymbolData(*B);
+    const MCSymbolData *B_Base = Asm.getAtom(&B_SD);
+
+    // Neither symbol can be modified.
+    if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
+        Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None)
+      report_fatal_error("unsupported relocation of modified symbol");
+
+    // We don't support PCrel relocations of differences. Darwin 'as' doesn't
+    // implement most of these correctly.
+    if (IsPCRel)
+      report_fatal_error("unsupported pc-relative relocation of difference");
+
+    // The support for the situation where one or both of the symbols would
+    // require a local relocation is handled just like if the symbols were
+    // external.  This is certainly used in the case of debug sections where the
+    // section has only temporary symbols and thus the symbols don't have base
+    // symbols.  This is encoded using the section ordinal and non-extern
+    // relocation entries.
+
+    // Darwin 'as' doesn't emit correct relocations for this (it ends up with a
+    // single SIGNED relocation); reject it for now.  Except the case where both
+    // symbols don't have a base, equal but both NULL.
+    if (A_Base == B_Base && A_Base)
+      report_fatal_error("unsupported relocation with identical base");
+
+    Value += Writer->getSymbolAddress(&A_SD, Layout) -
+      (A_Base == NULL ? 0 : Writer->getSymbolAddress(A_Base, Layout));
+    Value -= Writer->getSymbolAddress(&B_SD, Layout) -
+      (B_Base == NULL ? 0 : Writer->getSymbolAddress(B_Base, Layout));
+
+    if (A_Base) {
+      Index = A_Base->getIndex();
+      IsExtern = 1;
+    }
+    else {
+      Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
+      IsExtern = 0;
+    }
+    Type = macho::RIT_PPC_64_Unsigned;
+
+    macho::RelocationEntry MRE;
+    MRE.Word0 = FixupOffset;
+    MRE.Word1 = ((Index     <<  0) |
+                 (IsPCRel   << 24) |
+                 (Log2Size  << 25) |
+                 (IsExtern  << 27) |
+                 (Type      << 28));
+    Writer->addRelocation(Fragment->getParent(), MRE);
+
+    if (B_Base) {
+      Index = B_Base->getIndex();
+      IsExtern = 1;
+    }
+    else {
+      Index = B_SD.getFragment()->getParent()->getOrdinal() + 1;
+      IsExtern = 0;
+    }
+    Type = macho::RIT_PPC_64_Subtractor;
+  } else {
+    const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
+    MCSymbolData &SD = Asm.getSymbolData(*Symbol);
+    const MCSymbolData *Base = Asm.getAtom(&SD);
+
+    // Relocations inside debug sections always use local relocations when
+    // possible. This seems to be done because the debugger doesn't fully
+    // understand x86_64 relocation entries, and expects to find values that
+    // have already been fixed up.
+    if (Symbol->isInSection()) {
+      const MCSectionMachO &Section = static_cast<const MCSectionMachO&>(
+        Fragment->getParent()->getSection());
+      if (Section.hasAttribute(MCSectionMachO::S_ATTR_DEBUG))
+        Base = 0;
+    }
+
+    // x86_64 almost always uses external relocations, except when there is no
+    // symbol to use as a base address (a local symbol with no preceding
+    // non-local symbol).
+    if (Base) {
+      Index = Base->getIndex();
+      IsExtern = 1;
+
+      // Add the local offset, if needed.
+      if (Base != &SD)
+        Value += Layout.getSymbolOffset(&SD) - Layout.getSymbolOffset(Base);
+    } else if (Symbol->isInSection() && !Symbol->isVariable()) {
+      // The index is the section ordinal (1-based).
+      Index = SD.getFragment()->getParent()->getOrdinal() + 1;
+      IsExtern = 0;
+      Value += Writer->getSymbolAddress(&SD, Layout);
+
+      if (IsPCRel)
+        Value -= FixupAddress + (1 << Log2Size);
+    } else if (Symbol->isVariable()) {
+      const MCExpr *Value = Symbol->getVariableValue();
+      int64_t Res;
+      bool isAbs = Value->EvaluateAsAbsolute(Res, Layout,
+                                             Writer->getSectionAddressMap());
+      if (isAbs) {
+        FixedValue = Res;
+        return;
+      } else {
+        report_fatal_error("unsupported relocation of variable '" +
+                           Symbol->getName() + "'");
+      }
+    } else {
+      report_fatal_error("unsupported relocation of undefined symbol '" +
+                         Symbol->getName() + "'");
+    }
+
+    MCSymbolRefExpr::VariantKind Modifier = Target.getSymA()->getKind();
+    if (IsPCRel) {
+      if (IsRIPRel) {
+        if (Modifier == MCSymbolRefExpr::VK_GOTPCREL) {
+          // x86_64 distinguishes movq foo@GOTPCREL so that the linker can
+          // rewrite the movq to an leaq at link time if the symbol ends up in
+          // the same linkage unit.
+          if (unsigned(Fixup.getKind()) == PPC::reloc_riprel_4byte_movq_load)
+            Type = macho::RIT_PPC_64_GOTLoad;
+          else
+            Type = macho::RIT_PPC_64_GOT;
+        }  else if (Modifier == MCSymbolRefExpr::VK_TLVP) {
+          Type = macho::RIT_PPC_64_TLV;
+        }  else if (Modifier != MCSymbolRefExpr::VK_None) {
+          report_fatal_error("unsupported symbol modifier in relocation");
+        } else {
+          Type = macho::RIT_PPC_64_Signed;
+
+          // The Darwin x86_64 relocation format has a problem where it cannot
+          // encode an address (L<foo> + <constant>) which is outside the atom
+          // containing L<foo>. Generally, this shouldn't occur but it does
+          // happen when we have a RIPrel instruction with data following the
+          // relocation entry (e.g., movb $012, L0(%rip)). Even with the PCrel
+          // adjustment Darwin x86_64 uses, the offset is still negative and the
+          // linker has no way to recognize this.
+          //
+          // To work around this, Darwin uses several special relocation types
+          // to indicate the offsets. However, the specification or
+          // implementation of these seems to also be incomplete; they should
+          // adjust the addend as well based on the actual encoded instruction
+          // (the additional bias), but instead appear to just look at the final
+          // offset.
+          switch (-(Target.getConstant() + (1LL << Log2Size))) {
+          case 1: Type = macho::RIT_PPC_64_Signed1; break;
+          case 2: Type = macho::RIT_PPC_64_Signed2; break;
+          case 4: Type = macho::RIT_PPC_64_Signed4; break;
+          }
+        }
+      } else {
+        if (Modifier != MCSymbolRefExpr::VK_None)
+          report_fatal_error("unsupported symbol modifier in branch "
+                             "relocation");
+
+        Type = macho::RIT_PPC_64_Branch;
+      }
+    } else {
+      if (Modifier == MCSymbolRefExpr::VK_GOT) {
+        Type = macho::RIT_PPC_64_GOT;
+      } else if (Modifier == MCSymbolRefExpr::VK_GOTPCREL) {
+        // GOTPCREL is allowed as a modifier on non-PCrel instructions, in which
+        // case all we do is set the PCrel bit in the relocation entry; this is
+        // used with exception handling, for example. The source is required to
+        // include any necessary offset directly.
+        Type = macho::RIT_PPC_64_GOT;
+        IsPCRel = 1;
+      } else if (Modifier == MCSymbolRefExpr::VK_TLVP) {
+        report_fatal_error("TLVP symbol modifier should have been rip-rel");
+      } else if (Modifier != MCSymbolRefExpr::VK_None)
+        report_fatal_error("unsupported symbol modifier in relocation");
+      else
+        Type = macho::RIT_PPC_64_Unsigned;
+    }
+  }
+
+  // x86_64 always writes custom values into the fixups.
+  FixedValue = Value;
+
+  // struct relocation_info (8 bytes)
+  macho::RelocationEntry MRE;
+  MRE.Word0 = FixupOffset;
+  MRE.Word1 = ((Index     <<  0) |
+               (IsPCRel   << 24) |
+               (Log2Size  << 25) |
+               (IsExtern  << 27) |
+               (Type      << 28));
+  Writer->addRelocation(Fragment->getParent(), MRE);
+***/
+}
+#endif
+
+bool PPCMachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
+                                                    const MCAssembler &Asm,
+                                                    const MCAsmLayout &Layout,
+                                                    const MCFragment *Fragment,
+                                                    const MCFixup &Fixup,
+                                                    MCValue Target,
+                                                    unsigned Log2Size,
+                                                    uint64_t &FixedValue) {
+/***
+  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
+  unsigned Type = macho::RIT_Vanilla;
+
+  // See <reloc.h>.
+  const MCSymbol *A = &Target.getSymA()->getSymbol();
+  MCSymbolData *A_SD = &Asm.getSymbolData(*A);
+
+  if (!A_SD->getFragment())
+    report_fatal_error("symbol '" + A->getName() +
+                       "' can not be undefined in a subtraction expression");
+
+  uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
+  uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
+  FixedValue += SecAddr;
+  uint32_t Value2 = 0;
+
+  if (const MCSymbolRefExpr *B = Target.getSymB()) {
+    MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
+
+    if (!B_SD->getFragment())
+      report_fatal_error("symbol '" + B->getSymbol().getName() +
+                         "' can not be undefined in a subtraction expression");
+
+    // Select the appropriate difference relocation type.
+    //
+    // Note that there is no longer any semantic difference between these two
+    // relocation types from the linkers point of view, this is done solely for
+    // pedantic compatibility with 'as'.
+    Type = A_SD->isExternal() ? (unsigned)macho::RIT_Difference :
+      (unsigned)macho::RIT_Generic_LocalDifference;
+    Value2 = Writer->getSymbolAddress(B_SD, Layout);
+    FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
+  }
+
+  // Relocations are written out in reverse order, so the PAIR comes first.
+  if (Type == macho::RIT_Difference ||
+      Type == macho::RIT_Generic_LocalDifference) {
+    // If the offset is too large to fit in a scattered relocation,
+    // we're hosed. It's an unfortunate limitation of the MachO format.
+    if (FixupOffset > 0xffffff) {
+      char Buffer[32];
+      format("0x%x", FixupOffset).print(Buffer, sizeof(Buffer));
+      Asm.getContext().FatalError(Fixup.getLoc(),
+                         Twine("Section too large, can't encode "
+                                "r_address (") + Buffer +
+                         ") into 24 bits of scattered "
+                         "relocation entry.");
+      llvm_unreachable("fatal error returned?!");
+    }
+
+    macho::RelocationEntry MRE;
+    MRE.Word0 = ((0         <<  0) |
+                 (macho::RIT_Pair  << 24) |
+                 (Log2Size  << 28) |
+                 (IsPCRel   << 30) |
+                 macho::RF_Scattered);
+    MRE.Word1 = Value2;
+    Writer->addRelocation(Fragment->getParent(), MRE);
+  } else {
+    // If the offset is more than 24-bits, it won't fit in a scattered
+    // relocation offset field, so we fall back to using a non-scattered
+    // relocation. This is a bit risky, as if the offset reaches out of
+    // the block and the linker is doing scattered loading on this
+    // symbol, things can go badly.
+    //
+    // Required for 'as' compatibility.
+    if (FixupOffset > 0xffffff)
+      return false;
+  }
+
+  macho::RelocationEntry MRE;
+  MRE.Word0 = ((FixupOffset <<  0) |
+               (Type        << 24) |
+               (Log2Size    << 28) |
+               (IsPCRel     << 30) |
+               macho::RF_Scattered);
+  MRE.Word1 = Value;
+  Writer->addRelocation(Fragment->getParent(), MRE);
+  return true;
+***/
+}
+
+#if IMPL_SEPARATE_TLV_RELOCATION
+void PPCMachObjectWriter::RecordTLVPRelocation(MachObjectWriter *Writer,
+                                               const MCAssembler &Asm,
+                                               const MCAsmLayout &Layout,
+                                               const MCFragment *Fragment,
+                                               const MCFixup &Fixup,
+                                               MCValue Target,
+                                               uint64_t &FixedValue) {
+/***
+  assert(Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP &&
+         !is64Bit() &&
+         "Should only be called with a 32-bit TLVP relocation!");
+
+  unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
+  uint32_t Value = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  unsigned IsPCRel = 0;
+
+  // Get the symbol data.
+  MCSymbolData *SD_A = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+  unsigned Index = SD_A->getIndex();
+
+  // We're only going to have a second symbol in pic mode and it'll be a
+  // subtraction from the picbase. For 32-bit pic the addend is the difference
+  // between the picbase and the next address.  For 32-bit static the addend is
+  // zero.
+  if (Target.getSymB()) {
+    // If this is a subtraction then we're pcrel.
+    uint32_t FixupAddress =
+      Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
+    MCSymbolData *SD_B = &Asm.getSymbolData(Target.getSymB()->getSymbol());
+    IsPCRel = 1;
+    FixedValue = (FixupAddress - Writer->getSymbolAddress(SD_B, Layout) +
+                  Target.getConstant());
+    FixedValue += 1ULL << Log2Size;
+  } else {
+    FixedValue = 0;
+  }
+
+  // struct relocation_info (8 bytes)
+  macho::RelocationEntry MRE;
+  MRE.Word0 = Value;
+  MRE.Word1 = ((Index                  <<  0) |
+               (IsPCRel                << 24) |
+               (Log2Size               << 25) |
+               (1                      << 27) | // Extern
+               (macho::RIT_Generic_TLV << 28)); // Type
+  Writer->addRelocation(Fragment->getParent(), MRE);
+***/
+}
+#endif
+
+// see PPCELFObjectWriter for a general outline of cases
+void PPCMachObjectWriter::RecordPPCRelocation(MachObjectWriter *Writer,
+                                              const MCAssembler &Asm,
+                                              const MCAsmLayout &Layout,
+                                              const MCFragment *Fragment,
+                                              const MCFixup &Fixup,
+                                              MCValue Target,
+                                              uint64_t &FixedValue) {
+  STACKTRACE_VERBOSE;
+/***
+  unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
+  unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
+
+#if IMPL_SEPARATE_TLV_RELOCATION
+  // If this is a 32-bit TLVP reloc it's handled a bit differently.
+  if (Target.getSymA() &&
+      Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP) {
+    RecordTLVPRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
+                         FixedValue);
+    return;
+  }
+#endif
+
+  // If this is a difference or a defined symbol plus an offset, then we need a
+  // scattered relocation entry. Differences always require scattered
+  // relocations.
+  if (Target.getSymB()) {
+    RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
+                              Target, Log2Size, FixedValue);
+    return;
+  }
+
+  // Get the symbol data, if any.
+  MCSymbolData *SD = 0;
+  if (Target.getSymA())
+    SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+
+  // If this is an internal relocation with an offset, it also needs a scattered
+  // relocation entry.
+  uint32_t Offset = Target.getConstant();
+  if (IsPCRel)
+    Offset += 1 << Log2Size;
+  // Try to record the scattered relocation if needed. Fall back to non
+  // scattered if necessary (see comments in RecordScatteredRelocation()
+  // for details).
+  if (Offset && SD && !Writer->doesSymbolRequireExternRelocation(SD) &&
+      RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
+                                Target, Log2Size, FixedValue))
+    return;
+
+  // See <reloc.h>.
+  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  unsigned Index = 0;
+  unsigned IsExtern = 0;
+  unsigned Type = 0;
+
+  if (Target.isAbsolute()) { // constant
+    // SymbolNum of 0 indicates the absolute section.
+    //
+    // FIXME: Currently, these are never generated (see code below). I cannot
+    // find a case where they are actually emitted.
+    Type = macho::RIT_Vanilla;
+  } else {
+    // Resolve constant variables.
+    if (SD->getSymbol().isVariable()) {
+      int64_t Res;
+      if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
+            Res, Layout, Writer->getSectionAddressMap())) {
+        FixedValue = Res;
+        return;
+      }
+    }
+
+    // Check whether we need an external or internal relocation.
+    if (Writer->doesSymbolRequireExternRelocation(SD)) {
+      IsExtern = 1;
+      Index = SD->getIndex();
+      // For external relocations, make sure to offset the fixup value to
+      // compensate for the addend of the symbol address, if it was
+      // undefined. This occurs with weak definitions, for example.
+      if (!SD->Symbol->isUndefined())
+        FixedValue -= Layout.getSymbolOffset(SD);
+    } else {
+      // The index is the section ordinal (1-based).
+      const MCSectionData &SymSD = Asm.getSectionData(
+        SD->getSymbol().getSection());
+      Index = SymSD.getOrdinal() + 1;
+      FixedValue += Writer->getSectionAddress(&SymSD);
+    }
+    if (IsPCRel)
+      FixedValue -= Writer->getSectionAddress(Fragment->getParent());
+
+    Type = macho::RIT_Vanilla;
+  }
+
+  // struct relocation_info (8 bytes)
+  macho::RelocationEntry MRE;
+  MRE.Word0 = FixupOffset;
+  MRE.Word1 = ((Index     <<  0) |
+               (IsPCRel   << 24) |
+               (Log2Size  << 25) |
+               (IsExtern  << 27) |
+               (Type      << 28));
+  Writer->addRelocation(Fragment->getParent(), MRE);
+***/
+}
+
+MCObjectWriter *llvm::createPPCMachObjectWriter(raw_ostream &OS,
+                                                bool Is64Bit,
+                                                uint32_t CPUType,
+                                                uint32_t CPUSubtype) {
+  return createMachObjectWriter(new PPCMachObjectWriter(Is64Bit,
+                                                        CPUType,
+                                                        CPUSubtype),
+                                OS, /*IsLittleEndian=*/false);
+}
Index: lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h
===================================================================
--- lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h	(revision 174335)
+++ lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h	(working copy)
@@ -45,6 +45,11 @@
 MCObjectWriter *createPPCELFObjectWriter(raw_ostream &OS,
                                          bool Is64Bit,
                                          uint8_t OSABI);
+/// createPPCELFObjectWriter - Construct a PPC Mach-O object writer.
+MCObjectWriter *createPPCMachObjectWriter(raw_ostream &OS,
+                                          bool Is64Bit,
+                                          uint32_t CPUType,
+                                          uint32_t CPUSubtype);
 } // End llvm namespace
 
 // Defines symbolic names for PowerPC registers.  This defines a mapping from
Index: lib/Target/CMakeLists.txt
===================================================================
--- lib/Target/CMakeLists.txt	(revision 174335)
+++ lib/Target/CMakeLists.txt	(working copy)
@@ -14,3 +14,7 @@
   message(STATUS "Targeting ${t}")
   add_subdirectory(${t})
 endforeach()
+
+# needed for symbol: llvm::MachineInstr::hasPropertyInBundle(unsigned int, llvm::MachineInstr::QueryType) const
+# but creates cyclic dependency
+# target_link_libraries(LLVMTarget LLVMCodeGen)
Index: autoconf/configure.ac
===================================================================
--- autoconf/configure.ac	(revision 174335)
+++ autoconf/configure.ac	(working copy)
@@ -1673,11 +1673,11 @@
 ],
 [
   AC_MSG_RESULT([yes])
-  AC_DEFINE([LLVM_HAS_ATOMICS], [1], [Has gcc/MSVC atomic intrinsics])
+  AC_DEFINE([LLVM_HAS_ATOMICS], [1], [Has gcc/MSVC/Apple atomic intrinsics])
 ],
 [
   AC_MSG_RESULT([no])
-  AC_DEFINE([LLVM_HAS_ATOMICS], [0], [Has gcc/MSVC atomic intrinsics])
+  AC_DEFINE([LLVM_HAS_ATOMICS], [0], [Has gcc/MSVC/Apple atomic intrinsics])
   AC_MSG_WARN([LLVM will be built thread-unsafe because atomic builtins are missing])
 ])
 AC_LANG_POP([C++])
Index: include/llvm/CodeGen/MachineInstr.h
===================================================================
--- include/llvm/CodeGen/MachineInstr.h	(revision 174335)
+++ include/llvm/CodeGen/MachineInstr.h	(working copy)
@@ -65,6 +65,7 @@
                                         // function frame setup code.
     BundledPred  = 1 << 1,              // Instruction has bundled predecessors.
     BundledSucc  = 1 << 2               // Instruction has bundled successors.
+    , InvalidMIFlag = 1 << 3		// Sanity checking
   };
 private:
   const MCInstrDesc *MCID;              // Instruction descriptor.
@@ -147,20 +148,25 @@
 
   /// getFlags - Return the MI flags bitvector.
   uint8_t getFlags() const {
+    assert(Flags < InvalidMIFlag);
     return Flags;
   }
 
   /// getFlag - Return whether an MI flag is set.
   bool getFlag(MIFlag Flag) const {
+    assert(Flags < InvalidMIFlag);
     return Flags & Flag;
   }
 
   /// setFlag - Set a MI flag.
   void setFlag(MIFlag Flag) {
+    assert(Flag < InvalidMIFlag);
     Flags |= (uint8_t)Flag;
   }
 
   void setFlags(unsigned flags) {
+    assert(flags < InvalidMIFlag);
+    // Mask below should be "static const"
     // Filter out the automatically maintained flags.
     unsigned Mask = BundledPred | BundledSucc;
     Flags = (Flags & Mask) | (flags & ~Mask);
@@ -168,6 +174,7 @@
 
   /// clearFlag - Clear a MI flag.
   void clearFlag(MIFlag Flag) {
+    assert(Flags < InvalidMIFlag);
     Flags &= ~((uint8_t)Flag);
   }
 
Index: include/llvm/CodeGen/ScheduleDFS.h
===================================================================
--- include/llvm/CodeGen/ScheduleDFS.h	(revision 174335)
+++ include/llvm/CodeGen/ScheduleDFS.h	(working copy)
@@ -68,8 +68,14 @@
 class SchedDFSResult {
   friend class SchedDFSImpl;
 
+#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
+public:
+#endif
   static const unsigned InvalidSubtreeID = ~0u;
 
+#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
+private:
+#endif
   /// \brief Per-SUnit data computed during DFS for various metrics.
   ///
   /// A node's SubtreeID is set to itself when it is visited to indicate that it
Index: include/llvm/Bitcode/BitstreamReader.h
===================================================================
--- include/llvm/Bitcode/BitstreamReader.h	(revision 174335)
+++ include/llvm/Bitcode/BitstreamReader.h	(working copy)
@@ -136,7 +136,9 @@
 ///   Record   - This is a record with a specific AbbrevID.
 ///
 struct BitstreamEntry {
-  enum {
+// anonymous enum named as workaround to g++-4.0.1 bug (fixed in 4.0.2):
+// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20589
+  enum KindEnum {
     Error,
     EndBlock,
     SubBlock,
Index: include/llvm/Object/MachOFormat.h
===================================================================
--- include/llvm/Object/MachOFormat.h	(revision 174335)
+++ include/llvm/Object/MachOFormat.h	(working copy)
@@ -407,6 +407,53 @@
 
   };
 
+/**
+ * PPC relocation types from <mach-o/ppc/reloc.h>
+ * (renamed, following conventions in this header)
+ *
+ * Relocation types used in the ppc implementation.  Relocation entries for
+ * things other than instructions use the same generic relocation as discribed
+ * above and their r_type is RELOC_VANILLA.  The rest of the relocation types
+ * are for instructions.  Since they are for instructions the r_address field
+ * indicates the 32 bit instruction that the relocation is to be preformed on.
+ * The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types
+ * except for PPC_RELOC_BR14.
+ *
+ * For PPC_RELOC_BR14 if the r_length is the unused value 3, then the branch was
+ * statically predicted setting or clearing the Y-bit based on the sign of the
+ * displacement or the opcode.  If this is the case the static linker must flip
+ * the value of the Y-bit if the sign of the displacement changes for non-branch
+ * always conditions.
+ */
+  enum RelocationInfoTypePPC {
+    RIT_PPC_VANILLA,  /* generic relocation as discribed above */
+    RIT_PPC_PAIR,     /* the second relocation entry of a pair */
+    RIT_PPC_BR14,     /* 14 bit branch displacement (to a word address) */
+    RIT_PPC_BR24,     /* 24 bit branch displacement (to a word address) */
+    RIT_PPC_HI16,     /* a PAIR follows with the low half */
+    RIT_PPC_LO16,     /* a PAIR follows with the high half */
+    RIT_PPC_HA16,     /* Same as the RELOC_HI16 except the low 16 bits and the
+                         * high 16 bits are added together with the low 16 bits
+                         * sign extened first.  This means if bit 15 of the low
+                         * 16 bits is set the high 16 bits stored in the
+                         * instruction will be adjusted.
+                         */
+    RIT_PPC_LO14,     /* Same as the LO16 except that the low 2 bits are not
+                         * stored in the instruction and are always zero.  This
+                         * is used in double word load/store instructions.
+                         */
+    RIT_PPC_SECTDIFF, /* a PAIR follows with subtract symbol value */
+    RIT_PPC_PB_LA_PTR,/* prebound lazy pointer */
+    RIT_PPC_HI16_SECTDIFF, /* section difference forms of above.  a PAIR */
+    RIT_PPC_LO16_SECTDIFF, /* follows these with subtract symbol value */
+    RIT_PPC_HA16_SECTDIFF,
+    RIT_PPC_JBSR,
+    RIT_PPC_LO14_SECTDIFF,
+    RIT_PPC_LOCAL_SECTDIFF,  /* like PPC_SECTDIFF, but the symbol
+                                 referenced was local.  */
+    RIT_PPC_TLV
+  };
+
 } // end namespace macho
 
 } // end namespace object
Index: include/llvm/ADT/DenseMap.h
===================================================================
--- include/llvm/ADT/DenseMap.h	(revision 174335)
+++ include/llvm/ADT/DenseMap.h	(working copy)
@@ -714,7 +714,7 @@
     init(NumInitBuckets);
   }
 
-  SmallDenseMap(const SmallDenseMap &other) {
+  SmallDenseMap(const SmallDenseMap &other) : BaseT() {
     init(0);
     copyFrom(other);
   }
Index: include/llvm/ADT/APInt.h
===================================================================
--- include/llvm/ADT/APInt.h	(revision 174335)
+++ include/llvm/ADT/APInt.h	(working copy)
@@ -91,14 +91,24 @@
     APINT_WORD_SIZE = static_cast<unsigned int>(sizeof(uint64_t))
   };
 
+public:
+  /// @brief Sanity check for debugging BidWidth, should be disabled
+  void sane_BitWidth(void) const {
+//    assert(BitWidth <= 99999);	// disable when not debugging
+  }
+
+private:
   /// This constructor is used only internally for speed of construction of
   /// temporaries. It is unsafe for general use so it is not public.
   /// @brief Fast internal constructor
-  APInt(uint64_t* val, unsigned bits) : BitWidth(bits), pVal(val) { }
+  APInt(uint64_t* val, unsigned bits) : BitWidth(bits), pVal(val) {
+    sane_BitWidth();
+  }
 
   /// @returns true if the number of bits <= 64, false otherwise.
   /// @brief Determine if this APInt just has one word to store value.
   bool isSingleWord() const {
+    sane_BitWidth();
     return BitWidth <= APINT_BITS_PER_WORD;
   }
 
@@ -234,6 +244,7 @@
     else
       initSlowCase(numBits, val, isSigned);
     clearUnusedBits();
+    sane_BitWidth();
   }
 
   /// Note that bigVal.size() can be smaller or larger than the corresponding
@@ -272,6 +283,7 @@
       VAL = that.VAL;
     else
       initSlowCase(that);
+    sane_BitWidth();
   }
 
 #if LLVM_HAS_RVALUE_REFERENCES
@@ -283,6 +295,7 @@
 
   /// @brief Destructor.
   ~APInt() {
+    sane_BitWidth();
     if (!isSingleWord())
       delete [] pVal;
   }
@@ -595,9 +608,10 @@
     if (isSingleWord() && RHS.isSingleWord()) {
       VAL = RHS.VAL;
       BitWidth = RHS.BitWidth;
+      sane_BitWidth();
       return clearUnusedBits();
     }
-
+    sane_BitWidth();
     return AssignSlowCase(RHS);
   }
 
Index: include/llvm/Support/stacktrace.h
===================================================================
--- include/llvm/Support/stacktrace.h	(revision 0)
+++ include/llvm/Support/stacktrace.h	(revision 0)
@@ -0,0 +1,249 @@
+/**
+	\file "util/stacktrace.h"
+	Utility macros and header for convenient stack-trace debugging.
+	$Id: stacktrace.h,v 1.1 2010/03/14 22:25:18 fang Exp $
+ */
+
+#ifndef	__UTIL_STACKTRACE_H__
+#define	__UTIL_STACKTRACE_H__
+
+// macros for enabling/disabling stacktrace code
+/**
+	Strongly recommend using these macros to be able to 
+	turn everything off at compile time.  
+	Predefine this to 0 at compile time to turn-off.  
+ */
+#ifndef	ENABLE_STACKTRACE
+#define	ENABLE_STACKTRACE	0	// on (1) or off (0) by default
+#endif
+
+#include <cassert>
+#include <iosfwd>		// needed for std::ostream forward declaration
+
+//=============================================================================
+// This is the macro interface intended for the programmer.  
+#if ENABLE_STACKTRACE
+#include "llvm/Support/cppcat.h"		// for the UNIQUIFY macros
+#include "llvm/Support/Compiler.h"	// for LLVM_ATTRIBUTE_UNUSED
+
+#define	__ATTRIBUTE_UNUSED__		LLVM_ATTRIBUTE_UNUSED
+
+/**
+	The macro that keeps track of scope and call stacks.  
+	\param str the string to be printed.  
+ */
+#define	STACKTRACE(str)							\
+	const util::stacktrace UNIQUIFY(__stacktrace_) (str)
+/**
+	No user-supplied string required, uses __PRETTY_FUNCTION__
+	built-in internal string.  Is this gcc-only?
+	There's always __func__ for brevity.
+ */
+#define	STACKTRACE_BRIEF						\
+	const util::stacktrace UNIQUIFY(__stacktrace_) (__func__)
+#define	STACKTRACE_VERBOSE						\
+	const util::stacktrace UNIQUIFY(__stacktrace__) (__PRETTY_FUNCTION__)
+/**
+	This enables echoing each time trace stack is updated, i.e., 
+	upon entering and leaving function call stack 
+	or lexical scopes.  
+ */
+#define STACKTRACE_ECHO_ON						\
+	const util::stacktrace::echo UNIQUIFY(__echo_stacktrace__) (1)
+#define STACKTRACE_ECHO_OFF						\
+	const util::stacktrace::echo UNIQUIFY(__echo_stacktrace__) (0)
+#define	STACKTRACE_STREAM						\
+		util::stacktrace::stream()
+/**
+	Indents and returns the current stream used by stacktrace.  
+ */
+#define STACKTRACE_INDENT						\
+		STACKTRACE_STREAM << util::stacktrace_auto_indent
+/**
+	ostream << style printing.  
+	This interface is preferable when compiler isn't smart enough
+	to optimize away no-ops with the null_stacktrace_stream.  
+	\param x may be a set of <<-cascaded arguments.  
+ */
+#define	STACKTRACE_INDENT_PRINT(x)	STACKTRACE_INDENT << x
+#define REDIRECT_STACKTRACE(os)						\
+	const util::stacktrace::redirect UNIQUIFY(__redir_stacktrace__) (os)
+#define	ASSERT_STACKTRACE(expr)						\
+	if (!(expr)) { util::stacktrace::full_dump(); assert(expr); }
+
+#else	// ENABLE_STACKTRACE --------------------------------------------------
+
+#define	STACKTRACE(str)
+#define	STACKTRACE_BRIEF
+#define	STACKTRACE_VERBOSE
+#define STACKTRACE_ECHO_ON
+#define STACKTRACE_ECHO_OFF
+#define	STACKTRACE_STREAM		NULL_STACKTRACE_STREAM
+#define STACKTRACE_INDENT		NULL_STACKTRACE_STREAM
+#define	STACKTRACE_INDENT_PRINT(x)
+#define REDIRECT_STACKTRACE(os)
+#define	ASSERT_STACKTRACE(expr)		assert(expr)
+#endif	// ENABLE_STACKTRACE --------------------------------------------------
+
+//=============================================================================
+// additional macros for general purpose use
+// we provide these macro layers for ease controlling
+// certain subsets of debugging
+
+#ifndef	STACKTRACE_DESTRUCTORS
+#define	STACKTRACE_DESTRUCTORS		(0 && ENABLE_STACKTRACE)
+#endif
+#ifndef	STACKTRACE_CONSTRUCTORS
+#define	STACKTRACE_CONSTRUCTORS		(0 && ENABLE_STACKTRACE)
+#endif
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	STACKTRACE_DTOR is intended for use with destructors
+ */
+#ifndef	STACKTRACE_DTOR
+#if STACKTRACE_DESTRUCTORS
+	#define	STACKTRACE_DTOR(x)	STACKTRACE(x)
+	#define	STACKTRACE_DTOR_BRIEF	STACKTRACE_BRIEF
+	#define	STACKTRACE_DTOR_VERBOSE	STACKTRACE_VERBOSE
+	#define	STACKTRACE_DTOR_PRINT(x)	STACKTRACE_INDENT_PRINT(x)
+#else
+	#define	STACKTRACE_DTOR(x)
+	#define	STACKTRACE_DTOR_BRIEF
+	#define	STACKTRACE_DTOR_VERBOSE
+	#define	STACKTRACE_DTOR_PRINT(x)
+#endif	// STACKTRACE_DESTRUCTORS
+#endif	// STACKTRACE_DTOR
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	STACKTRACE_CTOR is intended for use with constructors
+ */
+#ifndef	STACKTRACE_CTOR
+#if STACKTRACE_CONSTRUCTORS
+	#define	STACKTRACE_CTOR(x)	STACKTRACE(x)
+	#define	STACKTRACE_CTOR_BRIEF	STACKTRACE_BRIEF
+	#define	STACKTRACE_CTOR_VERBOSE	STACKTRACE_VERBOSE
+	#define	STACKTRACE_CTOR_PRINT(x)	STACKTRACE_INDENT_PRINT(x)
+#else
+	#define	STACKTRACE_CTOR(x)
+	#define	STACKTRACE_CTOR_BRIEF
+	#define	STACKTRACE_CTOR_VERBOSE
+	#define	STACKTRACE_CTOR_PRINT(x)
+#endif	// STACKTRACE_CONSTRUCTORS
+#endif	// STACKTRACE_CTOR
+
+//=============================================================================
+
+#if ENABLE_STACKTRACE
+
+#include <iosfwd>
+#include <string>
+#include <list>
+#include <stack>	// needed
+
+namespace util {
+using std::list;
+using std::string;
+using std::stack;
+
+//=============================================================================
+/**
+	Nothing is inlined because when you're debugging you shouldn't be
+	varing about performance.  
+	Can use for function scopes or any conditional statement scopes.  
+	Two mechanisms for controlling behavior, 
+	compile-time macros and public static variables.  
+	TODO: make one entry per thread, mapped by thread ID.
+ */
+class stacktrace {
+public:
+	/// the type of stack used to hold feedback text
+	typedef list<string>			stack_text_type;
+	/// the type of stack used to track on/off mode
+	typedef stack<int>			stack_echo_type;
+	/// the type of stack used to track stream redirections
+	typedef stack<std::ostream*>		stack_streams_type;
+
+public:
+	class manager;
+	struct echo;
+	struct redirect;
+	struct indent { };
+
+public:
+//	stacktrace(const char*);
+	stacktrace(const string&);
+	~stacktrace();
+public:
+	static
+	std::ostream&
+	stream(void);
+
+	/**
+		Explicit request by user to dump the stack trace.
+		Useful in assertion failures.  
+	 */
+	static
+	void
+	full_dump(void);
+
+private:
+	// and undefined
+	// non-copy-able
+	explicit
+	stacktrace(const stacktrace&);
+
+	// non-assignable
+	stacktrace&
+	operator = (const stacktrace&);
+
+	// non-heap allocatable
+	static void* operator new (size_t);
+	static void operator delete (void*);
+	static void* operator new (size_t, void*);
+	static void operator delete (void*, void*);
+	static void* operator new [] (size_t);
+	static void operator delete [] (void*);
+	static void* operator new [] (size_t, void*);
+	static void operator delete [] (void*, void*);
+
+} __ATTRIBUTE_UNUSED__ ;	// end class stacktrace
+
+//-----------------------------------------------------------------------------
+extern const stacktrace::indent	stacktrace_auto_indent;
+
+std::ostream&
+operator << (std::ostream&, const stacktrace::indent&);
+
+//-----------------------------------------------------------------------------
+/**
+	Whether or not to print upon entering and exiting.
+	Pass in 0 to disable.  
+	Enabling/disable lasts for the duration of the scope.  
+ */
+struct stacktrace::echo {
+	echo(const int i = 1);
+	~echo();
+} __ATTRIBUTE_UNUSED__ ;	// end struct echo
+
+//-----------------------------------------------------------------------------
+/**
+	Redirect all stack dumps to this ostream until changed otherwise.
+	Lasts for the duration of the scope where this is called.  
+ */
+struct stacktrace::redirect {
+	redirect(std::ostream&);
+	~redirect();
+} __ATTRIBUTE_UNUSED__ ;	// end struct redirect
+
+//=============================================================================
+
+}	// end namespace util
+
+#else	// ENABLE_STACKTRACE
+	// don't even bother processing class declaration!
+#endif	// ENABLE_STACKTRACE
+
+#endif	// __UTIL_STACKTRACE_H__
+
Index: include/llvm/Support/cppcat.h
===================================================================
--- include/llvm/Support/cppcat.h	(revision 0)
+++ include/llvm/Support/cppcat.h	(revision 0)
@@ -0,0 +1,48 @@
+/**
+	\file "util/cppcat.h"
+	Tricks for concatenating strings with the C-preprocessor.  
+	I learned this trick from:
+		http://www.slack.net/~ant/cpp/unqiue_name.html
+	$Id: cppcat.h,v 1.1 2010/03/14 22:25:16 fang Exp $
+ */
+
+#ifndef	__UTIL_CPPCAT_H__
+#define	__UTIL_CPPCAT_H__
+
+/**
+	Description also copied from the same web-site.
+
+	Sometimes one needs to supply an identifier for something that will 
+	never be referenced again. The most common occurrence is a local 
+	object of some type whose construction and destruction side-effects 
+	are wanted at the beginning and end of the scope it exists in, 
+	respectively. Having to come up with a name is both tedious and 
+	unclear, since the name will serve no purpose in the code. 
+	If it were possible, providing no name would make the intent clearer.
+
+	In the CONCAT macro, the seemingly-redundant helper macros 
+	(CONCAT_2_ and CONCAT_3_) are needed due to particulars of the 
+	preprocessor.
+
+	Generally, this construct will only be needed in a source file 
+	(and not a header). This makes it unlikely for it to clash with 
+	anything else. If it's needed in a header file, care must be 
+	taken that the name can't clash with any other identifier, 
+	because a clash may not show up until the header is integrated 
+	with another header file that happens to have an identical UNIQUE_NAME.
+ */
+
+#define	CONCAT_3_(x, y)		x##y
+#define	CONCAT_2_(x, y)		CONCAT_3_(x,y)
+#define	CONCAT(x, y)		CONCAT_2_(x,y)
+#define	UNIQUIFY(str)		CONCAT(str,__LINE__)
+
+/**
+	To try to protect macros with commas inside, without
+	requiring extra parentheses.  
+ */
+#define	CPPWRAP(x)		x
+
+
+#endif	// __UTIL_CPPCAT_H__
+
Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h	(revision 174335)
+++ include/llvm/Support/Compiler.h	(working copy)
@@ -174,7 +174,10 @@
 #define LLVM_READNONE
 #endif
 
-#ifdef __GNUC__  // aka 'PURE' but following LLVM Conventions.
+// this attribute may be buggy for older gcc-4.0.1 (apple)
+// removing this fixes bug #14244
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+// aka 'PURE' but following LLVM Conventions.
 #define LLVM_READONLY __attribute__((__pure__))
 #else
 #define LLVM_READONLY
Index: include/llvm/Support/Endian.h
===================================================================
--- include/llvm/Support/Endian.h	(revision 174335)
+++ include/llvm/Support/Endian.h	(working copy)
@@ -27,6 +27,31 @@
 enum {aligned = 0, unaligned = 1};
 
 namespace detail {
+#if 0
+template<typename value_type, alignment align>
+struct alignment_access_helper;
+
+template<typename value_type>
+struct alignment_access_helper<value_type, aligned>
+{
+  value_type val;
+};
+
+// Provides unaligned loads and stores.
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+#pragma pack(push)
+#pragma pack(1)
+#endif
+template<typename value_type>
+struct alignment_access_helper<value_type, unaligned>
+{
+  value_type val;
+};
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+#pragma pack(pop)
+#endif
+#endif
+
   /// \brief ::value is either alignment, or alignof(T) if alignment is 0.
   template<class T, int alignment>
   struct PickAlignment {
