fix crash when using zig to link
without explicit dynamic linker
This commit is contained in:
@@ -768,89 +768,8 @@ LLVMValueRef ZigLLVMBuildNUWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMVa
|
||||
return wrap(unwrap(builder)->CreateShl(unwrap(LHS), unwrap(RHS), name, false, true));
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
enum FloatAbi {
|
||||
FloatAbiHard,
|
||||
FloatAbiSoft,
|
||||
FloatAbiSoftFp,
|
||||
};
|
||||
|
||||
static FloatAbi get_float_abi(const Triple &triple) {
|
||||
if (triple.getEnvironment() == Triple::GNUEABIHF ||
|
||||
triple.getEnvironment() == Triple::EABIHF ||
|
||||
triple.getEnvironment() == Triple::MuslEABIHF)
|
||||
{
|
||||
return FloatAbiHard;
|
||||
} else {
|
||||
zig_panic("TODO: user needs to input if they want hard or soft floating point");
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag_buf) {
|
||||
ArrayRef<const char *> array_ref_args(args, arg_count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user