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
|
/*
* Copyright (c) 2015 Andrew Kelley
*
* This file is part of zig, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#include "zig_llvm.hpp"
/*
* The point of this file is to contain all the LLVM C++ API interaction so that:
* 1. The compile time of other files is kept under control.
* 2. Provide a C interface to the LLVM functions we need for self-hosting purposes.
* 3. Prevent C++ from infecting the rest of the project.
*/
#include <llvm/InitializePasses.h>
#include <llvm/PassRegistry.h>
#include <llvm/MC/SubtargetFeature.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/TargetParser.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/DIBuilder.h>
#include <llvm/IR/DiagnosticInfo.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/Scalar.h>
using namespace llvm;
void LLVMZigInitializeLoopStrengthReducePass(LLVMPassRegistryRef R) {
initializeLoopStrengthReducePass(*unwrap(R));
}
void LLVMZigInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R) {
initializeLowerIntrinsicsPass(*unwrap(R));
}
void LLVMZigInitializeUnreachableBlockElimPass(LLVMPassRegistryRef R) {
initializeUnreachableBlockElimPass(*unwrap(R));
}
char *LLVMZigGetHostCPUName(void) {
std::string str = sys::getHostCPUName();
return strdup(str.c_str());
}
char *LLVMZigGetNativeFeatures(void) {
SubtargetFeatures features;
StringMap<bool> host_features;
if (sys::getHostCPUFeatures(host_features)) {
for (auto &F : host_features)
features.AddFeature(F.first(), F.second);
}
return strdup(features.getString().c_str());
}
static void addAddDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
PM.add(createAddDiscriminatorsPass());
}
void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref) {
TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref);
Module* module = unwrap(module_ref);
TargetLibraryInfoImpl tlii(Triple(module->getTargetTriple()));
PassManagerBuilder *PMBuilder = new PassManagerBuilder();
PMBuilder->OptLevel = target_machine->getOptLevel();
PMBuilder->SizeLevel = 0;
PMBuilder->BBVectorize = true;
PMBuilder->SLPVectorize = true;
PMBuilder->LoopVectorize = true;
PMBuilder->DisableUnitAtATime = false;
PMBuilder->DisableUnrollLoops = false;
PMBuilder->MergeFunctions = true;
PMBuilder->PrepareForLTO = true;
PMBuilder->RerollLoops = true;
PMBuilder->addExtension(PassManagerBuilder::EP_EarlyAsPossible, addAddDiscriminatorsPass);
PMBuilder->LibraryInfo = &tlii;
PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel);
// Set up the per-function pass manager.
legacy::FunctionPassManager *FPM = new legacy::FunctionPassManager(module);
FPM->add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis()));
#ifndef NDEBUG
bool verify_module = true;
#else
bool verify_module = false;
#endif
if (verify_module) {
FPM->add(createVerifierPass());
}
PMBuilder->populateFunctionPassManager(*FPM);
// Set up the per-module pass manager.
legacy::PassManager *MPM = new legacy::PassManager();
MPM->add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis()));
PMBuilder->populateModulePassManager(*MPM);
// run per function optimization passes
FPM->doInitialization();
for (Function &F : *module)
if (!F.isDeclaration())
FPM->run(F);
FPM->doFinalization();
// run per module optimization passes
MPM->run(*module);
}
LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
unsigned NumArgs, unsigned CC, const char *Name)
{
CallInst *call_inst = CallInst::Create(unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Name);
call_inst->setCallingConv(CC);
return wrap(unwrap(B)->Insert(call_inst));
}
LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,
uint64_t size_in_bits, uint64_t align_in_bits, const char *name)
{
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createPointerType(
reinterpret_cast<DIType*>(pointee_type), size_in_bits, align_in_bits, name);
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
LLVMZigDIType *LLVMZigCreateDebugBasicType(LLVMZigDIBuilder *dibuilder, const char *name,
uint64_t size_in_bits, uint64_t align_in_bits, unsigned encoding)
{
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createBasicType(
name, size_in_bits, align_in_bits, encoding);
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
LLVMZigDIType *LLVMZigCreateDebugArrayType(LLVMZigDIBuilder *dibuilder, uint64_t size_in_bits,
uint64_t align_in_bits, LLVMZigDIType *elem_type, int elem_count)
{
SmallVector<Metadata *, 1> subrange;
subrange.push_back(reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateSubrange(0, elem_count - 1));
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createArrayType(
size_in_bits, align_in_bits,
reinterpret_cast<DIType*>(elem_type),
reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateArray(subrange));
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
LLVMZigDIType *LLVMZigCreateDebugMemberType(LLVMZigDIBuilder *dibuilder, LLVMZigDIScope *scope,
const char *name, LLVMZigDIFile *file, unsigned line, uint64_t size_in_bits,
uint64_t align_in_bits, uint64_t offset_in_bits, unsigned flags, LLVMZigDIType *type)
{
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createMemberType(
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line, size_in_bits, align_in_bits, offset_in_bits, flags,
reinterpret_cast<DIType*>(type));
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
LLVMZigDIType *LLVMZigCreateDebugStructType(LLVMZigDIBuilder *dibuilder, LLVMZigDIScope *scope,
const char *name, LLVMZigDIFile *file, unsigned line_number, uint64_t size_in_bits,
uint64_t align_in_bits, unsigned flags, LLVMZigDIType *derived_from,
LLVMZigDIType **types_array, int types_array_len, unsigned run_time_lang, LLVMZigDIType *vtable_holder,
const char *unique_id)
{
SmallVector<Metadata *, 8> fields;
for (int i = 0; i < types_array_len; i += 1) {
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
fields.push_back(ditype);
}
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createStructType(
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line_number, size_in_bits, align_in_bits, flags,
reinterpret_cast<DIType*>(derived_from),
reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateArray(fields),
run_time_lang,
reinterpret_cast<DIType*>(vtable_holder),
unique_id);
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder, unsigned tag,
const char *name, LLVMZigDIScope *scope, LLVMZigDIFile *file, unsigned line)
{
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createReplaceableCompositeType(
tag, name,
reinterpret_cast<DIScope*>(scope),
reinterpret_cast<DIFile*>(file),
line);
return reinterpret_cast<LLVMZigDIType*>(di_type);
}
void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
LLVMZigDIType *replacement)
{
reinterpret_cast<DIBuilder*>(dibuilder)->replaceTemporary(
TempDIType(reinterpret_cast<DIType*>(type)),
reinterpret_cast<DIType*>(replacement));
}
void LLVMZigReplaceDebugArrays(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
LLVMZigDIType **types_array, int types_array_len)
{
SmallVector<Metadata *, 8> fields;
for (int i = 0; i < types_array_len; i += 1) {
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
fields.push_back(ditype);
}
DICompositeType *composite_type = (DICompositeType*)reinterpret_cast<DIType*>(type);
reinterpret_cast<DIBuilder*>(dibuilder)->replaceArrays(
composite_type,
reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateArray(fields));
}
LLVMZigDISubroutineType *LLVMZigCreateSubroutineType(LLVMZigDIBuilder *dibuilder_wrapped,
LLVMZigDIFile *file, LLVMZigDIType **types_array, int types_array_len, unsigned flags)
{
SmallVector<Metadata *, 8> types;
for (int i = 0; i < types_array_len; i += 1) {
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
types.push_back(ditype);
}
DIBuilder *dibuilder = reinterpret_cast<DIBuilder*>(dibuilder_wrapped);
DISubroutineType *subroutine_type = dibuilder->createSubroutineType(
reinterpret_cast<DIFile*>(file),
dibuilder->getOrCreateTypeArray(types),
flags);
return reinterpret_cast<LLVMZigDISubroutineType*>(subroutine_type);
}
unsigned LLVMZigEncoding_DW_ATE_unsigned(void) {
return dwarf::DW_ATE_unsigned;
}
unsigned LLVMZigEncoding_DW_ATE_signed(void) {
return dwarf::DW_ATE_signed;
}
unsigned LLVMZigEncoding_DW_ATE_float(void) {
return dwarf::DW_ATE_float;
}
unsigned LLVMZigLang_DW_LANG_C99(void) {
return dwarf::DW_LANG_C99;
}
unsigned LLVMZigTag_DW_auto_variable(void) {
return dwarf::DW_TAG_auto_variable;
}
unsigned LLVMZigTag_DW_arg_variable(void) {
return dwarf::DW_TAG_arg_variable;
}
unsigned LLVMZigTag_DW_structure_type(void) {
return dwarf::DW_TAG_structure_type;
}
LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved) {
DIBuilder *di_builder = new DIBuilder(*unwrap(module), allow_unresolved);
return reinterpret_cast<LLVMZigDIBuilder *>(di_builder);
}
void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope) {
unwrap(builder)->SetCurrentDebugLocation(DebugLoc::get(
line, column, reinterpret_cast<DIScope*>(scope)));
}
LLVMZigDILexicalBlock *LLVMZigCreateLexicalBlock(LLVMZigDIBuilder *dbuilder, LLVMZigDIScope *scope,
LLVMZigDIFile *file, unsigned line, unsigned col)
{
DILexicalBlock *result = reinterpret_cast<DIBuilder*>(dbuilder)->createLexicalBlock(
reinterpret_cast<DIScope*>(scope),
reinterpret_cast<DIFile*>(file),
line,
col);
return reinterpret_cast<LLVMZigDILexicalBlock*>(result);
}
LLVMZigDILocalVariable *LLVMZigCreateLocalVariable(LLVMZigDIBuilder *dbuilder, unsigned tag,
LLVMZigDIScope *scope, const char *name, LLVMZigDIFile *file, unsigned line_no,
LLVMZigDIType *type, bool always_preserve, unsigned flags, unsigned arg_no)
{
DILocalVariable *result = reinterpret_cast<DIBuilder*>(dbuilder)->createLocalVariable(
tag,
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line_no,
reinterpret_cast<DIType*>(type),
always_preserve,
flags,
arg_no);
return reinterpret_cast<LLVMZigDILocalVariable*>(result);
}
LLVMZigDIScope *LLVMZigLexicalBlockToScope(LLVMZigDILexicalBlock *lexical_block) {
DIScope *scope = reinterpret_cast<DILexicalBlock*>(lexical_block);
return reinterpret_cast<LLVMZigDIScope*>(scope);
}
LLVMZigDIScope *LLVMZigCompileUnitToScope(LLVMZigDICompileUnit *compile_unit) {
DIScope *scope = reinterpret_cast<DICompileUnit*>(compile_unit);
return reinterpret_cast<LLVMZigDIScope*>(scope);
}
LLVMZigDIScope *LLVMZigFileToScope(LLVMZigDIFile *difile) {
DIScope *scope = reinterpret_cast<DIFile*>(difile);
return reinterpret_cast<LLVMZigDIScope*>(scope);
}
LLVMZigDIScope *LLVMZigSubprogramToScope(LLVMZigDISubprogram *subprogram) {
DIScope *scope = reinterpret_cast<DISubprogram*>(subprogram);
return reinterpret_cast<LLVMZigDIScope*>(scope);
}
LLVMZigDIScope *LLVMZigTypeToScope(LLVMZigDIType *type) {
DIScope *scope = reinterpret_cast<DIType*>(type);
return reinterpret_cast<LLVMZigDIScope*>(scope);
}
LLVMZigDICompileUnit *LLVMZigCreateCompileUnit(LLVMZigDIBuilder *dibuilder,
unsigned lang, const char *file, const char *dir, const char *producer,
bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name,
uint64_t dwo_id, bool emit_debug_info)
{
DICompileUnit *result = reinterpret_cast<DIBuilder*>(dibuilder)->createCompileUnit(
lang, file, dir, producer, is_optimized, flags, runtime_version, split_name,
DIBuilder::FullDebug, dwo_id, emit_debug_info);
return reinterpret_cast<LLVMZigDICompileUnit*>(result);
}
LLVMZigDIFile *LLVMZigCreateFile(LLVMZigDIBuilder *dibuilder, const char *filename, const char *directory) {
DIFile *result = reinterpret_cast<DIBuilder*>(dibuilder)->createFile(filename, directory);
return reinterpret_cast<LLVMZigDIFile*>(result);
}
LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigDIScope *scope,
const char *name, const char *linkage_name, LLVMZigDIFile *file, unsigned lineno,
LLVMZigDISubroutineType *ty, bool is_local_to_unit, bool is_definition, unsigned scope_line,
unsigned flags, bool is_optimized, LLVMValueRef function)
{
Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(function));
DISubprogram *result = reinterpret_cast<DIBuilder*>(dibuilder)->createFunction(
reinterpret_cast<DIScope*>(scope),
name, linkage_name,
reinterpret_cast<DIFile*>(file),
lineno,
reinterpret_cast<DISubroutineType*>(ty),
is_local_to_unit, is_definition, scope_line, flags, is_optimized, unwrapped_function);
return reinterpret_cast<LLVMZigDISubprogram*>(result);
}
void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder) {
reinterpret_cast<DIBuilder*>(dibuilder)->finalize();
}
LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder_wrapped) {
IRBuilderBase::InsertPoint *ip = new IRBuilderBase::InsertPoint();
*ip = unwrap(builder_wrapped)->saveIP();
return reinterpret_cast<LLVMZigInsertionPoint*>(ip);
}
void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *ip_wrapped) {
IRBuilderBase::InsertPoint *ip = reinterpret_cast<IRBuilderBase::InsertPoint*>(ip_wrapped);
unwrap(builder)->restoreIP(*ip);
}
LLVMValueRef LLVMZigInsertDeclareAtEnd(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref)
{
Instruction *result = reinterpret_cast<DIBuilder*>(dibuilder)->insertDeclare(
unwrap(storage),
reinterpret_cast<DILocalVariable *>(var_info),
reinterpret_cast<DIBuilder*>(dibuilder)->createExpression(),
reinterpret_cast<DILocation*>(debug_loc),
static_cast<BasicBlock*>(unwrap(basic_block_ref)));
return wrap(result);
}
LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr)
{
Instruction *result = reinterpret_cast<DIBuilder*>(dibuilder)->insertDeclare(
unwrap(storage),
reinterpret_cast<DILocalVariable *>(var_info),
reinterpret_cast<DIBuilder*>(dibuilder)->createExpression(),
reinterpret_cast<DILocation*>(debug_loc),
static_cast<Instruction*>(unwrap(insert_before_instr)));
return wrap(result);
}
LLVMZigDILocation *LLVMZigGetDebugLoc(unsigned line, unsigned col, LLVMZigDIScope *scope) {
DebugLoc debug_loc = DebugLoc::get(line, col, reinterpret_cast<DIScope*>(scope), nullptr);
return reinterpret_cast<LLVMZigDILocation*>(debug_loc.get());
}
void LLVMZigSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state) {
if (on_state) {
FastMathFlags fmf;
fmf.setUnsafeAlgebra();
unwrap(builder_wrapped)->SetFastMathFlags(fmf);
} else {
unwrap(builder_wrapped)->clearFastMathFlags();
}
}
//------------------------------------
enum FloatAbi {
FloatAbiHard,
FloatAbiSoft,
FloatAbiSoftFp,
};
static int get_arm_sub_arch_version(const Triple &triple) {
return ARMTargetParser::parseArchVersion(triple.getArchName());
}
static FloatAbi get_float_abi(const Triple &triple) {
switch (triple.getOS()) {
case Triple::Darwin:
case Triple::MacOSX:
case Triple::IOS:
if (get_arm_sub_arch_version(triple) == 6 ||
get_arm_sub_arch_version(triple) == 7)
{
return FloatAbiSoftFp;
} else {
return FloatAbiSoft;
}
case Triple::Win32:
return FloatAbiHard;
case Triple::FreeBSD:
switch (triple.getEnvironment()) {
case Triple::GNUEABIHF:
return FloatAbiHard;
default:
return FloatAbiSoft;
}
default:
switch (triple.getEnvironment()) {
case Triple::GNUEABIHF:
return FloatAbiHard;
case Triple::GNUEABI:
return FloatAbiSoftFp;
case Triple::EABIHF:
return FloatAbiHard;
case Triple::EABI:
return FloatAbiSoftFp;
case Triple::Android:
if (get_arm_sub_arch_version(triple) == 7) {
return FloatAbiSoftFp;
} else {
return FloatAbiSoft;
}
default:
return FloatAbiSoft;
}
}
}
Buf *get_dynamic_linker(LLVMTargetMachineRef target_machine_ref) {
TargetMachine *target_machine = reinterpret_cast<TargetMachine*>(target_machine_ref);
const Triple &triple = target_machine->getTargetTriple();
const Triple::ArchType arch = triple.getArch();
if (triple.getEnvironment() == Triple::Android) {
if (triple.isArch64Bit()) {
return buf_create_from_str("/system/bin/linker64");
} else {
return buf_create_from_str("/system/bin/linker");
}
} else if (arch == Triple::x86 ||
arch == Triple::sparc ||
arch == Triple::sparcel)
{
return buf_create_from_str("/lib/ld-linux.so.2");
} else if (arch == Triple::aarch64) {
return buf_create_from_str("/lib/ld-linux-aarch64.so.1");
} else if (arch == Triple::aarch64_be) {
return buf_create_from_str("/lib/ld-linux-aarch64_be.so.1");
} else if (arch == Triple::arm || arch == Triple::thumb) {
if (triple.getEnvironment() == Triple::GNUEABIHF ||
get_float_abi(triple) == FloatAbiHard)
{
return buf_create_from_str("/lib/ld-linux-armhf.so.3");
} else {
return buf_create_from_str("/lib/ld-linux.so.3");
}
} else if (arch == Triple::armeb || arch == Triple::thumbeb) {
if (triple.getEnvironment() == Triple::GNUEABIHF ||
get_float_abi(triple) == FloatAbiHard)
{
return buf_create_from_str("/lib/ld-linux-armhf.so.3");
} else {
return buf_create_from_str("/lib/ld-linux.so.3");
}
} else if (arch == Triple::mips || arch == Triple::mipsel ||
arch == Triple::mips64 || arch == Triple::mips64el)
{
// when you want to solve this TODO, grep clang codebase for
// getLinuxDynamicLinker
zig_panic("TODO figure out MIPS dynamic linker name");
} else if (arch == Triple::ppc) {
return buf_create_from_str("/lib/ld.so.1");
} else if (arch == Triple::ppc64) {
return buf_create_from_str("/lib64/ld64.so.2");
} else if (arch == Triple::ppc64le) {
return buf_create_from_str("/lib64/ld64.so.2");
} else if (arch == Triple::systemz) {
return buf_create_from_str("/lib64/ld64.so.1");
} else if (arch == Triple::sparcv9) {
return buf_create_from_str("/lib64/ld-linux.so.2");
} else if (arch == Triple::x86_64 &&
triple.getEnvironment() == Triple::GNUX32)
{
return buf_create_from_str("/libx32/ld-linux-x32.so.2");
} else {
return buf_create_from_str("/lib64/ld-linux-x86-64.so.2");
}
}
|