@@ -406,7 +406,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
406
406
bool RelaxELFRelocations,
407
407
bool UseInitArray,
408
408
const char *SplitDwarfFile,
409
- bool ForceEmulatedTls) {
409
+ bool ForceEmulatedTls,
410
+ const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
410
411
411
412
auto OptLevel = fromRust (RustOptLevel);
412
413
auto RM = fromRust (RustReloc);
@@ -462,12 +463,48 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
462
463
463
464
Options.EmitStackSizeSection = EmitStackSizeSection;
464
465
466
+
467
+ if (ArgsCstrBuff != nullptr )
468
+ {
469
+ int buffer_offset = 0 ;
470
+ assert (ArgsCstrBuff[ArgsCstrBuffLen - 1 ] == ' \0 ' );
471
+
472
+ const size_t arg0_len = std::strlen (ArgsCstrBuff);
473
+ char * arg0 = new char [arg0_len + 1 ];
474
+ memcpy (arg0, ArgsCstrBuff, arg0_len);
475
+ arg0[arg0_len] = ' \0 ' ;
476
+ buffer_offset += arg0_len + 1 ;
477
+
478
+ const int num_cmd_arg_strings =
479
+ std::count (&ArgsCstrBuff[buffer_offset], &ArgsCstrBuff[ArgsCstrBuffLen], ' \0 ' );
480
+
481
+ std::string* cmd_arg_strings = new std::string[num_cmd_arg_strings];
482
+ for (int i = 0 ; i < num_cmd_arg_strings; ++i)
483
+ {
484
+ assert (buffer_offset < ArgsCstrBuffLen);
485
+ const int len = std::strlen (ArgsCstrBuff + buffer_offset);
486
+ cmd_arg_strings[i] = std::string (&ArgsCstrBuff[buffer_offset], len);
487
+ buffer_offset += len + 1 ;
488
+ }
489
+
490
+ assert (buffer_offset == ArgsCstrBuffLen);
491
+
492
+ Options.MCOptions .Argv0 = arg0;
493
+ Options.MCOptions .CommandLineArgs =
494
+ llvm::ArrayRef<std::string>(cmd_arg_strings, num_cmd_arg_strings);
495
+ }
496
+
465
497
TargetMachine *TM = TheTarget->createTargetMachine (
466
498
Trip.getTriple (), CPU, Feature, Options, RM, CM, OptLevel);
467
499
return wrap (TM);
468
500
}
469
501
470
502
extern " C" void LLVMRustDisposeTargetMachine (LLVMTargetMachineRef TM) {
503
+
504
+ MCTargetOptions& MCOptions = unwrap (TM)->Options .MCOptions ;
505
+ delete[] MCOptions.Argv0 ;
506
+ delete[] MCOptions.CommandLineArgs .data ();
507
+
471
508
delete unwrap (TM);
472
509
}
473
510
0 commit comments