OttyLab / BitZenyAndroidMiningLibrary

9 stars 5 forks source link

x86 crashes #29

Open OttyLab opened 6 years ago

OttyLab commented 6 years ago
07-04 13:50:24.641 15470-15470/com.example.ottylab.bitzenyminer E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.example.ottylab.bitzenyminer, PID: 15470
                                                                                  java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.example.ottylab.bitzenyminer-1/lib/x86/libbitzenymininglibrary.so: has text relocations
                                                                                      at java.lang.Runtime.loadLibrary0(Runtime.java:989)
                                                                                      at java.lang.System.loadLibrary(System.java:1530)
                                                                                      at com.example.ottylab.bitzenymininglibrary.BitZenyMiningLibrary.<clinit>(BitZenyMiningLibrary.java:11)
                                                                                      at com.example.ottylab.bitzenyminer.MainActivity.onCreate(MainActivity.java:70)
                                                                                      at android.app.Activity.performCreate(Activity.java:6679)
                                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
OttyLab commented 6 years ago

Currently, x86 library includes TEXTREL entry in it. From Android API23, TEXTREL is prohibited and crash happens.

To fix this issue, there's 3 approaches

  1. Fix SHA2-x86.S to support position independent code
  2. Do not use SHA2-x86.S
  3. Change target API to 22 (lollipop)

I'll try 1. first.

OttyLab commented 6 years ago

sha2-x86.S includes .data like this;

    .data
    .p2align 7
sha256_4h:
    .long 0x6a09e667, 0x6a09e667, 0x6a09e667, 0x6a09e667
    .long 0xbb67ae85, 0xbb67ae85, 0xbb67ae85, 0xbb67ae85
    .long 0x3c6ef372, 0x3c6ef372, 0x3c6ef372, 0x3c6ef372
    .long 0xa54ff53a, 0xa54ff53a, 0xa54ff53a, 0xa54ff53a
    .long 0x510e527f, 0x510e527f, 0x510e527f, 0x510e527f
    .long 0x9b05688c, 0x9b05688c, 0x9b05688c, 0x9b05688c
    .long 0x1f83d9ab, 0x1f83d9ab, 0x1f83d9ab, 0x1f83d9ab
    .long 0x5be0cd19, 0x5be0cd19, 0x5be0cd19, 0x5be0cd19

Accessing .data code will produce TEXTREL and Android OS refuses to load.

As a fix, I propose that pushing all data into stack on the exposed function call, then popping all data on return.

OttyLab commented 6 years ago

@cryptozeny

master branch merges a workaround for x86. If you have time, could you try it ? (git submodule deinit is required, I suppose)

In this workaround, sha2-x86.S is not used (approach 2.). yescrypt does not use this, so there's no performance impact on bitzeny mining.

Fixing the assembly code would take much time. When I have time, I'll try.

cryptozeny commented 6 years ago

great! i will try it sooner. now i am upgradig cpuminer yescrypt0.5 to yesPower0.5. it boosts hashrate about 3~10%. could you update the cpuminer after its upgrading? 😅

OttyLab commented 6 years ago

@cryptozeny

Of course. Which code base can I use?

(At least, I need to change the code base from https://github.com/bitzeny/cpuminer to https://github.com/BitzenyCoreDevelopers/cpuminer 😄 )

OttyLab commented 6 years ago

@cryptozeny

I've updated the assembly code and master branch fixes the x86 issue. If you find some issue, please let me know.

(I must admit that the assembly code is not efficient because it needs to push some values to the stack and it would affect performance.)

OttyLab commented 6 years ago

32 replaces the cpuminer library

cryptozeny commented 6 years ago

sorry for late answer 😅 now i am working on cpuminer-yesPower and its almost done. it boosts 2~10% hash. currently it based on macchky's one. i think its not so far from yours. can it be merged into this app?

cryptozeny commented 6 years ago

sadly new yespower doesn't support 32bit arv7l (no neon arm), however the dev of yespower said it will be supported next release. also my cpuminer support both of yespower and old yescrypt.

cryptozeny commented 6 years ago

https://gist.github.com/cryptozeny/a249d37066fd84b15b3dc1273558520e

and it supports also another coin such as yenten, koto, wavi using yescrypt.