From 1c82d12cd0fdd3582a6e1fc5bbb97fc6b9b59555 Mon Sep 17 00:00:00 2001 From: Joakim Date: Sun, 18 Nov 2018 23:30:05 +0530 Subject: [PATCH 1/5] Android: change `long double` mangling on Android/x64 to `g` --- dmd/cppmangle.d | 4 +++- dmd/target.d | 14 +------------- gen/target.cpp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/dmd/cppmangle.d b/dmd/cppmangle.d index 96a1605c7ce..203368129e9 100644 --- a/dmd/cppmangle.d +++ b/dmd/cppmangle.d @@ -1196,7 +1196,9 @@ extern(C++): case Tint128: c = 'n'; break; case Tuns128: c = 'o'; break; case Tfloat64: c = 'd'; break; - case Tfloat80: c = 'e'; break; + case Tfloat80: + c = 'e'; + version (IN_LLVM) goto default; else break; case Tbool: c = 'b'; break; case Tchar: c = 'c'; break; case Twchar: c = 't'; break; // unsigned short (perhaps use 'Ds' ? diff --git a/dmd/target.d b/dmd/target.d index 0d469fe5995..b64f61c622d 100644 --- a/dmd/target.d +++ b/dmd/target.d @@ -133,6 +133,7 @@ struct Target return cppTypeInfoMangleItanium(cd); } + static const(char)* cppTypeMangle(Type t); static Expression getTargetInfo(const(char)* name, const ref Loc loc); } else // !IN_LLVM @@ -502,19 +503,6 @@ struct Target } } // !IN_LLVM - /** - * Gets vendor-specific type mangling for C++ ABI. - * Params: - * t = type to inspect - * Returns: - * string if type is mangled specially on target - * null if unhandled - */ - extern (C++) static const(char)* cppTypeMangle(Type t) - { - return null; - } - /** * Get the type that will really be used for passing the given argument * to an `extern(C++)` function. diff --git a/gen/target.cpp b/gen/target.cpp index 4a0dd1707b1..b9226586924 100644 --- a/gen/target.cpp +++ b/gen/target.cpp @@ -210,6 +210,25 @@ bool Target::isReturnOnStack(TypeFunction *tf, bool needsThis) { return gABI->returnInArg(tf, needsThis); } +/** + * Gets vendor-specific type mangling for C++ ABI. + * Params: + * t = type to inspect + * Returns: + * string if type is mangled specially on target + * null if unhandled + */ +const char *Target::cppTypeMangle(Type *t) { + if (t->isTypeBasic() && t->ty == Tfloat80) { + // LDC: `long double` on Android/x64 is __float128 and mangled as `g`. + bool isAndroidX64 = + global.params.targetTriple->getEnvironment() == llvm::Triple::Android && + global.params.targetTriple->getArch() == llvm::Triple::x86_64; + return isAndroidX64 ? "g" : "e"; + } + return nullptr; +} + Expression *Target::getTargetInfo(const char *name_, const Loc &loc) { const llvm::StringRef name(name_); const auto &triple = *global.params.targetTriple; From 8a87cadf62ea8be719a3822986b45a74e0af4427 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 2 Dec 2018 19:30:55 +0100 Subject: [PATCH 2/5] Resync gen/target.cpp with dmd/target.d --- dmd/cppmangle.d | 12 +++++++++--- dmd/target.d | 44 +++++++++++++++++++++++++------------------- gen/target.cpp | 44 +++++++++++++++++++++++--------------------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/dmd/cppmangle.d b/dmd/cppmangle.d index 203368129e9..05b0418b96b 100644 --- a/dmd/cppmangle.d +++ b/dmd/cppmangle.d @@ -1196,9 +1196,15 @@ extern(C++): case Tint128: c = 'n'; break; case Tuns128: c = 'o'; break; case Tfloat64: c = 'd'; break; - case Tfloat80: - c = 'e'; - version (IN_LLVM) goto default; else break; +version (IN_LLVM) +{ + // there are special cases for D `real`, handled via Target.cppTypeMangle() in the default case + case Tfloat80: goto default; +} +else +{ + case Tfloat80: c = 'e'; break; +} case Tbool: c = 'b'; break; case Tchar: c = 'c'; break; case Twchar: c = 't'; break; // unsigned short (perhaps use 'Ds' ? diff --git a/dmd/target.d b/dmd/target.d index b64f61c622d..cc9a57b2618 100644 --- a/dmd/target.d +++ b/dmd/target.d @@ -109,11 +109,10 @@ struct Target // implemented in gen/target.cpp: static void _init(); - // Type sizes and support. static uint alignsize(Type type); static uint fieldalign(Type type); static uint critsecsize(); - static Type va_listType(); // get type of va_list + static Type va_listType(); static int isVectorTypeSupported(int sz, Type type); static bool isVectorOpSupported(Type type, TOK op, Type t2 = null); @@ -134,7 +133,6 @@ struct Target } static const(char)* cppTypeMangle(Type t); - static Expression getTargetInfo(const(char)* name, const ref Loc loc); } else // !IN_LLVM { @@ -501,6 +499,19 @@ struct Target else static assert(0, "fix this"); } + + /** + * Gets vendor-specific type mangling for C++ ABI. + * Params: + * t = type to inspect + * Returns: + * string if type is mangled specially on target + * null if unhandled + */ + extern (C++) static const(char)* cppTypeMangle(Type t) + { + return null; + } } // !IN_LLVM /** @@ -536,6 +547,17 @@ struct Target return global.params.isWindows ? LINK.windows : LINK.c; } + version (IN_LLVM) + { + extern (C++): + + static TypeTuple toArgTypes(Type t); + static bool isReturnOnStack(TypeFunction tf, bool needsThis); + // unused: static ulong parameterSize(const ref Loc loc, Type t); + static Expression getTargetInfo(const(char)* name, const ref Loc loc); + } + else // !IN_LLVM + { /** * Describes how an argument type is passed to a function on target. * Params: @@ -545,19 +567,12 @@ struct Target * empty tuple if type is always passed on the stack * null if the type is a `void` or argtypes aren't supported by the target */ - version (IN_LLVM) - { - extern (C++) static TypeTuple toArgTypes(Type t); - } - else - { extern (C++) static TypeTuple toArgTypes(Type t) { if (global.params.is64bit && global.params.isWindows) return null; return .toArgTypes(t); } - } /** * Determine return style of function - whether in registers or @@ -568,12 +583,6 @@ struct Target * Returns: * true if return value from function is on the stack */ - version (IN_LLVM) - { - extern (C++) static bool isReturnOnStack(TypeFunction tf, bool needsThis); - } - else - { extern (C++) static bool isReturnOnStack(TypeFunction tf, bool needsThis) { if (tf.isref) @@ -726,10 +735,7 @@ struct Target return false; } } - } // !IN_LLVM - version (IN_LLVM) {} else - { /*** * Determine the size a value of type `t` will be when it * is passed on the function parameter stack. diff --git a/gen/target.cpp b/gen/target.cpp index b9226586924..25cdcf196f7 100644 --- a/gen/target.cpp +++ b/gen/target.cpp @@ -26,6 +26,11 @@ using llvm::APFloat; +// in dmd/argtypes.d: +TypeTuple *toArgTypes(Type *t); +// in dmd/argtypes_sysv_x64.d: +TypeTuple *toArgTypes_sysv_x64(Type *t); + void Target::_init() { CTFloat::initialize(); @@ -206,10 +211,6 @@ bool Target::isVectorOpSupported(Type *type, TOK op, Type *t2) { return true; } -bool Target::isReturnOnStack(TypeFunction *tf, bool needsThis) { - return gABI->returnInArg(tf, needsThis); -} - /** * Gets vendor-specific type mangling for C++ ABI. * Params: @@ -219,16 +220,29 @@ bool Target::isReturnOnStack(TypeFunction *tf, bool needsThis) { * null if unhandled */ const char *Target::cppTypeMangle(Type *t) { - if (t->isTypeBasic() && t->ty == Tfloat80) { - // LDC: `long double` on Android/x64 is __float128 and mangled as `g`. - bool isAndroidX64 = - global.params.targetTriple->getEnvironment() == llvm::Triple::Android && - global.params.targetTriple->getArch() == llvm::Triple::x86_64; + if (t->ty == Tfloat80) { + const auto &triple = *global.params.targetTriple; + // `long double` on Android/x64 is __float128 and mangled as `g` + bool isAndroidX64 = triple.getEnvironment() == llvm::Triple::Android && + triple.getArch() == llvm::Triple::x86_64; return isAndroidX64 ? "g" : "e"; } return nullptr; } +TypeTuple *Target::toArgTypes(Type *t) { + const auto &triple = *global.params.targetTriple; + if (triple.getArch() == llvm::Triple::x86) + return ::toArgTypes(t); + if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindows()) + return toArgTypes_sysv_x64(t); + return nullptr; +} + +bool Target::isReturnOnStack(TypeFunction *tf, bool needsThis) { + return gABI->returnInArg(tf, needsThis); +} + Expression *Target::getTargetInfo(const char *name_, const Loc &loc) { const llvm::StringRef name(name_); const auto &triple = *global.params.targetTriple; @@ -275,15 +289,3 @@ Expression *Target::getTargetInfo(const char *name_, const Loc &loc) { return nullptr; } - -TypeTuple *toArgTypes(Type *t); -TypeTuple *toArgTypes_sysv_x64(Type *t); - -TypeTuple *Target::toArgTypes(Type *t) { - const auto &triple = *global.params.targetTriple; - if (triple.getArch() == llvm::Triple::x86) - return ::toArgTypes(t); - if (triple.getArch() == llvm::Triple::x86_64 && !triple.isOSWindows()) - return toArgTypes_sysv_x64(t); - return nullptr; -} From 32805f69be37d2d95f6b006c90c58e38e1e2109a Mon Sep 17 00:00:00 2001 From: Joakim Date: Mon, 10 Dec 2018 23:42:46 +0530 Subject: [PATCH 3/5] Android: make x86/x64 std.math work and cherrypick other upstream fixes. --- runtime/phobos | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/phobos b/runtime/phobos index 59fc794f065..e16ecf941e0 160000 --- a/runtime/phobos +++ b/runtime/phobos @@ -1 +1 @@ -Subproject commit 59fc794f065088522ae73d623d86449e08662742 +Subproject commit e16ecf941e02b9c595beb1990d148609189839d5 From 8eee08b710396956d6fea01315e8ad6403eb660b Mon Sep 17 00:00:00 2001 From: Joakim Date: Tue, 11 Dec 2018 00:31:14 +0530 Subject: [PATCH 4/5] Android: don't use ld.gold by default yet. --- driver/linker-gcc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/driver/linker-gcc.cpp b/driver/linker-gcc.cpp index 17ce1ebbf81..421f5d27789 100644 --- a/driver/linker-gcc.cpp +++ b/driver/linker-gcc.cpp @@ -524,7 +524,9 @@ void ArgsBuilder::build(llvm::StringRef outputPath, void ArgsBuilder::addLinker() { if (!opts::linker.empty()) { args.push_back("-fuse-ld=" + opts::linker); - } else if (global.params.isLinux) { + } else if (global.params.isLinux && + global.params.targetTriple->getEnvironment() != + llvm::Triple::Android) { // Default to ld.gold on Linux due to ld.bfd issues with ThinLTO (see #2278) // and older bfd versions stripping llvm.used symbols (e.g., ModuleInfo // refs) with --gc-sections (see #2870). From 026e912f4d0dbc51a666b478b9933082cfe3fb95 Mon Sep 17 00:00:00 2001 From: Joakim Date: Tue, 11 Dec 2018 20:23:53 +0530 Subject: [PATCH 5/5] Alpine: get Phobos building again by adding attributes it needs to core.sys.posix.sys.stat.stat_t. --- runtime/druntime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/druntime b/runtime/druntime index 8b42b5787aa..e901e9dc3c0 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit 8b42b5787aaeb786ddbc71fdf32e24d263d9cb99 +Subproject commit e901e9dc3c0edcecd9d9b581933fc3c421769421