Update clang to r339409.

Change-Id: I800772d2d838223be1f6b40d490c4591b937fca2
diff --git a/linux-x64/clang/include/lld/Common/Driver.h b/linux-x64/clang/include/lld/Common/Driver.h
index 15ec3cd..f6d9293 100644
--- a/linux-x64/clang/include/lld/Common/Driver.h
+++ b/linux-x64/clang/include/lld/Common/Driver.h
@@ -30,7 +30,7 @@
 }
 
 namespace mach_o {
-bool link(llvm::ArrayRef<const char *> Args,
+bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly,
           llvm::raw_ostream &Diag = llvm::errs());
 }
 
diff --git a/linux-x64/clang/include/lld/Common/ErrorHandler.h b/linux-x64/clang/include/lld/Common/ErrorHandler.h
index 8ae6f46..f17f7cc 100644
--- a/linux-x64/clang/include/lld/Common/ErrorHandler.h
+++ b/linux-x64/clang/include/lld/Common/ErrorHandler.h
@@ -7,21 +7,62 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// In LLD, we have three levels of errors: fatal, error or warn.
+// We designed lld's error handlers with the following goals in mind:
 //
-// Fatal makes the program exit immediately with an error message.
-// You shouldn't use it except for reporting a corrupted input file.
+//  - Errors can occur at any place where we handle user input, but we don't
+//    want them to affect the normal execution path too much. Ideally,
+//    handling errors should be as simple as reporting them and exit (but
+//    without actually doing exit).
 //
-// Error prints out an error message and increment a global variable
-// ErrorCount to record the fact that we met an error condition. It does
-// not exit, so it is safe for a lld-as-a-library use case. It is generally
-// useful because it can report more than one error in a single run.
+//    In particular, the design to wrap all functions that could fail with
+//    ErrorOr<T> is rejected because otherwise we would have to wrap a large
+//    number of functions in lld with ErrorOr. With that approach, if some
+//    function F can fail, not only F but all functions that transitively call
+//    F have to be wrapped with ErrorOr. That seemed too much.
 //
-// Warn doesn't do anything but printing out a given message.
+//  - Finding only one error at a time is not sufficient. We want to find as
+//    many errors as possible with one execution of the linker. That means the
+//    linker needs to keep running after a first error and give up at some
+//    checkpoint (beyond which it would find cascading, false errors caused by
+//    the previous errors).
 //
-// It is not recommended to use llvm::outs() or llvm::errs() directly
-// in LLD because they are not thread-safe. The functions declared in
-// this file are mutually excluded, so you want to use them instead.
+//  - We want a simple interface to report errors. Unlike Clang, the data we
+//    handle is compiled binary, so we don't need an error reporting mechanism
+//    that's as sophisticated as the one that Clang has.
+//
+// The current lld's error handling mechanism is simple:
+//
+//  - When you find an error, report it using error() and continue as far as
+//    you can. An internal error counter is incremented by one every time you
+//    call error().
+//
+//    A common idiom to handle an error is calling error() and then returning
+//    a reasonable default value. For example, if your function handles a
+//    user-supplied alignment value, and if you find an invalid alignment
+//    (e.g. 17 which is not 2^n), you may report it using error() and continue
+//    as if it were alignment 1 (which is the simplest reasonable value).
+//
+//    Note that you should not continue with an invalid value; that breaks the
+//    internal consistency. You need to maintain all variables have some sane
+//    value even after an error occurred. So, when you have to continue with
+//    some value, always use a dummy value.
+//
+//  - Find a reasonable checkpoint at where you want to stop the linker, and
+//    add code to return from the function if errorCount() > 0. In most cases,
+//    a checkpoint already exists, so you don't need to do anything for this.
+//
+// This interface satisfies all the goals that we mentioned above.
+//
+// You should never call fatal() except for reporting a corrupted input file.
+// fatal() immediately terminates the linker, so the function is not desirable
+// if you are using lld as a subroutine in other program, and with that you
+// can find only one error at a time.
+//
+// warn() doesn't do anything but printing out a given message.
+//
+// It is not recommended to use llvm::outs() or llvm::errs() directly in lld
+// because they are not thread-safe. The functions declared in this file are
+// thread-safe.
 //
 //===----------------------------------------------------------------------===//
 
@@ -34,6 +75,10 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
 
+namespace llvm {
+class DiagnosticInfo;
+}
+
 namespace lld {
 
 class ErrorHandler {
@@ -74,6 +119,9 @@
 
 LLVM_ATTRIBUTE_NORETURN void exitLld(int Val);
 
+void diagnosticHandler(const llvm::DiagnosticInfo &DI);
+void checkError(Error E);
+
 // check functions are convenient functions to strip errors
 // from error-or-value objects.
 template <class T> T check(ErrorOr<T> E) {
diff --git a/linux-x64/clang/include/lld/Common/Strings.h b/linux-x64/clang/include/lld/Common/Strings.h
index 3be5eb9..e17b257 100644
--- a/linux-x64/clang/include/lld/Common/Strings.h
+++ b/linux-x64/clang/include/lld/Common/Strings.h
@@ -26,35 +26,8 @@
 std::vector<uint8_t> parseHex(llvm::StringRef S);
 bool isValidCIdentifier(llvm::StringRef S);
 
-// This is a lazy version of StringRef. String size is computed lazily
-// when it is needed. It is more efficient than StringRef to instantiate
-// if you have a string whose size is unknown.
-//
-// COFF and ELF string tables contain a lot of null-terminated strings.
-// Most of them are not necessary for the linker because they are names
-// of local symbols and the linker doesn't use local symbol names for
-// name resolution. So, we use this class to represents strings read
-// from string tables.
-class StringRefZ {
-public:
-  StringRefZ() : Start(nullptr), Size(0) {}
-  StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
-
-  /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
-
-  /*implicit*/ StringRefZ(llvm::StringRef S)
-      : Start(S.data()), Size(S.size()) {}
-
-  operator llvm::StringRef() const {
-    if (Size == (size_t)-1)
-      Size = strlen(Start);
-    return {Start, Size};
-  }
-
-private:
-  const char *Start;
-  mutable size_t Size;
-};
+// Write the contents of the a buffer to a file
+void saveBuffer(llvm::StringRef Buffer, const llvm::Twine &Path);
 
 // This class represents multiple glob patterns.
 class StringMatcher {
@@ -71,6 +44,6 @@
 inline llvm::ArrayRef<uint8_t> toArrayRef(llvm::StringRef S) {
   return {reinterpret_cast<const uint8_t *>(S.data()), S.size()};
 }
-}
+} // namespace lld
 
 #endif
diff --git a/linux-x64/clang/include/lld/Common/Version.h b/linux-x64/clang/include/lld/Common/Version.h
index 93de77d..23a10ed 100644
--- a/linux-x64/clang/include/lld/Common/Version.h
+++ b/linux-x64/clang/include/lld/Common/Version.h
@@ -18,7 +18,7 @@
 #include "llvm/ADT/StringRef.h"
 
 namespace lld {
-/// \brief Retrieves a string representing the complete lld version.
+/// Retrieves a string representing the complete lld version.
 std::string getLLDVersion();
 }