Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.47 KB | None | 0 0
  1. diff --git a/dmd2/root/port.c b/dmd2/root/port.c
  2. index a2a32cd..02412e7 100644
  3. --- a/dmd2/root/port.c
  4. +++ b/dmd2/root/port.c
  5. @@ -654,10 +654,6 @@ longdouble Port::strtold(const char *p, char **endp)
  6. #if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __NetBSD__ || __DragonFly__ || __HAIKU__
  7.  
  8. #include <math.h>
  9. -#if __linux__
  10. -#include <bits/nan.h>
  11. -#include <bits/mathdef.h>
  12. -#endif
  13. #if __FreeBSD__ && __i386__
  14. #include <ieeefp.h>
  15. #endif
  16. diff --git a/driver/codegenerator.cpp b/driver/codegenerator.cpp
  17. index 2e8c768..92e4c11 100644
  18. --- a/driver/codegenerator.cpp
  19. +++ b/driver/codegenerator.cpp
  20. @@ -81,6 +81,18 @@ void emitSymbolAddrGlobal(llvm::Module &lm, const char *symbolName,
  21. lm, voidPtr, false, llvm::GlobalValue::ExternalLinkage,
  22. llvm::ConstantExpr::getBitCast(targetSymbol, voidPtr), addrName);
  23. }
  24. +void emitSymbolAddrGlobal2(llvm::Module &lm, const char *symbolName,
  25. + const char *dataSection, const char *addrName) {
  26. + llvm::Type *voidPtr =
  27. + llvm::PointerType::get(llvm::Type::getInt8Ty(lm.getContext()), 0);
  28. + auto targetSymbol = new llvm::GlobalVariable(
  29. + lm, voidPtr, false, llvm::GlobalValue::ExternalWeakLinkage, 0,
  30. + addrName);
  31. + auto Symbol = new llvm::GlobalVariable(
  32. + lm, voidPtr, false, llvm::GlobalValue::ExternalLinkage,
  33. + llvm::ConstantExpr::getBitCast(targetSymbol, voidPtr), symbolName);
  34. + Symbol->setSection(dataSection);
  35. +}
  36. }
  37.  
  38. namespace ldc {
  39. @@ -216,6 +228,8 @@ void CodeGenerator::emit(Module *m) {
  40. emitSymbolAddrGlobal(ir_->module, "__bss_start", "_d_execBssBegAddr");
  41. emitSymbolAddrGlobal(ir_->module, "_end", "_d_execBssEndAddr");
  42. }
  43. + emitSymbolAddrGlobal2(ir_->module, "_tlsstart", ".tdata", "_tlsBegAddr");
  44. + emitSymbolAddrGlobal2(ir_->module, "_tlsend", ".tcommon", "_tlsEndAddr");
  45. }
  46.  
  47. finishLLModule(m);
  48. diff --git a/driver/linker.cpp b/driver/linker.cpp
  49. index 3cc1e4a..043df35 100644
  50. --- a/driver/linker.cpp
  51. +++ b/driver/linker.cpp
  52. @@ -165,7 +165,7 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
  53. switch (global.params.targetTriple.getOS()) {
  54. case llvm::Triple::Linux:
  55. addSoname = true;
  56. - args.push_back("-lrt");
  57. + //args.push_back("-lrt");
  58. if (!opts::disableLinkerStripDead) {
  59. args.push_back("-Wl,--gc-sections");
  60. }
  61. @@ -176,7 +176,7 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
  62. case llvm::Triple::OpenBSD:
  63. case llvm::Triple::DragonFly:
  64. addSoname = true;
  65. - args.push_back("-lpthread");
  66. + //args.push_back("-lpthread");
  67. args.push_back("-lm");
  68. break;
  69.  
  70. diff --git a/driver/main.cpp b/driver/main.cpp
  71. index bc6e6c1..1f8b58e 100644
  72. --- a/driver/main.cpp
  73. +++ b/driver/main.cpp
  74. @@ -737,6 +737,8 @@ static void registerPredefinedTargetVersions() {
  75. case llvm::Triple::Linux:
  76. if (global.params.targetTriple.getEnvironment() == llvm::Triple::Android) {
  77. VersionCondition::addPredefinedGlobalIdent("Android");
  78. + VersionCondition::addPredefinedGlobalIdent("linux");
  79. + VersionCondition::addPredefinedGlobalIdent("Posix");
  80. VersionCondition::addPredefinedGlobalIdent("CRuntime_Bionic");
  81. } else {
  82. VersionCondition::addPredefinedGlobalIdent("linux");
  83. diff --git a/driver/targetmachine.cpp b/driver/targetmachine.cpp
  84. index e64efd7..47fadbc 100644
  85. --- a/driver/targetmachine.cpp
  86. +++ b/driver/targetmachine.cpp
  87. @@ -506,6 +506,10 @@ llvm::TargetMachine *createTargetMachine(
  88. relocModel = llvm::Reloc::PIC_;
  89. }
  90.  
  91. + if (triple.getEnvironment() == llvm::Triple::Android) {
  92. + relocModel = llvm::Reloc::PIC_;
  93. + }
  94. +
  95. if (floatABI == FloatABI::Default) {
  96. switch (triple.getArch()) {
  97. default: // X86, ...
  98. diff --git a/gen/abi.cpp b/gen/abi.cpp
  99. index fa24b0a..d42d815 100644
  100. --- a/gen/abi.cpp
  101. +++ b/gen/abi.cpp
  102. @@ -201,7 +201,7 @@ struct UnknownTargetABI : TargetABI {
  103. return (rt->ty == Tstruct || rt->ty == Tsarray);
  104. }
  105.  
  106. - bool passByVal(Type *t) override { return t->toBasetype()->ty == Tstruct; }
  107. + bool passByVal(Type *t) override { return false; }//t->toBasetype()->ty == Tstruct; }
  108.  
  109. void rewriteFunctionType(TypeFunction *t, IrFuncTy &fty) override {
  110. // why?
  111. diff --git a/gen/module.cpp b/gen/module.cpp
  112. index 76c2b0a..04d1706 100644
  113. --- a/gen/module.cpp
  114. +++ b/gen/module.cpp
  115. @@ -935,7 +935,7 @@ static void genModuleInfo(Module *m, bool emitFullModuleInfo) {
  116. b.finalize(moduleInfoSym->getType()->getPointerElementType(), moduleInfoSym);
  117. moduleInfoSym->setLinkage(llvm::GlobalValue::ExternalLinkage);
  118.  
  119. - if (global.params.targetTriple.isOSLinux() || global.params.targetTriple.isOSFreeBSD() ||
  120. + if ((global.params.targetTriple.isOSLinux() && global.params.targetTriple.getEnvironment() != llvm::Triple::Android)|| global.params.targetTriple.isOSFreeBSD() ||
  121. #if LDC_LLVM_VER > 305
  122. global.params.targetTriple.isOSNetBSD() || global.params.targetTriple.isOSOpenBSD() ||
  123. global.params.targetTriple.isOSDragonFly()
  124. diff --git a/gen/runtime.cpp b/gen/runtime.cpp
  125. index 5a32dc3..68497b0 100644
  126. --- a/gen/runtime.cpp
  127. +++ b/gen/runtime.cpp
  128. @@ -652,7 +652,7 @@ static void buildRuntimeModule() {
  129. {objectTy});
  130.  
  131. // void _d_dso_registry(CompilerDSOData* data)
  132. - if (global.params.targetTriple.isOSLinux() || global.params.targetTriple.isOSFreeBSD() ||
  133. + if ((global.params.targetTriple.isOSLinux() && global.params.targetTriple.getEnvironment() != llvm::Triple::Android) || global.params.targetTriple.isOSFreeBSD() ||
  134. #if LDC_LLVM_VER > 305
  135. global.params.targetTriple.isOSNetBSD() || global.params.targetTriple.isOSOpenBSD() ||
  136. global.params.targetTriple.isOSDragonFly()
  137. diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
  138. index be5d71e..6d3f5e2 100644
  139. --- a/runtime/CMakeLists.txt
  140. +++ b/runtime/CMakeLists.txt
  141. @@ -272,10 +272,23 @@ macro(dc input_d d_flags output_dir output_suffix outlist_o outlist_bc)
  142. set(dc_flags --output-o)
  143. endif()
  144.  
  145. + set(cur_d_flags ${d_flags})
  146. + if("${cur_d_flags}" MATCHES "-release")
  147. + if("${input_d}" MATCHES "std/exception.d")
  148. + list(APPEND cur_d_flags -disable-inlining)
  149. + elseif("${input_d}" MATCHES "std/internal/math/errorfunction.d")
  150. + list(APPEND cur_d_flags -disable-inlining)
  151. + elseif("${input_d}" MATCHES "std/math.d")
  152. + list(APPEND cur_d_flags -disable-inlining)
  153. + elseif("${input_d}" MATCHES "std/random.d")
  154. + string(REPLACE "-O3" "-O0" cur_d_flags "${cur_d_flags}")
  155. + endif()
  156. + endif()
  157. +
  158. add_custom_command(
  159. OUTPUT
  160. ${outfiles}
  161. - COMMAND ${LDC_EXE} ${dc_flags} -c -I${RUNTIME_DIR}/src -I${RUNTIME_DIR}/src/gc ${input_d} -of${output_o} ${d_flags}
  162. + COMMAND ${LDC_EXE} ${dc_flags} -c -I${RUNTIME_DIR}/src -I${RUNTIME_DIR}/src/gc ${input_d} -of${output_o} ${cur_d_flags}
  163. WORKING_DIRECTORY ${PROJECT_PARENT_DIR}
  164. DEPENDS ${input_d}
  165. ${LDC_EXE}
  166. @@ -473,7 +486,9 @@ endmacro()
  167. # Set up build targets.
  168. #
  169.  
  170. -set(RT_CFLAGS "")
  171. +set(RT_CFLAGS "-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -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")
  172. +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")
  173. +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")
  174.  
  175. # This is a bit of a mess as we need to join the two libraries together on
  176. # OS X before installing them. After this has run, LIBS_TO_INSTALL contains
  177. @@ -652,6 +667,12 @@ macro(build_test_runner name_suffix d_flags c_flags)
  178. if(PHOBOS2_DIR)
  179. set(phobos2_o "")
  180. set(phobos2_bc "")
  181. + set(test_runner_o "")
  182. + set(test_runner ${PROJECT_BINARY_DIR}/test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX})
  183. + set(ANDROID_DIR "${PROJECT_PARENT_DIR}/../android")
  184. + set(android_native_app_glue_o "${ANDROID_DIR}/samples/native-activity/android_native_app_glue.o")
  185. + set(test_runner_so ${ANDROID_DIR}/samples/native-activity/libs/armeabi-v7a/libnative-activity${name_suffix}.so)
  186. +
  187. compile_phobos2("${flags}" "-unittest${name_suffix}" "" phobos2_o phobos2_bc)
  188.  
  189. set(phobos2-casm phobos2-ldc-casm${name_suffix})
  190. @@ -666,6 +687,68 @@ macro(build_test_runner name_suffix d_flags c_flags)
  191.  
  192. set_target_properties(${phobos2-casm} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON)
  193. add_custom_target(phobos2-ldc-unittest${name_suffix} DEPENDS ${phobos2_o} ${phobos2-casm})
  194. + set(runner_flags "${flags}")
  195. + if("${flags}" MATCHES "-debug")
  196. + list(APPEND runner_flags -d-debug)
  197. + endif()
  198. + dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags}" "${RUNTIME_DIR}"
  199. + "${name_suffix}" test_runner_o druntime_bc)
  200. + add_custom_command(
  201. + OUTPUT ${test_runner}
  202. + COMMAND ${CMAKE_C_COMPILER} ${RT_LDFLAGS} ${test_runner_o}
  203. + ${druntime_o} ${phobos2_o}
  204. + "${output_path}/lib${druntime-casm}.a"
  205. + "${output_path}/lib${phobos2-casm}.a"
  206. + -o${test_runner}
  207. + WORKING_DIRECTORY ${PROJECT_PARENT_DIR}
  208. + DEPENDS ${CMAKE_C_COMPILER}
  209. + ${test_runner_o}
  210. + ${druntime_o}
  211. + ${druntime-casm}
  212. + ${phobos2_o}
  213. + ${phobos2-casm}
  214. + )
  215. + add_custom_target(test-runner${name_suffix} DEPENDS ${test_runner})
  216. + set(test_runner_apk_o "")
  217. + dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags};-d-version=apk;-I${ANDROID_DIR}" "${RUNTIME_DIR}"
  218. + "-apk${name_suffix}" test_runner_apk_o druntime_bc)
  219. + set(file_apk_o "")
  220. + dc("${PHOBOS2_DIR}/std/file.d" "${flags};-d-version=apk" "${PHOBOS2_DIR}"
  221. + "-apk-unittest${name_suffix}" file_apk_o phobos2_bc)
  222. + set(main_o "")
  223. + dc("${ANDROID_DIR}/samples/native-activity/jni/main.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}"
  224. + "${name_suffix}" main_o druntime_bc)
  225. + set(sensor_o "")
  226. + dc("${ANDROID_DIR}/android/sensor.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}"
  227. + "${name_suffix}" sensor_o druntime_bc)
  228. + string(REPLACE " " ";" RT_CFLAGS${name_suffix} ${RT_CFLAGS})
  229. + add_custom_command(
  230. + OUTPUT ${android_native_app_glue_o}
  231. + COMMAND ${CMAKE_C_COMPILER} ${RT_CFLAGS} -c "${ANDROID_DIR}/samples/native-activity/android_native_app_glue.c" -o ${android_native_app_glue_o}
  232. + WORKING_DIRECTORY ${PROJECT_PARENT_DIR}
  233. + DEPENDS ${CMAKE_C_COMPILER}
  234. + )
  235. + list(REMOVE_ITEM phobos2_o "${PROJECT_PARENT_DIR}/build/runtime/std/file-unittest${name_suffix}.o")
  236. + add_custom_command(
  237. + OUTPUT ${test_runner_so}
  238. + COMMAND ${CMAKE_C_COMPILER} ${TEST_SO_LDFLAGS}
  239. + ${main_o} ${sensor_o} ${test_runner_apk_o}
  240. + ${file_apk_o} ${android_native_app_glue_o}
  241. + ${druntime_o} ${phobos2_o}
  242. + "${output_path}/lib${druntime-casm}.a"
  243. + "${output_path}/lib${phobos2-casm}.a"
  244. + -o${test_runner_so}
  245. + WORKING_DIRECTORY ${PROJECT_PARENT_DIR}
  246. + DEPENDS ${CMAKE_C_COMPILER}
  247. + ${main_o} ${sensor_o}
  248. + ${test_runner_apk_o} ${android_native_app_glue_o}
  249. + ${druntime_o}
  250. + ${druntime-casm}
  251. + ${phobos2_o}
  252. + ${phobos2-casm}
  253. + ${file_apk_o}
  254. + )
  255. + add_custom_target(test-runner-apk${name_suffix} DEPENDS ${test_runner_so})
  256. add_test(build-phobos2-ldc-unittest${name_suffix} "${CMAKE_COMMAND}"
  257. --build ${CMAKE_BINARY_DIR} --target phobos2-ldc-unittest${name_suffix})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement