Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecj error: dalvikvm: Abort #18557

Open
hanyman7 opened this issue Nov 22, 2023 · 29 comments · May be fixed by termux/termux-tools#138
Open

ecj error: dalvikvm: Abort #18557

hanyman7 opened this issue Nov 22, 2023 · 29 comments · May be fixed by termux/termux-tools#138
Labels
android-14 inactive No activity in a certain period of time

Comments

@hanyman7
Copy link

A recent software was installed on my Samsung SM-A546U.
I can compile java code using ecj as before.
Additionally, dx --dex output=myclasses.dex
Then either add classes.dex to CLASSPATH or using -cp myclasses.dex Abort(s)

dalvikvm -cp myclasses.dex com.me.HelloWorld
Aborted

added echo statement to dalvikvm

exec /apex/com.android.art/bin/dalvikvm -Xusejit:true -Xnoimage-dex2oat -Djava.io.tmpdir=/data/data/com.termux/files/usr/tmp -cp classes.dex com.me.HelloWorld
Aborted

Interesting that both ecj and dx use same dalvikvm, but difference is that -Xcompiler mode seems to work ??? Help

Please guide me to collect any info requested
Screenshot_20231122_074141_Settings

termux-info.txt

@twaik
Copy link
Member

twaik commented Nov 22, 2023

  1. logcat.
  2. This issue must be posted in termux-packages repo, not in termux-tools.

@hanyman7
Copy link
Author

Yikes, I just noticed that this update took my phone from Android 13 to Android 14 ????

@twaik
Copy link
Member

twaik commented Nov 22, 2023

I think you should just do pkg up, update should fix this.

@hanyman7
Copy link
Author

Thanks for the quick reply, I just tried pkg up and seems like no updates,
All packages are up to date.

@twaik
Copy link
Member

twaik commented Nov 22, 2023

chmod -w /data/data/com.termux/files/usr/share/dex/ecj.jar

@hanyman7
Copy link
Author

Also could you please point me in the right direction to collect logcat data. I don't know how to do it. I tried setting the level to verbose on Termux and got a bunch of output, but honestly don't know what I'm doing, poking in the dark 😏

@hanyman7
Copy link
Author

chmod -w /data/data/com.termux/files/usr/share/dex/ecj.jar

Huh ? How's that supposed to help. I only have a problem with running classes.
ecj and dx have already run. I am now just trying to run a simple class.

Anyway to collect info on the Abort issue ?

@twaik
Copy link
Member

twaik commented Nov 22, 2023

  1. Run logcat -d > log.txt in termux.
  2. Move log.txt to sdcard and pin to post.

@twaik
Copy link
Member

twaik commented Nov 22, 2023

Huh ? How's that supposed to help. I only have a problem with running classes.

#16255

@twaik
Copy link
Member

twaik commented Nov 22, 2023

Any news on this?

@hanyman7
Copy link
Author

  1. Run logcat -d > log.txt in termux.
  2. Move log.txt to sdcard and pin to post.

Thank you 🙏, I collected the data
But don't know how to interpret... Might spend a little time investigating. Seems to complain about lack of image, etc and eventually aborts

@twaik
Copy link
Member

twaik commented Nov 22, 2023

Post it and I will tell you why that happens.

@hanyman7
Copy link
Author

Post it and I will tell you why that happens.

I think you are absolutely right. I read about the issue as you mentioned above. Will take a small break and try to make classes readonly
logcat.txt

@twaik
Copy link
Member

twaik commented Nov 22, 2023

Your error is dalvikvm: Attempt to load writable dex file: /data/data/com.termux/files/home/work/hello2/classes.dex. Make it non-writable too.

@thunder-coding thunder-coding transferred this issue from termux/termux-tools Nov 22, 2023
@hanyman7
Copy link
Author

Your error is dalvikvm: Attempt to load writable dex file: /data/data/com.termux/files/home/work/hello2/classes.dex. Make it non-writable too.

@hanyman7
Copy link
Author

Twaik can't thank you enough for guiding me through this. It worked
👍👍👍

@twaik twaik reopened this Nov 22, 2023
@twaik
Copy link
Member

twaik commented Nov 22, 2023

We should patch ecj to do this automatically.

@hanyman7
Copy link
Author

We should patch ecj to do this automatically.

I also use a copy of Sun's jar tool to produce my jar files. Experimenting now to see if
A. classes within jar r/w matters
B. Jar itself r/w matters
Will comment soon.

Again thanks a million for pointing me in the right direction, I was already going down hell path getting a tar of dalvikvm and bin/lib64/javalib from my Android 13 phone, lol 😂

@hanyman7
Copy link
Author

Ok, I experimented a bit.
If CLASSPATH and/or the -cp argument point to any files that are not write protected, dalvikvm will Abort.
So any .dex or .jar files in -cp or CLASSPATH will do. When a jar/dex file is created the individual write attributes of the elements in the jar/dex file don't matter. The only thing that matters is that the output file or jar and dex as seen by dalvikvm must be read only.

@hanyman7
Copy link
Author

We should patch ecj to do this automatically.

See above, I ran a few tests as I was modifying my build process and I had to ensure that all jar files (which contain .dex files) and individual.dex files that were in -cp argument or CLASSPATH as een by dalvikvm MUST be READ-ONLY.

So I am not sure that ecj is culprit.

dx --dex which used to transcode .class to dex or '.jar files contained .class files' to a dex-output is culprit. This is because it's the only way to prepare an object that is usable by dalvikvm.

One could also include multiple.dex files in a jar and use that in -cp/CLASSPATH but also the jar utility must ensure that the produced output is READ-ONLY. So jar utilities are culprit

I hope this helps.... ecj is only converting .java to .class which are unusable as is.

@twaik
Copy link
Member

twaik commented Nov 24, 2023

Ok, I experimented a bit.

It was no need to do that. #16255

@hanyman7
Copy link
Author

Ok, I experimented a bit.

It was no need to do that. #16255

They are talking about am utility.
In general many users, myself included, have a lot of java code in Termux as well as Java servers. I don't use APKs

So I needed to modify my own java build environment which is a mix of jar and dex files

@twaik
Copy link
Member

twaik commented Nov 24, 2023

Quote:

Android 14 requires that all dynamically loaded dex files are read-only to prevent security issues.

@hanyman7
Copy link
Author

Quote:

Android 14 requires that all dynamically loaded dex files are read-only to prevent security issues.

I agree 100%, but the question is what produces the artifacts that are in -cp or CLASSPATH.
The answer is jar and dx -- dex output=...

@twaik twaik changed the title dalvikvm: Abort ecj error: dalvikvm: Abort Dec 14, 2023
@stale stale bot added the inactive No activity in a certain period of time label Feb 29, 2024
@twaik
Copy link
Member

twaik commented Mar 31, 2024

Ok, now I see that we download .jar and do not build it from source. Maybe we should make it run with openjdk-17? @licy183 @truboxl ?

@twaik
Copy link
Member

twaik commented Oct 9, 2024

That is the problem: https://cs.android.com/android/platform/superproject/+/dd6fde63193fda968440fc0a4cd9ccee5d282ab0:art/runtime/native/dalvik_system_DexFile.cc;l=381

Android checks if current uid is 0 (root), 1000 (system) or 2000 (shell) AND if apk has write access.
Possible solution: make a little library which overrides regular access function which will always report no write access or override regular getuid which will always report 2000 (shell) and put this library to LD_PRELOAD in dalvikvm starting script.

@stale stale bot removed the inactive No activity in a certain period of time label Oct 9, 2024
@twaik
Copy link
Member

twaik commented Oct 10, 2024

@licy183 @truboxl should we create a wrapper script for dalvikvm for overriding W^X behaviour or we should just close the issue?

@twaik
Copy link
Member

twaik commented Oct 10, 2024

Oh, so we should just create a library for that and add it to LD_PRELOAD, right?
@sylirre @Grimler91 @2096779623 pinging you because you commited to the repo.

twaik added a commit to twaik/termux-tools that referenced this issue Oct 22, 2024
twaik added a commit to twaik/termux-tools that referenced this issue Oct 22, 2024
@stale stale bot added the inactive No activity in a certain period of time label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android-14 inactive No activity in a certain period of time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants