Created
May 1, 2017 10:16
-
-
Save joakim-noah/d25c3b9198ba5544bf816726224ada9d to your computer and use it in GitHub Desktop.
LDC for native Android/ARM, applied to the release-1.2.x branch 2.072
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gen/inlineir.cpp b/gen/inlineir.cpp | |
index 66fac9a8..773728dc 100644 | |
--- a/gen/inlineir.cpp | |
+++ b/gen/inlineir.cpp | |
@@ -55,7 +55,9 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl, | |
// always inlined, this name does not escape the current compiled module; not | |
// even at -O0. | |
static size_t namecounter = 0; | |
- std::string mangled_name = "inline.ir." + std::to_string(namecounter++); | |
+ std::ostringstream os; | |
+ os << namecounter++; | |
+ std::string mangled_name = "inline.ir." + os.str(); | |
TemplateInstance *tinst = fdecl->parent->isTemplateInstance(); | |
assert(tinst); | |
diff --git a/gen/mangling.cpp b/gen/mangling.cpp | |
index ef312009..e7fe0165 100644 | |
--- a/gen/mangling.cpp | |
+++ b/gen/mangling.cpp | |
@@ -60,18 +60,26 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) { | |
if (auto packages = moddecl->packages) { | |
for (size_t i = 0; i < packages->dim; ++i) { | |
llvm::StringRef str = (*packages)[i]->toChars(); | |
- ret += std::to_string(str.size()); | |
+ std::ostringstream os; | |
+ os << str.size(); | |
+ ret += os.str(); | |
ret += str; | |
} | |
} | |
llvm::StringRef str = moddecl->id->toChars(); | |
- ret += std::to_string(str.size()); | |
+ std::ostringstream os; | |
+ os << str.size(); | |
+ ret += os.str(); | |
ret += str; | |
} | |
// source line number | |
- auto lineNo = std::to_string(symb->loc.linnum); | |
- ret += std::to_string(lineNo.size()+1); | |
+ std::ostringstream os; | |
+ os << symb->loc.linnum; | |
+ auto lineNo = os.str(); | |
+ std::ostringstream os2; | |
+ os2 << lineNo.size()+1; | |
+ ret += os2.str(); | |
ret += 'L'; | |
ret += lineNo; | |
@@ -83,13 +91,17 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) { | |
// top aggregate | |
if (auto agg = symb->isMember()) { | |
llvm::StringRef topaggr = agg->ident->toChars(); | |
- ret += std::to_string(topaggr.size()); | |
+ std::ostringstream os; | |
+ os << topaggr.size(); | |
+ ret += os.str(); | |
ret += topaggr; | |
} | |
// identifier | |
llvm::StringRef identifier = symb->toChars(); | |
- ret += std::to_string(identifier.size()); | |
+ std::ostringstream os3; | |
+ os3 << identifier.size(); | |
+ ret += os3.str(); | |
ret += identifier; | |
return ret; | |
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt | |
index 502ec0ff..cefdf192 100644 | |
--- a/runtime/CMakeLists.txt | |
+++ b/runtime/CMakeLists.txt | |
@@ -67,6 +67,7 @@ file(GLOB_RECURSE DRUNTIME_D_GCSTUB ${RUNTIME_DIR}/src/gcstub/*.d) | |
list(REMOVE_ITEM DRUNTIME_D ${DRUNTIME_D_GCSTUB}) | |
# remove some modules in rt/ | |
list(REMOVE_ITEM DRUNTIME_D | |
+ ${RUNTIME_DIR}/src/core/stdc/tgmath.d | |
${RUNTIME_DIR}/src/rt/alloca.d | |
${RUNTIME_DIR}/src/rt/deh.d | |
${RUNTIME_DIR}/src/rt/deh_win32.d | |
@@ -495,7 +496,9 @@ include(profile-rt/DefineBuildProfileRT.cmake) | |
# Set up build targets. | |
# | |
-set(RT_CFLAGS "") | |
+set(RT_CFLAGS "-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security") | |
+set(RT_LDFLAGS "-Wl,-z,nocopyreloc;-lgcc;-target;armv7-none-linux-androideabi;-no-canonical-prefixes;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-mthumb;-Wl,--export-dynamic;-lc;-lm") | |
+set(TEST_SO_LDFLAGS "-Wl,-soname,libnative-activity${name_suffix}.so;-shared;-lgcc;-no-canonical-prefixes;-target;armv7-none-linux-androideabi;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-mthumb;-llog;-landroid;-lEGL;-lGLESv1_CM;-lc;-lm") | |
# This is a bit of a mess as we need to join the two libraries together on | |
# OS X before installing them. After this has run, LIBS_TO_INSTALL contains | |
@@ -661,6 +664,62 @@ macro(build_test_runner name_suffix path_suffix d_flags c_flags) | |
set_tests_properties(build-phobos2-test-runner${target_suffix} PROPERTIES | |
DEPENDS "build-druntime-ldc-unittest${target_suffix};build-phobos2-ldc-unittest${target_suffix}" | |
) | |
+ | |
+ set(test_runner_o "") | |
+ set(test_runner ${PROJECT_BINARY_DIR}/test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}) | |
+ set(ANDROID_DIR "${PROJECT_PARENT_DIR}/../android") | |
+ set(test_runner_so ${ANDROID_DIR}/samples/native-activity/libs/armeabi-v7a/libnative-activity${name_suffix}.so) | |
+ set(runner_flags "${flags}") | |
+ if("${flags}" MATCHES "-debug") | |
+ list(APPEND runner_flags -d-debug) | |
+ endif() | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" test_runner_o druntime_bc) | |
+ add_custom_command( | |
+ OUTPUT ${test_runner} | |
+ COMMAND ${CMAKE_C_COMPILER} ${RT_LDFLAGS} ${test_runner_o} | |
+ ${druntime_o} ${DRUNTIME_C} ${DRUNTIME_ASM} ${phobos2_o} ${PHOBOS2_C} | |
+ -o${test_runner} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${test_runner_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ) | |
+ add_custom_target(test-runner${name_suffix} DEPENDS ${test_runner}) | |
+ set(test_runner_apk_o "") | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags};-d-version=apk;-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "-apk${name_suffix}" test_runner_apk_o druntime_bc) | |
+ set(file_apk_o "") | |
+ dc("${PHOBOS2_DIR}/std/file.d" "${flags};-d-version=apk" "${PHOBOS2_DIR}" | |
+ "-apk-unittest${name_suffix}" file_apk_o phobos2_bc) | |
+ set(main_o "") | |
+ dc("${ANDROID_DIR}/samples/native-activity/jni/main.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" main_o druntime_bc) | |
+ set(sensor_o "") | |
+ dc("${ANDROID_DIR}/android/sensor.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" sensor_o druntime_bc) | |
+ string(REPLACE " " ";" RT_CFLAGS${name_suffix} ${RT_CFLAGS}) | |
+ set(android_native_app_glue_o "") | |
+ dc("${ANDROID_DIR}/android_native_app_glue.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" android_native_app_glue_o druntime_bc) | |
+ list(REMOVE_ITEM phobos2_o "${PROJECT_PARENT_DIR}/build/runtime/std/file-unittest${name_suffix}.o") | |
+ add_custom_command( | |
+ OUTPUT ${test_runner_so} | |
+ COMMAND ${CMAKE_C_COMPILER} ${TEST_SO_LDFLAGS} | |
+ ${main_o} ${sensor_o} ${test_runner_apk_o} | |
+ ${file_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} ${DRUNTIME_C} ${DRUNTIME_ASM} ${phobos2_o} ${PHOBOS2_C} | |
+ -o${test_runner_so} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${main_o} ${sensor_o} | |
+ ${test_runner_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ${file_apk_o} | |
+ ) | |
+ add_custom_target(test-runner-apk${name_suffix} DEPENDS ${test_runner_so}) | |
endif() | |
endmacro() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment