summaryrefslogtreecommitdiff
path: root/patches/rustc-src-maple.patch
blob: 31f52163099626f7749aa7dedcafc34abd73e75a (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
--- rustc-1.74.0-src.orig/compiler/rustc_codegen_llvm/src/consts.rs	2023-11-12 23:10:51.000000000 -0500
+++ rustc-1.74.0-src/compiler/rustc_codegen_llvm/src/consts.rs	2025-05-07 11:37:17.220114783 -0400
@@ -371,8 +371,9 @@
             // otherwise some LLVM optimization passes don't work as expected
             let mut val_llty = self.val_ty(v);
             let v = if val_llty == self.type_i1() {
-                val_llty = self.type_i8();
-                llvm::LLVMConstZExt(v, val_llty)
+                // val_llty = self.type_i8();
+                // llvm::LLVMConstZExt(v, val_llty)
+                unimplemented!("Const ZExt");
             } else {
                 v
             };
--- rustc-1.74.0-src.orig/compiler/rustc_codegen_llvm/src/llvm/ffi.rs	2023-11-12 23:10:51.000000000 -0500
+++ rustc-1.74.0-src/compiler/rustc_codegen_llvm/src/llvm/ffi.rs	2025-05-07 11:39:59.399988363 -0400
@@ -969,7 +969,7 @@
         ConstantIndices: *const &'a Value,
         NumIndices: c_uint,
     ) -> &'a Value;
-    pub fn LLVMConstZExt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
+    // pub fn LLVMConstZExt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
     pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
     pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
     pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
--- rustc-1.74.0-src.orig/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h	2023-11-12 23:10:51.000000000 -0500
+++ rustc-1.74.0-src/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h	2025-05-06 22:48:58.362609469 -0400
@@ -23,9 +23,9 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/IPO.h"
-#include "llvm/Transforms/Instrumentation.h"
+#include "llvm/Transforms/Utils/Instrumentation.h"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Vectorize.h"
+#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"

 #define LLVM_VERSION_GE(major, minor)                                          \
   (LLVM_VERSION_MAJOR > (major) ||                                             \
--- ./rustc-1.74.0-src.orig/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp	2023-11-13 04:10:51.000000000 +0000
+++ ./rustc-1.74.0-src/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp	2025-05-08 01:29:24.667035511 +0000
@@ -1,3 +1,4 @@
+#include <llvm/Pass.h>
 #include <stdio.h>

 #include <cstddef>
@@ -38,7 +39,7 @@
 #include "llvm/LTO/LTO.h"
 #include "llvm/Bitcode/BitcodeWriter.h"

-#include "llvm/Transforms/Instrumentation.h"
+#include "llvm/Transforms/Utils/Instrumentation.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
@@ -50,6 +51,9 @@
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils.h"

+#include "llvm-c/TargetMachine.h"
+#include "llvm-c/Target.h"
+
 using namespace llvm;

 static codegen::RegisterCodeGenFlags CGF;
@@ -331,7 +335,7 @@
                                         PrintBackendInfo Print,
                                         void* Out) {
   const TargetMachine *Target = unwrap(TM);
-  const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
+  const Triple::ArchType HostArch = Triple(LLVMGetDefaultTargetTriple()).getArch();
   const Triple::ArchType TargetArch = Target->getTargetTriple().getArch();

   std::ostringstream Buf;
@@ -351,7 +355,7 @@
   // different arch since that could be wrong or misleading.
   if (HostArch == TargetArch) {
     MaxCPULen = std::max(MaxCPULen, (unsigned) std::strlen("native"));
-    const StringRef HostCPU = sys::getHostCPUName();
+    const StringRef HostCPU = LLVMGetHostCPUName();
     Buf << "    " << std::left << std::setw(MaxCPULen) << "native"
         << " - Select the CPU of the current host "
            "(currently " << HostCPU.str() << ").\n";
@@ -397,7 +401,7 @@
 }

 extern "C" const char* LLVMRustGetHostCPUName(size_t *len) {
-  StringRef Name = sys::getHostCPUName();
+  StringRef Name = LLVMGetHostCPUName();
   *len = Name.size();
   return Name.data();
 }
@@ -452,7 +456,7 @@
   if (OutputObjFile) {
       Options.ObjectFilenameForDebug = OutputObjFile;
   }
-#if LLVM_VERSION_GE(16, 0)
+/*#if LLVM_VERSION_GE(16, 0)
   if (!strcmp("zlib", DebugInfoCompression) && llvm::compression::zlib::isAvailable()) {
     Options.CompressDebugSections = DebugCompressionType::Zlib;
   } else if (!strcmp("zstd", DebugInfoCompression) && llvm::compression::zstd::isAvailable()) {
@@ -460,9 +464,9 @@
   } else if (!strcmp("none", DebugInfoCompression)) {
     Options.CompressDebugSections = DebugCompressionType::None;
   }
-#endif
+#endif*/

-  Options.RelaxELFRelocations = RelaxELFRelocations;
+  //Options.RelaxELFRelocations = RelaxELFRelocations;
   Options.UseInitArray = UseInitArray;

 #if LLVM_VERSION_LT(17, 0)
@@ -515,8 +519,11 @@
     assert(buffer_offset == ArgsCstrBuffLen);

     Options.MCOptions.Argv0 = arg0;
-    Options.MCOptions.CommandLineArgs =
-      llvm::ArrayRef<std::string>(cmd_arg_strings, num_cmd_arg_strings);
+    std::string args = "";
+    for (int i = 0; i < num_cmd_arg_strings; i++) {
+      args += cmd_arg_strings[i] + " ";
+    }
+    Options.MCOptions.CommandlineArgs = args;
   }

   TargetMachine *TM = TheTarget->createTargetMachine(
@@ -527,8 +534,8 @@
 extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {

   MCTargetOptions& MCOptions = unwrap(TM)->Options.MCOptions;
-  delete[] MCOptions.Argv0;
-  delete[] MCOptions.CommandLineArgs.data();
+  // delete[] MCOptions.Argv0;
+  // delete[] MCOptions.CommandLineArgs.data();

   delete unwrap(TM);
 }
@@ -541,7 +548,7 @@
   TargetLibraryInfoImpl TLII(TargetTriple);
   if (DisableSimplifyLibCalls)
     TLII.disableAllFunctions();
-  unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII));
+  unwrap(PMR)->add(reinterpret_cast<Pass*>(new TargetLibraryInfoWrapperPass(TLII)));
 }

 extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
@@ -761,6 +768,7 @@
                         FS,
 #endif
                         PGOOptions::IRInstr, PGOOptions::NoCSAction,
+                        PGOOptions::ColdFuncOpt::Default,
                         DebugInfoForProfiling);
   } else if (PGOUsePath) {
     assert(!PGOSampleUsePath);
@@ -770,6 +778,7 @@
                         FS,
 #endif
                         PGOOptions::IRUse, PGOOptions::NoCSAction,
+                        PGOOptions::ColdFuncOpt::Default,
                         DebugInfoForProfiling);
   } else if (PGOSampleUsePath) {
     PGOOpt = PGOOptions(PGOSampleUsePath, "", "",
@@ -778,6 +787,7 @@
                         FS,
 #endif
                         PGOOptions::SampleUse, PGOOptions::NoCSAction,
+                        PGOOptions::ColdFuncOpt::Default,
                         DebugInfoForProfiling);
   } else if (DebugInfoForProfiling) {
     PGOOpt = PGOOptions("", "", "",
@@ -786,6 +796,7 @@
                         FS,
 #endif
                         PGOOptions::NoAction, PGOOptions::NoCSAction,
+                        PGOOptions::ColdFuncOpt::Default,
                         DebugInfoForProfiling);
   }

@@ -813,7 +824,7 @@
   // PassBuilder does not create a pipeline.
   std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
       PipelineStartEPCallbacks;
-  std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
+  std::vector<std::function<void(ModulePassManager &, OptimizationLevel, ThinOrFullLTOPhase)>>
       OptimizerLastEPCallbacks;

   if (!IsLinkerPluginLTO
@@ -823,7 +834,7 @@
       [](ModulePassManager &MPM, OptimizationLevel Level) {
         MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
                                        /*ImportSummary=*/nullptr,
-                                       /*DropTypeTests=*/false));
+                                       /*DropTypeTests=*/llvm::lowertypetests::DropTestKind::None));
       }
     );
   }
@@ -854,7 +865,7 @@
         // cargo run tests in multhreading mode by default
         // so use atomics for coverage counters
         Options.Atomic = true;
-        MPM.addPass(InstrProfiling(Options, false));
+        MPM.addPass(InstrProfilingLoweringPass(Options, false));
       }
     );
   }
@@ -867,7 +878,7 @@
           /*CompileKernel=*/false,
           /*EagerChecks=*/true);
       OptimizerLastEPCallbacks.push_back(
-        [Options](ModulePassManager &MPM, OptimizationLevel Level) {
+        [Options](ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase _) {
 #if LLVM_VERSION_LT(16, 0)
           MPM.addPass(ModuleMemorySanitizerPass(Options));
           MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
@@ -880,7 +891,7 @@

     if (SanitizerOptions->SanitizeThread) {
       OptimizerLastEPCallbacks.push_back(
-        [](ModulePassManager &MPM, OptimizationLevel Level) {
+        [](ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase _) {
           MPM.addPass(ModuleThreadSanitizerPass());
           MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
         }
@@ -889,7 +900,7 @@

     if (SanitizerOptions->SanitizeAddress || SanitizerOptions->SanitizeKernelAddress) {
       OptimizerLastEPCallbacks.push_back(
-        [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
+        [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase _) {
           auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
           AddressSanitizerOptions opts = AddressSanitizerOptions{
             CompileKernel,
@@ -908,7 +919,7 @@
     }
     if (SanitizerOptions->SanitizeHWAddress) {
       OptimizerLastEPCallbacks.push_back(
-        [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
+        [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase _) {
           HWAddressSanitizerOptions opts(
               /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover,
               /*DisableOptimization=*/false);
@@ -945,7 +956,7 @@
         PB.registerOptimizerLastEPCallback(C);

       // Pass false as we manually schedule ThinLTOBufferPasses below.
-      MPM = PB.buildO0DefaultPipeline(OptLevel, /* PreLinkLTO */ false);
+      MPM = PB.buildO0DefaultPipeline(OptLevel, /* PreLinkLTO */ ThinOrFullLTOPhase::FullLTOPreLink);
     } else {
       for (const auto &C : PipelineStartEPCallbacks)
         PB.registerPipelineStartEPCallback(C);
@@ -956,7 +967,7 @@

       switch (OptStage) {
       case LLVMRustOptStage::PreLinkNoLTO:
-        MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
+        MPM = PB.buildPerModuleDefaultPipeline(OptLevel, ThinOrFullLTOPhase::FullLTOPreLink);
         break;
       case LLVMRustOptStage::PreLinkThinLTO:
         MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);
@@ -967,7 +978,7 @@
         if (OptimizerLastEPCallbacks.empty())
           NeedThinLTOBufferPasses = false;
         for (const auto &C : OptimizerLastEPCallbacks)
-          C(MPM, OptLevel);
+          C(MPM, OptLevel, ThinOrFullLTOPhase::None);
         break;
       case LLVMRustOptStage::PreLinkFatLTO:
         MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel);
@@ -989,7 +1000,7 @@
     for (const auto &C : PipelineStartEPCallbacks)
       C(MPM, OptLevel);
     for (const auto &C : OptimizerLastEPCallbacks)
-      C(MPM, OptLevel);
+      C(MPM, OptLevel, ThinOrFullLTOPhase::None);
   }

   if (ExtraPassesLen) {
@@ -1218,7 +1229,7 @@
   // Not 100% sure what these are, but they impact what's internalized and
   // what's inlined across modules, I believe.
 #if LLVM_VERSION_GE(18, 0)
-  DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
+  FunctionImporter::ImportListsTy ImportLists;
   DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
   DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
 #else
@@ -1407,12 +1418,12 @@
   TargetMachine &Target = *unwrap(TM);

   bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
-  bool error = renameModuleForThinLTO(Mod, Data->Index, ClearDSOLocal);
+  renameModuleForThinLTO(Mod, Data->Index, ClearDSOLocal);

-  if (error) {
-    LLVMRustSetLastError("renameModuleForThinLTO failed");
-    return false;
-  }
+  // if (error) {
+  //   LLVMRustSetLastError("renameModuleForThinLTO failed");
+  //   return false;
+  // }
   return true;
 }

@@ -1629,14 +1640,13 @@
 // used during the normal linker-plugin incremental thin-LTO process.
 extern "C" void
 LLVMRustComputeLTOCacheKey(RustStringRef KeyOut, const char *ModId, LLVMRustThinLTOData *Data) {
-  SmallString<40> Key;
   llvm::lto::Config conf;
   const auto &ImportList = Data->ImportLists.lookup(ModId);
   const auto &ExportList = Data->ExportLists.lookup(ModId);
   const auto &ResolvedODR = Data->ResolvedODR.lookup(ModId);
   const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(ModId);
-  std::set<GlobalValue::GUID> CfiFunctionDefs;
-  std::set<GlobalValue::GUID> CfiFunctionDecls;
+  DenseSet<GlobalValue::GUID> CfiFunctionDefs;
+  DenseSet<GlobalValue::GUID> CfiFunctionDecls;

   // Based on the 'InProcessThinBackend' constructor in LLVM
   for (auto &Name : Data->Index.cfiFunctionDefs())
@@ -1646,7 +1656,7 @@
     CfiFunctionDecls.insert(
         GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));

-  llvm::computeLTOCacheKey(Key, conf, Data->Index, ModId,
+  std::string Key = llvm::computeLTOCacheKey(conf, Data->Index, ModId,
       ImportList, ExportList, ResolvedODR, DefinedGlobals, CfiFunctionDefs, CfiFunctionDecls
   );
   
--- rustc-1.74.0-src.orig/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp	2023-11-12 23:10:51.000000000 -0500
+++ rustc-1.74.0-src/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp	2025-05-07 11:23:24.661493619 -0400
@@ -1081,11 +1081,12 @@
     LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
     uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
     LLVMBasicBlockRef InsertAtEnd) {
-  return wrap(Builder->insertDeclare(
+    Builder->insertDeclare(
       unwrap(V), unwrap<DILocalVariable>(VarInfo),
       Builder->createExpression(llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)),
       DebugLoc(cast<MDNode>(unwrap(DL))),
-      unwrap(InsertAtEnd)));
+      unwrap(InsertAtEnd));
+    return nullptr; //FIXME: VERY BAD
 }

 extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
@@ -1105,7 +1106,7 @@
       unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
       unwrapDI<DIFile>(File), LineNumber,
       SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
-      unwrapDI<DIType>(ClassTy), "", IsScoped));
+      unwrapDI<DIType>(ClassTy), 0, "", IsScoped));
 }

 extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
@@ -1369,8 +1370,8 @@
     return LLVMPointerTypeKind;
   case Type::FixedVectorTyID:
     return LLVMVectorTypeKind;
-  case Type::X86_MMXTyID:
-    return LLVMX86_MMXTypeKind;
+  // case Type::X86_MMXTyID:
+  //   return LLVMX86_MMXTypeKind;
   case Type::TokenTyID:
     return LLVMTokenTypeKind;
   case Type::ScalableVectorTyID:
@@ -1814,6 +1815,7 @@
       std::string{},    // ExtName
       std::string{},    // SymbolName
       std::string{},    // AliasTarget
+      std::string{},
       ordinal,          // Ordinal
       ordinal_present,  // Noname
       false,            // Data
@@ -1909,7 +1911,7 @@
         }
       }
       if (DiagnosticHandlerCallback) {
-        DiagnosticHandlerCallback(DI, DiagnosticHandlerContext);
+        DiagnosticHandlerCallback(&DI, DiagnosticHandlerContext);
         return true;
       }
       return false;
--- rustc-1.74.0-src.orig/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs	2023-11-12 23:10:51.000000000 -0500
+++ rustc-1.74.0-src/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs	2025-05-07 17:44:10.449613830 -0400
@@ -18,8 +18,9 @@
     Target {
         llvm_target: "x86_64-unknown-linux-musl".into(),
         pointer_width: 64,
-        data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-            .into(),
+        //data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+        data_layout:
+            "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
         arch: "x86_64".into(),
         options: base,
     }