summaryrefslogtreecommitdiff
path: root/debian/patches/dyson.patch
blob: 4a44596d2893391eff5d9bf3597aacb186c65734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
Index: llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- llvm-toolchain-8.git.orig/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+++ llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
@@ -107,6 +107,10 @@ extern struct ps_strings *__ps_strings;
 #define environ _environ
 #endif
 
+#ifndef O_DIRECTORY
+#define O_DIRECTORY 0
+#endif
+
 extern char **environ;
 
 #if SANITIZER_LINUX
Index: llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- llvm-toolchain-8.git.orig/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -35,6 +35,10 @@
 #include <sys/resource.h>
 #include <syslog.h>
 
+#if SANITIZER_SOLARIS
+#include <stdlib.h> // for getexecname()
+#endif
+
 #if SANITIZER_FREEBSD
 # if !SANITIZER_KFREEBSD
 # include <pthread_np.h>
Index: llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.cc
===================================================================
--- llvm-toolchain-8.git.orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.cc
+++ llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.cc
@@ -202,7 +202,7 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi
 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr);
 CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum);
 
-CHECK_TYPE_SIZE(glob_t);
+//CHECK_TYPE_SIZE(glob_t);
 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
 CHECK_SIZE_AND_OFFSET(glob_t, gl_offs);
Index: llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.h
===================================================================
--- llvm-toolchain-8.git.orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.h
+++ llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_solaris.h
@@ -193,6 +193,8 @@ struct __sanitizer_tm {
   int tm_wday;
   int tm_yday;
   int tm_isdst;
+  long tm_gmtoff;
+  const char* tm_zone;
 };
 
 struct __sanitizer_msghdr {
Index: llvm-toolchain-8.git/polly/lib/Transform/ScheduleOptimizer.cpp
===================================================================
--- llvm-toolchain-8.git.orig/polly/lib/Transform/ScheduleOptimizer.cpp
+++ llvm-toolchain-8.git/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -911,9 +911,9 @@ getMicroKernelParams(const TargetTransfo
   auto Nvec = RegisterBitwidth / ElementSize;
   if (Nvec == 0)
     Nvec = 2;
-  int Nr =
-      ceil(sqrt(Nvec * LatencyVectorFma * ThroughputVectorFma) / Nvec) * Nvec;
-  int Mr = ceil(Nvec * LatencyVectorFma * ThroughputVectorFma / Nr);
+  double _tmp = Nvec * LatencyVectorFma * ThroughputVectorFma;
+  int Nr = ceil(sqrt(_tmp) / Nvec) * Nvec;
+  int Mr = ceil(_tmp / Nr);
   return {Mr, Nr};
 }
 
Index: llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cc
===================================================================
--- llvm-toolchain-8.git.orig/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cc
+++ llvm-toolchain-8.git/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cc
@@ -124,6 +124,10 @@ uptr internal_filesize(fd_t fd) {
   return (uptr)st.st_size;
 }
 
+DECLARE__REAL_AND_INTERNAL(uptr, dup, int oldfd) {
+  return _REAL(dup)(oldfd);
+}
+
 DECLARE__REAL_AND_INTERNAL(uptr, dup2, int oldfd, int newfd) {
   return _REAL(dup2)(oldfd, newfd);
 }
Index: llvm-toolchain-8.git/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm-toolchain-8.git.orig/cmake/modules/AddLLVM.cmake
+++ llvm-toolchain-8.git/cmake/modules/AddLLVM.cmake
@@ -200,7 +200,7 @@ function(add_link_opts target_name)
 
     # Pass -O3 to the linker. This enabled different optimizations on different
     # linkers.
-    if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32))
+    if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|AIX" OR WIN32))
       set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                    LINK_FLAGS " -Wl,-O3")
     endif()
@@ -218,9 +218,6 @@ function(add_link_opts target_name)
         # ld64's implementation of -dead_strip breaks tools that use plugins.
         set_property(TARGET ${target_name} APPEND_STRING PROPERTY
                      LINK_FLAGS " -Wl,-dead_strip")
-      elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
-        set_property(TARGET ${target_name} APPEND_STRING PROPERTY
-                     LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
       elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
         # Object files are compiled with -ffunction-data-sections.
         # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
Index: llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Solaris.cpp
===================================================================
--- llvm-toolchain-8.git.orig/clang/lib/Driver/ToolChains/Solaris.cpp
+++ llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -15,8 +15,8 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
-#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -24,24 +24,22 @@ using namespace clang::driver::toolchain
 using namespace clang;
 using namespace llvm::opt;
 
-void solaris::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
-                                      const InputInfo &Output,
-                                      const InputInfoList &Inputs,
-                                      const ArgList &Args,
-                                      const char *LinkingOutput) const {
-  claimNoWarnArgs(Args);
-  ArgStringList CmdArgs;
-
-  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
-
-  CmdArgs.push_back("-o");
-  CmdArgs.push_back(Output.getFilename());
-
-  for (const auto &II : Inputs)
-    CmdArgs.push_back(II.getFilename());
+static std::string getMultiarchTriple(const Driver &D,
+                                      const llvm::Triple &TargetTriple) {
+  switch (TargetTriple.getArch()) {
+  default:
+    break;
 
-  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
-  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
+  case llvm::Triple::x86:
+    if (D.getVFS().exists(D.SysRoot + "/lib/i386-illumos"))
+      return "i386-illumos";
+    break;
+  case llvm::Triple::x86_64:
+    if (D.getVFS().exists(D.SysRoot + "/lib/x86_64-illumos"))
+      return "x86_64-illumos";
+    break;
+  }
+  return TargetTriple.str();
 }
 
 void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
@@ -49,34 +47,49 @@ void solaris::Linker::ConstructJob(Compi
                                    const InputInfoList &Inputs,
                                    const ArgList &Args,
                                    const char *LinkingOutput) const {
-  ArgStringList CmdArgs;
+  const Driver &D = getToolChain().getDriver();
 
-  // Demangle C++ names in errors
-  CmdArgs.push_back("-C");
+  ArgStringList CmdArgs;
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared)) {
-    CmdArgs.push_back("-e");
-    CmdArgs.push_back("_start");
-  }
+  CmdArgs.push_back("--hash-style=both");
+#ifdef ENABLE_LINKER_BUILD_ID
+  CmdArgs.push_back("--build-id");
+#endif
 
   if (Args.hasArg(options::OPT_static)) {
-    CmdArgs.push_back("-Bstatic");
-    CmdArgs.push_back("-dn");
-  } else {
-    CmdArgs.push_back("-Bdynamic");
-    if (Args.hasArg(options::OPT_shared)) {
-      CmdArgs.push_back("-shared");
-    } else {
-      CmdArgs.push_back("--dynamic-linker");
-      CmdArgs.push_back(
-          Args.MakeArgString(getToolChain().GetFilePath("ld.so.1")));
-    }
-
-    // libpthread has been folded into libc since Solaris 10, no need to do
-    // anything for pthreads. Claim argument to avoid warning.
-    Args.ClaimAllArgs(options::OPT_pthread);
-    Args.ClaimAllArgs(options::OPT_pthreads);
-  }
+    CmdArgs.push_back("-static");
+  } else  if (Args.hasArg(options::OPT_shared)) {
+    CmdArgs.push_back("-shared");
+  }
+
+  if (!D.SysRoot.empty())
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+  if (Args.hasArg(options::OPT_rdynamic))
+    CmdArgs.push_back("-export-dynamic");
+
+  if (Args.hasArg(options::OPT_s))
+    CmdArgs.push_back("-s");
+
+  if (!Args.hasArg(options::OPT_static))
+    CmdArgs.push_back("--eh-frame-hdr");
+
+  // libpthread has been folded into libc since Solaris 10, no need to do
+  // anything for pthreads. Claim argument to avoid warning.
+  Args.ClaimAllArgs(options::OPT_pthread);
+  Args.ClaimAllArgs(options::OPT_pthreads);
+
+  CmdArgs.push_back("-m");
+  switch (getToolChain().getTriple().getArch()) {
+    case llvm::Triple::x86:
+      CmdArgs.push_back("elf_i386_sol2");
+      break;
+    case llvm::Triple::x86_64:
+      CmdArgs.push_back("elf_x86_64_sol2");
+      break;
+    default:
+      llvm_unreachable("Unsupported architecture");
+   }
 
   if (Output.isFilename()) {
     CmdArgs.push_back("-o");
@@ -97,13 +110,6 @@ void solaris::Linker::ConstructJob(Compi
         Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
-  // Provide __start___sancov_guards.  Solaris ld doesn't automatically create
-  // __start_SECNAME labels.
-  CmdArgs.push_back("--whole-archive");
-  CmdArgs.push_back(
-      getToolChain().getCompilerRTArgString(Args, "sancov_begin", false));
-  CmdArgs.push_back("--no-whole-archive");
-
   getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
@@ -132,66 +138,24 @@ void solaris::Linker::ConstructJob(Compi
       linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
   }
 
-  // Provide __stop___sancov_guards.  Solaris ld doesn't automatically create
-  // __stop_SECNAME labels.
-  CmdArgs.push_back("--whole-archive");
-  CmdArgs.push_back(
-      getToolChain().getCompilerRTArgString(Args, "sancov_end", false));
-  CmdArgs.push_back("--no-whole-archive");
-
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
     CmdArgs.push_back(
         Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
   }
   CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
 
+  if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
+    CmdArgs.push_back("--no-demangle");
+
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
 }
 
-static StringRef getSolarisLibSuffix(const llvm::Triple &Triple) {
-  switch (Triple.getArch()) {
-  case llvm::Triple::x86:
-  case llvm::Triple::sparc:
-    break;
-  case llvm::Triple::x86_64:
-    return "/amd64";
-  case llvm::Triple::sparcv9:
-    return "/sparcv9";
-  default:
-    llvm_unreachable("Unsupported architecture");
-  }
-  return "";
-}
-
-/// Solaris - Solaris tool chain which can call as(1) and ld(1) directly.
-
 Solaris::Solaris(const Driver &D, const llvm::Triple &Triple,
                  const ArgList &Args)
-    : Generic_ELF(D, Triple, Args) {
-
-  GCCInstallation.init(Triple, Args);
-
-  StringRef LibSuffix = getSolarisLibSuffix(Triple);
-  path_list &Paths = getFilePaths();
-  if (GCCInstallation.isValid()) {
-    // On Solaris gcc uses both an architecture-specific path with triple in it
-    // as well as a more generic lib path (+arch suffix).
-    addPathIfExists(D,
-                    GCCInstallation.getInstallPath() +
-                        GCCInstallation.getMultilib().gccSuffix(),
-                    Paths);
-    addPathIfExists(D, GCCInstallation.getParentLibPath() + LibSuffix, Paths);
-  }
-
-  // If we are currently running Clang inside of the requested system root,
-  // add its parent library path to those searched.
-  if (StringRef(D.Dir).startswith(D.SysRoot))
-    addPathIfExists(D, D.Dir + "/../lib", Paths);
-
-  addPathIfExists(D, D.SysRoot + "/usr/lib" + LibSuffix, Paths);
+    : Linux(D, Triple, Args) {
 }
 
 SanitizerMask Solaris::getSupportedSanitizers() const {
@@ -206,7 +170,7 @@ SanitizerMask Solaris::getSupportedSanit
 }
 
 Tool *Solaris::buildAssembler() const {
-  return new tools::solaris::Assembler(*this);
+  return new tools::gnutools::Assembler(*this);
 }
 
 Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); }
@@ -254,6 +218,32 @@ void Solaris::AddClangSystemIncludeArgs(
     }
   }
 
+  const StringRef X86_64MultiarchIncludeDirs[] = {
+      "/usr/include/x86_64-illumos"
+  };
+  const StringRef X86MultiarchIncludeDirs[] = {
+      "/usr/include/i386-illumos"
+  };
+
+  ArrayRef<StringRef> MultiarchIncludeDirs;
+  switch (getTriple().getArch()) {
+  case llvm::Triple::x86_64:
+    MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
+    break;
+  case llvm::Triple::x86:
+    MultiarchIncludeDirs = X86MultiarchIncludeDirs;
+    break;
+  default:
+    break;
+  }
+
+  for (StringRef Dir : MultiarchIncludeDirs) {
+    if (D.getVFS().exists(D.SysRoot + Dir)) {
+      addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + Dir);
+      break;
+    }
+  }
+
   addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
 }
 
@@ -271,12 +261,14 @@ void Solaris::addLibStdCxxIncludePaths(
   StringRef LibDir = GCCInstallation.getParentLibPath();
   StringRef TripleStr = GCCInstallation.getTriple().str();
   const Multilib &Multilib = GCCInstallation.getMultilib();
+  const std::string GCCMultiarchTriple = getMultiarchTriple( getDriver(), GCCInstallation.getTriple());
+  const std::string TargetMultiarchTriple = getMultiarchTriple(getDriver(), getTriple());
   const GCCVersion &Version = GCCInstallation.getVersion();
 
   // The primary search for libstdc++ supports multiarch variants.
   addLibStdCXXIncludePaths(LibDir.str() + "/../include", "/c++/" + Version.Text,
                            TripleStr,
-                           /*GCCMultiarchTriple*/ "",
-                           /*TargetMultiarchTriple*/ "",
+                           GCCMultiarchTriple,
+                           TargetMultiarchTriple,
                            Multilib.includeSuffix(), DriverArgs, CC1Args);
 }
Index: llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Solaris.h
===================================================================
--- llvm-toolchain-8.git.orig/clang/lib/Driver/ToolChains/Solaris.h
+++ llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Solaris.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SOLARIS_H
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SOLARIS_H
 
-#include "Gnu.h"
+#include "Linux.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
 
@@ -18,21 +18,7 @@ namespace clang {
 namespace driver {
 namespace tools {
 
-/// solaris -- Directly call Solaris assembler and linker
 namespace solaris {
-class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
-public:
-  Assembler(const ToolChain &TC)
-      : Tool("solaris::Assembler", "assembler", TC) {}
-
-  bool hasIntegratedCPP() const override { return false; }
-
-  void ConstructJob(Compilation &C, const JobAction &JA,
-                    const InputInfo &Output, const InputInfoList &Inputs,
-                    const llvm::opt::ArgList &TCArgs,
-                    const char *LinkingOutput) const override;
-};
-
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
 public:
   Linker(const ToolChain &TC) : Tool("solaris::Linker", "linker", TC) {}
@@ -50,7 +36,7 @@ public:
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Solaris : public Linux {
 public:
   Solaris(const Driver &D, const llvm::Triple &Triple,
           const llvm::opt::ArgList &Args);
Index: llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- llvm-toolchain-8.git.orig/clang/lib/Driver/ToolChains/Gnu.cpp
+++ llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1836,36 +1836,7 @@ bool Generic_GCC::GCCInstallationDetecto
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
     const llvm::Triple &TargetTriple, SmallVectorImpl<std::string> &Prefixes,
     StringRef SysRoot) {
-  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
-    // Solaris is a special case.
-    // The GCC installation is under
-    //   /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/
-    // so we need to find those /usr/gcc/*/lib/gcc libdirs and go with
-    // /usr/gcc/<version> as a prefix.
 
-    std::string PrefixDir = SysRoot.str() + "/usr/gcc";
-    std::error_code EC;
-    for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(PrefixDir, EC),
-                                       LE;
-         !EC && LI != LE; LI = LI.increment(EC)) {
-      StringRef VersionText = llvm::sys::path::filename(LI->path());
-      GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
-
-      // Filter out obviously bad entries.
-      if (CandidateVersion.Major == -1 || CandidateVersion.isOlderThan(4, 1, 1))
-        continue;
-
-      std::string CandidatePrefix = PrefixDir + "/" + VersionText.str();
-      std::string CandidateLibPath = CandidatePrefix + "/lib/gcc";
-      if (!D.getVFS().exists(CandidateLibPath))
-        continue;
-
-      Prefixes.push_back(CandidatePrefix);
-    }
-    return;
-  }
-
-  // Non-Solaris is much simpler - most systems just go with "/usr".
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
     // Yet, still look for RHEL devtoolsets.
     Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
Index: llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- llvm-toolchain-8.git.orig/clang/lib/Driver/ToolChains/Linux.cpp
+++ llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Linux.cpp
@@ -82,12 +82,18 @@ static std::string getMultiarchTriple(co
   case llvm::Triple::x86:
     if (IsAndroid)
       return "i686-linux-android";
+    if (TargetTriple.getOS() == llvm::Triple::Solaris &&
+        D.getVFS().exists(SysRoot + "/lib/i386-illumos"))
+      return "i386-illumos";
     if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
       return "i386-linux-gnu";
     break;
   case llvm::Triple::x86_64:
     if (IsAndroid)
       return "x86_64-linux-android";
+    if (TargetTriple.getOS() == llvm::Triple::Solaris &&
+        D.getVFS().exists(SysRoot + "/lib/x86_64-illumos"))
+      return "x86_64-illumos";
     // We don't want this for x32, otherwise it will match x86_64 libs
     if (TargetEnvironment != llvm::Triple::GNUX32 &&
         D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
Index: llvm-toolchain-8.git/utils/FileCheck/FileCheck.cpp
===================================================================
--- llvm-toolchain-8.git.orig/utils/FileCheck/FileCheck.cpp
+++ llvm-toolchain-8.git/utils/FileCheck/FileCheck.cpp
@@ -403,7 +403,7 @@ static void DumpAnnotatedInput(raw_ostre
   unsigned LineCount = InputFileText.count('\n');
   if (InputFileEnd[-1] != '\n')
     ++LineCount;
-  unsigned LineNoWidth = log10(LineCount) + 1;
+  unsigned LineNoWidth = log10((double)LineCount) + 1;
   // +3 below adds spaces (1) to the left of the (right-aligned) line numbers
   // on input lines and (2) to the right of the (left-aligned) labels on
   // annotation lines so that input lines and annotation lines are more
Index: llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- llvm-toolchain-8.git.orig/clang/lib/Driver/ToolChains/Clang.cpp
+++ llvm-toolchain-8.git/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4667,7 +4667,8 @@ void Clang::ConstructJob(Compilation &C,
   if (!Args.hasFlag(
           options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
           !RawTriple.isOSWindows() &&
-              RawTriple.getOS() != llvm::Triple::Solaris &&
+              // https://bugs.llvm.org/show_bug.cgi?id=42182
+              /* RawTriple.getOS() != llvm::Triple::Solaris && */
               TC.getArch() != llvm::Triple::xcore &&
               ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
                RawTriple.hasEnvironment())) ||
Index: llvm-toolchain-8.git/clang/tools/libclang/CMakeLists.txt
===================================================================
--- llvm-toolchain-8.git.orig/clang/tools/libclang/CMakeLists.txt
+++ llvm-toolchain-8.git/clang/tools/libclang/CMakeLists.txt
@@ -57,10 +57,7 @@ if (TARGET clangTidyPlugin)
   endif()
 endif ()
 
-find_library(DL_LIBRARY_PATH dl)
-if (DL_LIBRARY_PATH)
-  list(APPEND LIBS dl)
-endif()
+list(APPEND LIBS m)
 
 option(LIBCLANG_BUILD_STATIC
   "Build libclang as a static library (in addition to a shared one)" OFF)
Index: llvm-toolchain-8.git/libcxx/include/cstdio
===================================================================
--- llvm-toolchain-8.git.orig/libcxx/include/cstdio
+++ llvm-toolchain-8.git/libcxx/include/cstdio
@@ -153,9 +153,6 @@ using ::tmpnam;
 
 #ifndef _LIBCPP_HAS_NO_STDIN
 using ::getchar;
-#if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_MSVCRT)
-using ::gets;
-#endif
 using ::scanf;
 using ::vscanf;
 #endif
Index: llvm-toolchain-8.git/libcxx/include/__locale
===================================================================
--- llvm-toolchain-8.git.orig/libcxx/include/__locale
+++ llvm-toolchain-8.git/libcxx/include/__locale
@@ -26,8 +26,7 @@
 #elif defined(__ANDROID__)
 # include <support/android/locale_bionic.h>
 #elif defined(__sun__)
-# include <xlocale.h>
-# include <support/solaris/xlocale.h>
+#include <support/xlocale/__strtonum_fallback.h>
 #elif defined(_NEWLIB_VERSION)
 # include <support/newlib/xlocale.h>
 #elif (defined(__APPLE__)      || defined(__FreeBSD__) \
Index: llvm-toolchain-8.git/libcxx/include/__config
===================================================================
--- llvm-toolchain-8.git.orig/libcxx/include/__config
+++ llvm-toolchain-8.git/libcxx/include/__config
@@ -971,7 +971,7 @@ template <unsigned> struct __static_asse
 #endif
 
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
-    defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
+    defined(__NetBSD__) || defined(__CloudABI__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
 
Index: llvm-toolchain-8.git/libcxx/src/support/solaris/xlocale.cpp
===================================================================
--- llvm-toolchain-8.git.orig/libcxx/src/support/solaris/xlocale.cpp
+++ llvm-toolchain-8.git/libcxx/src/support/solaris/xlocale.cpp
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifdef __sun__
+#ifdef __fuck_you__
 
 #include "support/solaris/xlocale.h"
 #include <stdarg.h>
Index: llvm-toolchain-8.git/libcxx/src/filesystem/directory_iterator.cpp
===================================================================
--- llvm-toolchain-8.git.orig/libcxx/src/filesystem/directory_iterator.cpp
+++ llvm-toolchain-8.git/libcxx/src/filesystem/directory_iterator.cpp
@@ -25,36 +25,7 @@ namespace detail {
 namespace {
 
 #if !defined(_LIBCPP_WIN32API)
-template <class DirEntT, class = decltype(DirEntT::d_type)>
-static file_type get_file_type(DirEntT* ent, int) {
-  switch (ent->d_type) {
-  case DT_BLK:
-    return file_type::block;
-  case DT_CHR:
-    return file_type::character;
-  case DT_DIR:
-    return file_type::directory;
-  case DT_FIFO:
-    return file_type::fifo;
-  case DT_LNK:
-    return file_type::symlink;
-  case DT_REG:
-    return file_type::regular;
-  case DT_SOCK:
-    return file_type::socket;
-  // Unlike in lstat, hitting "unknown" here simply means that the underlying
-  // filesystem doesn't support d_type. Report is as 'none' so we correctly
-  // set the cache to empty.
-  case DT_UNKNOWN:
-    break;
-  }
-  return file_type::none;
-}
-
-template <class DirEntT>
-static file_type get_file_type(DirEntT* ent, long) {
-  return file_type::none;
-}
+// Use fstatat(), stupid.
 
 static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
                                                   error_code& ec) {
@@ -66,7 +37,7 @@ static pair<string_view, file_type> posi
       ec = capture_errno();
     return {};
   } else {
-    return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
+    return {dir_entry_ptr->d_name, file_type::none};
   }
 }
 #else