Log as below. I tried to to --debug, but didn't get much info. Please kindly advise how to proceed.
ubuntu@ $ redex dummy.apk -o output.apk
libredex/DexClass.h:784: void DexMethod::attach_annotation_set(DexAnnotationSet*): assertion `false' failed.
attach_annotation_set failed for method Lcom/twitter/util/di/qualifier/SchedulerType;.<init>
/usr/local/bin/redex-all[0x4b91e8]
/lib/x86_64-linux-gnu/libc.so.6(+0x36cb0)[0x7f0d458dacb0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f0d458dac37]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7f0d458de028]
/usr/local/bin/redex-all[0x4b91c7]
/usr/local/bin/redex-all[0x4c6274]
/usr/local/bin/redex-all[0x4c64bc]
/usr/local/bin/redex-all[0x4ca406]
/usr/local/bin/redex-all[0x549780]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8184)[0x7f0d468ca184]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f0d4599e37d]
Traceback (most recent call last):
File "/usr/local/bin/redex", line 506, in <module>
run_redex(args)
File "/usr/local/bin/redex", line 448, in run_redex
dexen)
File "/usr/local/bin/redex", line 117, in run_pass
raise err
subprocess.CalledProcessError: Command '/usr/local/bin/redex-all --apkdir /tmp/tmpKEZFBr.redex_extracted_apk --outdir /tmp/tmpgEnVZ4.redex_dexen /tmp/tmpgEnVZ4.redex_dexen/dex0/classes.dex /tmp/tmpgEnVZ4.redex_dexen/dex1/classes2.dex /tmp/tmpgEnVZ4.redex_dexen/dex2/classes3.dex /tmp/tmpgEnVZ4.redex_dexen/dex3/classes4.dex /tmp/tmpgEnVZ4.redex_dexen/dex4/classes5.dex /tmp/tmpgEnVZ4.redex_dexen/dex5/classes6.dex /tmp/tmpgEnVZ4.redex_dexen/dex6/classes7.dex /tmp/tmpgEnVZ4.redex_dexen/dex7/classes8.dex /tmp/tmpgEnVZ4.redex_dexen/dex8/classes9.dex /tmp/tmpgEnVZ4.redex_dexen/dex9/classes10.dex /tmp/tmpgEnVZ4.redex_dexen/dex10/classes11.dex /tmp/tmpgEnVZ4.redex_dexen/dex11/classes12.dex /tmp/tmpgEnVZ4.redex_dexen/dex12/classes13.dex /tmp/tmpgEnVZ4.redex_dexen/dex13/classes14.dex /tmp/tmpgEnVZ4.redex_dexen/dex14/classes15.dex /tmp/tmpgEnVZ4.redex_dexen/dex15/classes16.dex /tmp/tmpgEnVZ4.redex_dexen/dex16/classes17.dex /tmp/tmpgEnVZ4.redex_dexen/dex17/classes18.dex /tmp/tmpgEnVZ4.redex_dexen/dex18/classes19.dex /tmp/tmpgEnVZ4.redex_dexen/dex19/classes20.dex /tmp/tmpgEnVZ4.redex_dexen/dex20/classes21.dex /tmp/tmpgEnVZ4.redex_dexen/dex21/classes22.dex /tmp/tmpgEnVZ4.redex_dexen/dex22/classes23.dex /tmp/tmpgEnVZ4.redex_dexen/dex23/classes24.dex /tmp/tmpgEnVZ4.redex_dexen/dex24/classes25.dex /tmp/tmpgEnVZ4.redex_dexen/dex25/classes26.dex /tmp/tmpgEnVZ4.redex_dexen/dex26/classes27.dex /tmp/tmpgEnVZ4.redex_dexen/dex27/classes28.dex /tmp/tmpgEnVZ4.redex_dexen/dex28/classes29.dex /tmp/tmpgEnVZ4.redex_dexen/dex29/classes30.dex /tmp/tmpgEnVZ4.redex_dexen/dex30/classes31.dex /tmp/tmpgEnVZ4.redex_dexen/dex31/classes32.dex /tmp/tmpgEnVZ4.redex_dexen/dex32/classes33.dex /tmp/tmpgEnVZ4.redex_dexen/dex33/classes34.dex /tmp/tmpgEnVZ4.redex_dexen/dex34/classes35.dex /tmp/tmpgEnVZ4.redex_dexen/dex35/classes36.dex /tmp/tmpgEnVZ4.redex_dexen/dex36/classes37.dex /tmp/tmpgEnVZ4.redex_dexen/dex37/classes38.dex /tmp/tmpgEnVZ4.redex_dexen/dex38/classes39.dex /tmp/tmpgEnVZ4.redex_dexen/dex39/classes40.dex /tmp/tmpgEnVZ4.redex_dexen/dex40/classes41.dex /tmp/tmpgEnVZ4.redex_dexen/dex41/classes42.dex /tmp/tmpgEnVZ4.redex_dexen/dex42/classes43.dex /tmp/tmpgEnVZ4.redex_dexen/dex43/classes44.dex /tmp/tmpgEnVZ4.redex_dexen/dex44/classes45.dex /tmp/tmpgEnVZ4.redex_dexen/dex45/classes46.dex /tmp/tmpgEnVZ4.redex_dexen/dex46/classes47.dex /tmp/tmpgEnVZ4.redex_dexen/dex47/classes48.dex /tmp/tmpgEnVZ4.redex_dexen/dex48/classes49.dex /tmp/tmpgEnVZ4.redex_dexen/dex49/classes50.dex /tmp/tmpgEnVZ4.redex_dexen/dex50/classes51.dex /tmp/tmpgEnVZ4.redex_dexen/dex51/classes52.dex /tmp/tmpgEnVZ4.redex_dexen/dex52/classes53.dex /tmp/tmpgEnVZ4.redex_dexen/dex53/classes54.dex /tmp/tmpgEnVZ4.redex_dexen/dex54/classes55.dex /tmp/tmpgEnVZ4.redex_dexen/dex55/classes56.dex /tmp/tmpgEnVZ4.redex_dexen/dex56/classes57.dex /tmp/tmpgEnVZ4.redex_dexen/dex57/classes58.dex /tmp/tmpgEnVZ4.redex_dexen/dex58/classes59.dex /tmp/tmpgEnVZ4.redex_dexen/dex59/classes60.dex /tmp/tmpgEnVZ4.redex_dexen/dex60/classes61.dex /tmp/tmpgEnVZ4.redex_dexen/dex61/classes62.dex /tmp/tmpgEnVZ4.redex_dexen/dex62/classes63.dex /tmp/tmpgEnVZ4.redex_dexen/dex63/classes64.dex /tmp/tmpgEnVZ4.redex_dexen/dex64/classes65.dex /tmp/tmpgEnVZ4.redex_dexen/dex65/classes66.dex /tmp/tmpgEnVZ4.redex_dexen/dex66/classes67.dex /tmp/tmpgEnVZ4.redex_dexen/dex67/classes68.dex /tmp/tmpgEnVZ4.redex_dexen/dex68/classes69.dex /tmp/tmpgEnVZ4.redex_dexen/dex69/classes70.dex /tmp/tmpgEnVZ4.redex_dexen/dex70/classes71.dex /tmp/tmpgEnVZ4.redex_dexen/dex71/classes72.dex /tmp/tmpgEnVZ4.redex_dexen/dex72/classes73.dex /tmp/tmpgEnVZ4.redex_dexen/dex73/classes74.dex /tmp/tmpgEnVZ4.redex_dexen/dex74/classes75.dex /tmp/tmpgEnVZ4.redex_dexen/dex75/classes76.dex /tmp/tmpgEnVZ4.redex_dexen/dex76/classes77.dex /tmp/tmpgEnVZ4.redex_dexen/dex77/classes78.dex /tmp/tmpgEnVZ4.redex_dexen/dex78/classes79.dex /tmp/tmpgEnVZ4.redex_dexen/dex79/classes80.dex /tmp/tmpgEnVZ4.redex_dexen/dex80/classes81.dex /tmp/tmpgEnVZ4.redex_dexen/dex81/classes82.dex /tmp/tmpgEnVZ4.redex_dexen/dex82/classes83.dex /tmp/tmpgEnVZ4.redex_dexen/dex83/classes84.dex /tmp/tmpgEnVZ4.redex_dexen/dex84/classes85.dex /tmp/tmpgEnVZ4.redex_dexen/dex85/classes86.dex /tmp/tmpgEnVZ4.redex_dexen/dex86/classes87.dex /tmp/tmpgEnVZ4.redex_dexen/dex87/classes88.dex /tmp/tmpgEnVZ4.redex_dexen/dex88/classes89.dex /tmp/tmpgEnVZ4.redex_dexen/dex89/classes90.dex /tmp/tmpgEnVZ4.redex_dexen/dex90/classes91.dex /tmp/tmpgEnVZ4.redex_dexen/dex91/classes92.dex /tmp/tmpgEnVZ4.redex_dexen/dex92/classes93.dex /tmp/tmpgEnVZ4.redex_dexen/dex93/classes94.dex /tmp/tmpgEnVZ4.redex_dexen/dex94/classes95.dex /tmp/tmpgEnVZ4.redex_dexen/dex95/classes96.dex /tmp/tmpgEnVZ4.redex_dexen/dex96/classes97.dex /tmp/tmpgEnVZ4.redex_dexen/dex97/classes98.dex /tmp/tmpgEnVZ4.redex_dexen/dex98/classes99.dex /tmp/tmpgEnVZ4.redex_dexen/dex99/classes100.dex /tmp/tmpgEnVZ4.redex_dexen/dex100/classes101.dex /tmp/tmpgEnVZ4.redex_dexen/dex101/classes102.dex /tmp/tmpgEnVZ4.redex_dexen/dex102/classes103.dex /tmp/tmpgEnVZ4.redex_dexen/dex103/classes104.dex /tmp/tmpgEnVZ4.redex_dexen/dex104/classes105.dex /tmp/tmpgEnVZ4.redex_dexen/dex105/classes106.dex /tmp/tmpgEnVZ4.redex_dexen/dex106/classes107.dex /tmp/tmpgEnVZ4.redex_dexen/dex107/classes108.dex /tmp/tmpgEnVZ4.redex_dexen/dex108/classes109.dex /tmp/tmpgEnVZ4.redex_dexen/dex109/classes110.dex /tmp/tmpgEnVZ4.redex_dexen/dex110/classes111.dex /tmp/tmpgEnVZ4.redex_dexen/dex111/classes112.dex /tmp/tmpgEnVZ4.redex_dexen/dex112/classes113.dex /tmp/tmpgEnVZ4.redex_dexen/dex113/classes114.dex /tmp/tmpgEnVZ4.redex_dexen/dex114/classes115.dex /tmp/tmpgEnVZ4.redex_dexen/dex115/classes116.dex /tmp/tmpgEnVZ4.redex_dexen/dex116/classes117.dex /tmp/tmpgEnVZ4.redex_dexen/dex117/classes118.dex /tmp/tmpgEnVZ4.redex_dexen/dex118/classes119.dex /tmp/tmpgEnVZ4.redex_dexen/dex119/classes120.dex /tmp/tmpgEnVZ4.redex_dexen/dex120/classes121.dex /tmp/tmpgEnVZ4.redex_dexen/dex121/classes122.dex /tmp/tmpgEnVZ4.redex_dexen/dex122/classes123.dex /tmp/tmpgEnVZ4.redex_dexen/dex123/classes124.dex /tmp/tmpgEnVZ4.redex_dexen/dex124/classes125.dex /tmp/tmpgEnVZ4.redex_dexen/dex125/classes126.dex /tmp/tmpgEnVZ4.redex_dexen/dex126/classes127.dex /tmp/tmpgEnVZ4.redex_dexen/dex127/classes128.dex /tmp/tmpgEnVZ4.redex_dexen/dex128/classes129.dex /tmp/tmpgEnVZ4.redex_dexen/dex129/classes130.dex /tmp/tmpgEnVZ4.redex_dexen/dex130/classes131.dex /tmp/tmpgEnVZ4.redex_dexen/dex131/classes132.dex /tmp/tmpgEnVZ4.redex_dexen/dex132/classes133.dex /tmp/tmpgEnVZ4.redex_dexen/dex133/classes134.dex /tmp/tmpgEnVZ4.redex_dexen/dex134/classes135.dex /tmp/tmpgEnVZ4.redex_dexen/dex135/classes136.dex /tmp/tmpgEnVZ4.redex_dexen/dex136/classes137.dex /tmp/tmpgEnVZ4.redex_dexen/dex137/classes138.dex /tmp/tmpgEnVZ4.redex_dexen/dex138/classes139.dex /tmp/tmpgEnVZ4.redex_dexen/dex139/classes140.dex /tmp/tmpgEnVZ4.redex_dexen/dex140/classes141.dex /tmp/tmpgEnVZ4.redex_dexen/dex141/classes142.dex /tmp/tmpgEnVZ4.redex_dexen/dex142/classes143.dex /tmp/tmpgEnVZ4.redex_dexen/dex143/classes144.dex /tmp/tmpgEnVZ4.redex_dexen/dex144/classes145.dex /tmp/tmpgEnVZ4.redex_dexen/dex145/classes146.dex /tmp/tmpgEnVZ4.redex_dexen/dex146/classes147.dex /tmp/tmpgEnVZ4.redex_dexen/dex147/classes148.dex /tmp/tmpgEnVZ4.redex_dexen/dex148/classes149.dex /tmp/tmpgEnVZ4.redex_dexen/dex149/classes150.dex /tmp/tmpgEnVZ4.redex_dexen/dex150/classes151.dex /tmp/tmpgEnVZ4.redex_dexen/dex151/classes152.dex /tmp/tmpgEnVZ4.redex_dexen/dex152/classes153.dex' returned non-zero exit status -6
Any way to print a more helpful call stack?
We think this commit https://github.com/facebook/redex/commit/698e8c7884563e51d31861fc168b4cad917b9ed6 may have fixed the issue. Could you please pull and try again?
@justinjhendrick Thanks for the response! I think the error went away a while ago, but I recently ran into similar issues showing a stack like the above. Do you know any way I can expand it for more information?
/tmp/redex.bvFNCz/redex-all[0x4cbfb5]
/tmp/redex.bvFNCz/redex-all[0x4cbfd8]
/lib64/libc.so.6(+0x35250)[0x7f746a514250]
/tmp/redex.bvFNCz/redex-all[0x5746a3]
/tmp/redex.bvFNCz/redex-all[0x573c19]
/tmp/redex.bvFNCz/redex-all[0x573c19]
/tmp/redex.bvFNCz/redex-all[0x575669]
/tmp/redex.bvFNCz/redex-all[0x47fbc4]
/tmp/redex.bvFNCz/redex-all[0x480acc]
/tmp/redex.bvFNCz/redex-all[0x514473]
/tmp/redex.bvFNCz/redex-all[0x413cb0]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f746a500b35]
/tmp/redex.bvFNCz/redex-all[0x416705]
Traceback (most recent call last):
File "/tmp/redex.bvFNCz/redex.py", line 546, in <module>
run_redex(args)
File "/tmp/redex.bvFNCz/redex.py", line 485, in run_redex
debugger)
File "/tmp/redex.bvFNCz/redex.py", line 134, in run_pass
raise err
We have tons of build scripts and I'm not sure which one open source uses. Can you show me redex --help, please?
I'm asking because we recently added a --lldb and --gdb to launch redex-all with a debugger
That won't solve your issue though because it looks like you don't have debug symbols in redex-all for some reason.
Try changing the flags in Makefile.am
AM_CXXFLAGS = --std=gnu++11 -O0 -Wall -g --fno-inline
Great! Definitely more helpful trace than before:
./libredex/VirtualScope.h:243: std::vector<DexMethod*> devirtualize(const SignatureMap&): assertion `scope.methods.size() == 1' failed.
/tmp/redex.2Ep726/redex-all[0x4e4645]
/tmp/redex.2Ep726/redex-all[0x4e4742]
/tmp/redex.2Ep726/redex-all[0x435e2f]
/tmp/redex.2Ep726/redex-all[0x436310]
/tmp/redex.2Ep726/redex-all[0x48ceb5]
/tmp/redex.2Ep726/redex-all[0x48d29d]
/tmp/redex.2Ep726/redex-all[0x547cd9]
/tmp/redex.2Ep726/redex-all[0x40abb2]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f9cd30e2b15]
/tmp/redex.2Ep726/redex-all[0x40c82d]
terminate called after throwing an instance of 'std::runtime_error'
what(): Redex assertion failure
/tmp/redex.2Ep726/redex-all[0x4e4645]
/tmp/redex.2Ep726/redex-all[0x4e4668]
/lib64/libc.so.6(+0x35670)[0x7f9cd30f6670]
/lib64/libc.so.6(gsignal+0x37)[0x7f9cd30f65f7]
/lib64/libc.so.6(abort+0x148)[0x7f9cd30f7ce8]
/lib64/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x165)[0x7f9cd39fb9d5]
/lib64/libstdc++.so.6(+0x5e946)[0x7f9cd39f9946]
/lib64/libstdc++.so.6(+0x5e973)[0x7f9cd39f9973]
/lib64/libstdc++.so.6(+0x5eb93)[0x7f9cd39f9b93]
/tmp/redex.2Ep726/redex-all[0x4e478c]
/tmp/redex.2Ep726/redex-all[0x435e2f]
/tmp/redex.2Ep726/redex-all[0x436310]
/tmp/redex.2Ep726/redex-all[0x48ceb5]
/tmp/redex.2Ep726/redex-all[0x48d29d]
/tmp/redex.2Ep726/redex-all[0x547cd9]
/tmp/redex.2Ep726/redex-all[0x40abb2]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f9cd30e2b15]
/tmp/redex.2Ep726/redex-all[0x40c82d]
which points to https://github.com/facebook/redex/blob/master/libredex/VirtualScope.h#L243 which was from 2b2c6bcdd73280d13e72f27b1e252164970aeaf3, not sure if it has the wrong assumption, or there is something funky with my proguard config.
a bit more context:
./redex input.apk -o output.apk works, but once I added --proguard-config=<some file>, it errors out.
Below is the --help as requested.
root[7]713f94b01f2f(docker) redex # ./redex --help
usage: redex.py [-h] [-o [OUT]] [-j JARPATHS] [--redex-binary [REDEX_BINARY]]
[-c CONFIG] [--sign] [-s [KEYSTORE]] [-a [KEYALIAS]]
[-p [KEYPASS]] [-u] [-w [WARN]] [-d] [-m [PROGUARD_MAP]]
[-q [PRINTSEEDS]] [-P PROGUARD_CONFIGS] [-k [KEEP]]
[-S PASSTHRU] [-J PASSTHRU_JSON] [--lldb] [--gdb]
input_apk
Given an APK, produce a better APK!
positional arguments:
input_apk Input APK file
optional arguments:
-h, --help show this help message and exit
-o [OUT], --out [OUT]
Output APK file name (defaults to redex-out.apk)
-j JARPATHS, --jarpath JARPATHS
Path to dependent library jar file
--redex-binary [REDEX_BINARY]
Path to redex binary
-c CONFIG, --config CONFIG
Configuration file
--sign Sign the apk after optimizing it
-s [KEYSTORE], --keystore [KEYSTORE]
-a [KEYALIAS], --keyalias [KEYALIAS]
-p [KEYPASS], --keypass [KEYPASS]
-u, --unpack-only Unpack the apk and print the unpacked directories,
don't run any redex passes or repack the apk
-w [WARN], --warn [WARN]
Control verbosity of warnings
-d, --debug Unpack the apk and print the redex command line to run
-m [PROGUARD_MAP], --proguard-map [PROGUARD_MAP]
Path to proguard mapping.txt for deobfuscating names
-q [PRINTSEEDS], --printseeds [PRINTSEEDS]
File to print seeds to
-P PROGUARD_CONFIGS, --proguard-config PROGUARD_CONFIGS
Path to proguard config
-k [KEEP], --keep [KEEP]
Path to file containing classes to keep
-S PASSTHRU Arguments passed through to redex
-J PASSTHRU_JSON JSON-formatted arguments passed through to redex
--lldb Run redex binary in lldb
--gdb Run redex binary in gdb
Can confirm that it works with proguard file at e496a998bf37647b01387641fd7cef4dbf97bd65 Feb 1st, so the breaking changes were introduced later.
The assertion looks sane. There should only be one method marked as FINAL, though there may be some mistake in creating the signature map.
Could you open this up in the debugger and see what's in scope.methods?
Thanks for the guidance. We are currently focusing on getting redex shipped with an older release, then plan to come back to debug/fix this issue in order to move forward with the latest changes.
I can run redex on twitter.apk, and twitter doesn't crash! I've updated default.config and it will go up for code review soon but I'll share it with you now, @wisechengyi.
Here's what I'm doing:
1) based on 478b7348d69e21ad0501d15b012d6de88ed3fb5b
2) using config:
{
"redex" : {
"passes" : [
"ReBindRefsPass",
"BridgePass",
"SynthPass",
"FinalInlinePass",
"SimpleInlinePass",
"PeepholePassV2",
"LocalConstantPropagationPass",
"RedundantMoveEliminationPass",
"LocalDcePass",
"RemoveGotosPass",
"DelSuperPass",
"SingleImplPass",
"StaticReloPass",
"ReorderInterfacesPass",
"RemoveEmptyClassesPass",
"ShortenSrcStringsPass"
]
},
"SimpleInlinePass": {
"callee_invoke_direct" : true,
"super_same_class" : true,
"virtual_same_class" : true,
"use_liveness" : true,
"throws": true,
"multiple_callers": true
},
"FinalInlinePass" : {
"propagate_static_finals": true,
"replace_encodable_clinits": true,
"inline_string_fields": true,
"inline_wide_fields": true
},
"RedundantMoveEliminationPass" : {
"eliminate_const_literals": false,
"full_method_analysis": true
}
}
3) invoking like this:
redex -c twitter.config twitter.apk --out twitter-redex.apk `find ~/Downloads/home/yic/ -name '*.txt' | sed 's/^/ -P /g'` --sign
(the find ... sed is to grab all your proguard configs)
You should see some additional dex size wins with this change too!
That's awesome! I was just fiddling with RenameClassesPassV2 then realized the sha we are on does not have that, but now I should be able to build the latest redex and these features. will update once it all works out
@justinjhendrick are you sure it ran with the proguard files and passed? It still crash on me with the same error on sha 478b7348d69e21ad0501d15b012d6de88ed3fb5b
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/redex.grX5XR/redex.py", line 577, in <module>
run_redex(args)
File "/tmp/redex.grX5XR/redex.py", line 514, in run_redex
debugger)
File "/tmp/redex.grX5XR/redex.py", line 160, in run_pass
'by running %(lldb_script_name)s') % script_filenames)
RuntimeError: redex-all crashed with exit code -6! You can re-run it under gdb by running /tmp/redex.grX5XR/redex-gdb-wq2bh5uy.sh or under lldb by running /tmp/redex.grX5XR/redex-lldb-9segme_s.sh
This is the config I ended up having by eliminating failing passes one by one.
{
"redex": {
"passes": [
"ReBindRefsPass",
"BridgePass",
"SynthPass",
"FinalInlinePass",
"LocalDcePass",
"DelSuperPass",
"SingleImplPass",
"StaticReloPass",
"RemoveEmptyClassesPass",
"ShortenSrcStringsPass"
]
},
"FinalInlinePass": {
"propagate_static_finals": true,
"replace_encodable_clinits": true,
"inline_string_fields": true,
"inline_wide_fields": true
},
"keep_annotations": [
"Lcom/twitter/util/annotation/RedexDoNotStrip;"
]
}
Diff from the whole set
index 2b25862..2cb4f8d 100644
--- a/app/twitter/gradle/twitter-redex.json
+++ b/app/twitter/gradle/twitter-redex.json
@@ -5,45 +5,20 @@
"BridgePass",
"SynthPass",
"FinalInlinePass",
- "SimpleInlinePass",
- "PeepholePassV2",
- "LocalConstantPropagationPass",
- "RedundantMoveEliminationPass",
"LocalDcePass",
- "RemoveGotosPass",
"DelSuperPass",
"SingleImplPass",
"StaticReloPass",
- "ReorderInterfacesPass",
"RemoveEmptyClassesPass",
- "ShortenSrcStringsPass",
- "RenameClassesPassV2"
+ "ShortenSrcStringsPass"
]
},
- "SimpleInlinePass": {
- "callee_invoke_direct": true,
- "super_same_class": true,
- "virtual_same_class": true,
- "use_liveness": true,
- "throws": true,
- "multiple_callers": true
- },
"FinalInlinePass": {
"propagate_static_finals": true,
"replace_encodable_clinits": true,
"inline_string_fields": true,
"inline_wide_fields": true
},
- "RedundantMoveEliminationPass": {
- "eliminate_const_literals": false,
- "full_method_analysis": true
- },
- "RenameClassesPassV2": {
- "###": "don't rename classes that have these annotations",
- "dont_rename_annotated": [
- "Lcom/twitter/util/annotation/RedexDoNotStrip;"
- ]
- },
"keep_annotations": [
"Lcom/twitter/util/annotation/RedexDoNotStrip;"
]
The exception you posted isn't the root cause. That's a failure of the python script while handling the exception (smh). Could you scroll up some more and post the root cause, please? (you may need to enable debug info by adding -g in the cpp flags in the makefile)
EDIT: exit code -6 is SIGABRT, so it probably failed an assertion. I assume it's the scope.methods.size() == 1 again.
How exactly are you invoking redex? I'm trying to reproduce your issue.
Ah yes looks like same error, and line number has reflected the changes.
./libredex/VirtualScope.h:441: std::vector<DexMethod*> devirtualize(const SignatureMap&): assertion `scope.methods.size() == 1' failed.
/tmp/redex.CMwTH8/redex-all[0x532435]
/tmp/redex.CMwTH8/redex-all[0x532548]
/tmp/redex.CMwTH8/redex-all[0x43abcf]
/tmp/redex.CMwTH8/redex-all[0x4d16ed]
/tmp/redex.CMwTH8/redex-all[0x4cfc3d]
/tmp/redex.CMwTH8/redex-all[0x4d00f7]
/tmp/redex.CMwTH8/redex-all[0x5a43ab]
/tmp/redex.CMwTH8/redex-all[0x40c702]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa597263f45]
/tmp/redex.CMwTH8/redex-all[0x40f14b]
terminate called after throwing an instance of 'std::runtime_error'
what(): Redex assertion failure
/tmp/redex.CMwTH8/redex-all[0x532435]
/tmp/redex.CMwTH8/redex-all[0x532458]
/lib/x86_64-linux-gnu/libc.so.6(+0x36cb0)[0x7fa597278cb0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7fa597278c37]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7fa59727c028]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x125)[0x7fa597b943e5]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x6a1d6)[0x7fa597b921d6]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x6a221)[0x7fa597b92221]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x6a463)[0x7fa597b92463]
/tmp/redex.CMwTH8/redex-all[0x532598]
/tmp/redex.CMwTH8/redex-all[0x43abcf]
/tmp/redex.CMwTH8/redex-all[0x4d16ed]
/tmp/redex.CMwTH8/redex-all[0x4cfc3d]
/tmp/redex.CMwTH8/redex-all[0x4d00f7]
/tmp/redex.CMwTH8/redex-all[0x5a43ab]
/tmp/redex.CMwTH8/redex-all[0x40c702]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa597263f45]
/tmp/redex.CMwTH8/redex-all[0x40f14b]
Traceback (most recent call last):
File "/tmp/redex.CMwTH8/redex.py", line 147, in run_pass
subprocess.check_call(args, env=env)
File "/usr/lib/python3.4/subprocess.py", line 561, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/redex.CMwTH8/redex-all', '--apkdir', '/tmp/redex.CMwTH8/tmpg72drvpb.redex_extracted_apk', '--outdir', '/tmp/redex.CMwTH8/tmp7vajnbkt.redex_dexen', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/10_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/11_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/12_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/13_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/14_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/15_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/16_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/17_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/18_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/19_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/1_default-options.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/20_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/21_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/22_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/23_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/24_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/25_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/26_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/27_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/28_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/29_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/2_spongycastle-keep.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/30_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/31_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/32_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/33_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/34_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/35_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/36_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/37_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/3_app-options.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/4_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/5_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/6_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/7_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/8_proguard.txt', '--proguard-config=/Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/9_proguard.txt', '/tmp/redex.CMwTH8/tmp7vajnbkt.redex_dexen/dex0/classes.dex', '/tmp/redex.CMwTH8/tmp7vajnbkt.redex_dexen/dex1/classes2.dex', '/tmp/redex.CMwTH8/tmp7vajnbkt.redex_dexen/dex2/classes3.dex', '/tmp/redex.CMwTH8/tmp7vajnbkt.redex_dexen/dex3/classes4.dex']' returned non-zero exit status -6
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/redex.CMwTH8/redex.py", line 577, in <module>
run_redex(args)
File "/tmp/redex.CMwTH8/redex.py", line 514, in run_redex
debugger)
File "/tmp/redex.CMwTH8/redex.py", line 160, in run_pass
'by running %(lldb_script_name)s') % script_filenames)
RuntimeError: redex-all crashed with exit code -6! You can re-run it under gdb by running /tmp/redex.CMwTH8/redex-gdb-2gkx0xjh.sh or under lldb by running /tmp/redex.CMwTH8/redex-lldb-dymtc1wt.sh
Invocation as follows:
./redex /Users/yic/Dropbox/Public/release.apk -o redexed.apk \
`find /Users/yic/ext/workspace/twitter-android/app/twitter/build/defaultRelease/proguard_files/ -name '*.txt' | sed 's/^/ -P /g'`
Edit: sha is recent 478b7348d69e21ad0501d15b012d6de88ed3fb5b
This is so weird. I just did the same thing as you and it doesn't crash. Maybe it's an open source build thing... Let me go build it that way.
It looks like this is only called from SimpleInlinePass and AccessMarkingPass Could you try a config without those two passes for now while I debug this?
I can't repro with the open source build (on my mac) either. Can you investigate a bit more with --lldb and report what you find?
Sorry I should add it is built in a ubuntu 14.04 box. I can give you the docker image if needed. I will try with --lldb as well
--gdb works too, btw
At sha d26015bf8c1048343617c7fcd5fc1e626aaca8f1 on centos7
Breakpoint 1, devirtualize (sig_map=...) at ./libredex/VirtualScope.h:261
261 always_assert(scope.methods.size() == 1);
Missing separate debuginfos, use: debuginfo-install boost-filesystem-1.53.0-26.el7.x86_64 boost-regex-1.53.0-26.el7.x86_64 boost-system-1.53.0-26.el7.x86_64 glibc-2.17-157.el7_3.4.x86_64 jsoncpp-0.10.5-2.el7.x86_64 libicu-50.1.2-15.el7.x86_64 zlib-1.2.7-17.el7.x86_64
(gdb) scope.methods
Undefined command: "scope". Try "help".
(gdb) p scope
$1 = (const VirtualScope &) @0x4228f20: {type = 0x7fffd53791b0, methods = {<std::_Vector_base<std::pair<DexMethod*, VirtualFlags>, std::allocator<std::pair<DexMethod*, VirtualFlags> > >> = {
_M_impl = {<std::allocator<std::pair<DexMethod*, VirtualFlags> >> = {<__gnu_cxx::new_allocator<std::pair<DexMethod*, VirtualFlags> >> = {<No data fields>}, <No data fields>}, _M_start = 0x4228790, _M_finish = 0x42287e0,
_M_end_of_storage = 0x42287e0}}, <No data fields>}, interfaces = {_M_t = {
_M_impl = {<std::allocator<std::_Rb_tree_node<DexType const*> >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<DexType const*> >> = {<No data fields>}, <No data fields>}, _M_key_compare = {<No data fields>}, _M_header = {
_M_color = std::_S_red, _M_parent = 0x0, _M_left = 0x4228f48, _M_right = 0x4228f48}, _M_node_count = 0}}}}
(gdb) p scope.methods
$2 = {<std::_Vector_base<std::pair<DexMethod*, VirtualFlags>, std::allocator<std::pair<DexMethod*, VirtualFlags> > >> = {
_M_impl = {<std::allocator<std::pair<DexMethod*, VirtualFlags> >> = {<__gnu_cxx::new_allocator<std::pair<DexMethod*, VirtualFlags> >> = {<No data fields>}, <No data fields>}, _M_start = 0x4228790, _M_finish = 0x42287e0,
_M_end_of_storage = 0x42287e0}}, <No data fields>}
(gdb) p scope.methods.size()
$3 = 8796088684833
rerun at the same breakpoint:
(gdb) p scope.methods.size()
$13 = 8796088685014
The number seems uninitialized?
Edit:
ran the 3rd time
(gdb) p scope.methods.size()
$2 = 8796088684997
Edit 2:
I am not able to repro the issue on mac with on the same sha.
Did the following to initialize any struct, but still no dice
@@ -98,7 +98,7 @@ using VirtualMethod = std::pair<DexMethod*, VirtualFlags>;
*/
struct VirtualScope {
const DexType* type;
- std::vector<VirtualMethod> methods;
+ std::vector<VirtualMethod> methods = {};
TypeSet interfaces;
};
Not sure what's so different between mac and centos in this particular case.
Looks like a memory corruption or dangling pointer as the container had garbage values.
@thezhangwei, the assertion is from the devirt. Do you have any clue?
Perhaps we are making the wrong assumption about virtual scopes built here.
Would be great to get the apk and config so I can dig a bit more.
Thanks @thezhangwei, i'll make a dockerfile as a reference going forward because platform and build process have been a factor. In the meantime, you can try it out on ubuntu 14.04 at SHA d26015bf8c1048343617c7fcd5fc1e626aaca8f1
apk: https://www.dropbox.com/s/iyxohg7knqmyn0y/release.apk?dl=0
redex config: https://github.com/facebook/redex/blob/master/config/default.config
proguard configs: archive.zip
redex -c default.config input.apk --out output.apk `find <extracted archive> -name '*.txt' | sed 's/^/ -P /g'` --sign
There is a chance you may not hit the issue, so I will follow up with a Dockerfile.
correction:
use the following the config instead to repro:
{
"redex" : {
"passes" : [
"ReBindRefsPass",
"BridgePass",
"SynthPass",
"FinalInlinePass",
"SimpleInlinePass",
"LocalDcePass",
"DelSuperPass",
"SingleImplPass",
"StaticReloPass",
"RemoveEmptyClassesPass",
"ShortenSrcStringsPass"
]
},
"SimpleInlinePass": {
"callee_invoke_direct" : true,
"super_same_class" : true,
"virtual_same_class" : true,
"use_liveness" : true,
"throws": true,
"multiple_callers": true
},
"FinalInlinePass" : {
"propagate_static_finals": true,
"replace_encodable_clinits": true,
"inline_string_fields": true,
"inline_wide_fields": true
},
"RedundantMoveEliminationPass" : {
"eliminate_const_literals": false,
"full_method_analysis": true
}
}
will submit a Dockerfile soon.
Done https://github.com/wisechengyi/redex_repro
Steps are in readme
Hi there, just pinging to see where we are on this or if anything I can help with. thank you
Sorry for the delay. I had to prioritize a few other tasks last week. Will look into this the next few days. :)
no worries thank you :)
Hmm.. similar to what Justin pointed out above, I can't repro on my machine. I will give another try with open source build.
correct, it works for me on mac as well. it only happens with oss build on ubuntu or centos.
Thanks @thezhangwei!
@wisechengyi, did that commit fix it on your end too?
Hey thanks for checking in. Sorry was distracted by other things.
1) This issue per se may be fixed. I'm aiming to verify soon (this weekend hopefully)
2) Although in terms of unblocking us, I am a bit skeptical because there seems to be another exception mentioned at https://github.com/wisechengyi/redex/pull/1#issue-247882459
Yeah I don't have access to a Ubuntu box so I tried to debug in the docker image but was not able to get stack trace there. The new crash seems to be in Inliner. I could dig in more if I can get more debug info on that.
Cherry picked 5f5fb48e79cd249282a5e46131740347b7282aeb into my branch
Getting a different crash, as expected from https://github.com/wisechengyi/redex/pull/1#issue-247882459
Added -rdynamic as suggested, it showed more detail. Does it look like a different issue?
/tmp/redex.2FCFLA/redex-all(_Z15crash_backtracev+0x15)[0x91dcc5]
/tmp/redex.2FCFLA/redex-all(_Z23crash_backtrace_handleri+0x8)[0x91dce8]
/lib/x86_64-linux-gnu/libc.so.6(+0x36cb0)[0x7fe91f0c5cb0]
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner21cross_store_referenceEP9DexMethod+0x269)[0x979c69]
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner12is_inlinableER13InlineContextP9DexMethodS3_+0x1e)[0x97af6e]
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner14inline_calleesEP9DexMethodRKSt6vectorIS1_SaIS1_EE+0x2fe)[0x97b2de]
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner13caller_inlineEP9DexMethodRKSt6vectorIS1_SaIS1_EERSt13unordered_setIS1_St4hashIS1_ESt8equal_toIS1_ES3_E+0x165)[0x97b765]
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner14inline_methodsEv+0x9c)[0x97b83c]
/tmp/redex.2FCFLA/redex-all(_ZN16SimpleInlinePass8run_passERSt6vectorI8DexStoreSaIS1_EER11ConfigFilesR11PassManager+0x150)[0x8be260]
/tmp/redex.2FCFLA/redex-all(_ZN11PassManager10run_passesERSt6vectorI8DexStoreSaIS1_EER11ConfigFiles+0x91b)[0x987ffb]
/tmp/redex.2FCFLA/redex-all(main+0xb25)[0x8084d5]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fe91f0b0f45]
/tmp/redex.2FCFLA/redex-all[0x80aefb]
Traceback (most recent call last):
File "/tmp/redex.2FCFLA/redex.py", line 574, in <module>
run_redex(args)
File "/tmp/redex.2FCFLA/redex.py", line 511, in run_redex
debugger)
File "/tmp/redex.2FCFLA/redex.py", line 160, in run_pass
'by running %(lldb_script_name)s') % script_filenames)
RuntimeError: redex-all crashed with exit code -11! You can re-run it under gdb by running /tmp/redex.2FCFLA/redex-gdb-5IuZrd.sh or under lldb by running /tmp/redex.2FCFLA/redex-lldb-vsetfQ.sh
Thanks for checking the patch.
The new crash happens in SimpleInlinePass. It does seem like a separate issue to me. :)
@wisechengyi To get a more helpful stack crash report, could you recompile redex-all with -O0 option? The crash was from MultiMethodInliner::cross_store_reference, but I'd like to see more clues.
it's already -O0 https://github.com/wisechengyi/redex/blob/debug/Makefile.am#L6
@wisechengyi Ah, thanks for the info. MultiMethodInliner::cross_store_reference has a good amount of chances of nullptr. https://github.com/facebook/redex/blob/master/libredex/InlineHelper.cpp#L531-L582
In the bottom of the crash log, there is a command line that allows you to run with debugger. Can you figure it out which line was the fault?
It did not stop any of the breakpoints I set.
cross_store_reference has the same code in my branch https://github.com/wisechengyi/redex/blob/debug/libredex/InlineHelper.cpp#L535-L586
(gdb) break InlineHelper.cpp:535
Note: breakpoint 2 also set at pc 0x979a00. // first instruction
Breakpoint 31 at 0x979a00: file libredex/InlineHelper.cpp, line 535.
(gdb) break InlineHelper.cpp:586
Note: breakpoints 28, 29, 32 and 33 also set at pc 0x979c34. // last instruction
Breakpoint 35 at 0x979c34: file libredex/InlineHelper.cpp, line 586.
In the stacktrace:
/tmp/redex.2FCFLA/redex-all(_ZN18MultiMethodInliner21cross_store_referenceEP9DexMethod+0x269)[0x979c69], which has a memory location > last instruction.
Is there anything further I can do to remove the compiler optimization?
Sure, you could take "SimpleInlinePass" out of your config file for now while we fix this crash.
Ah. I understand what you meant now, haha. Remove gcc/clang optimization. Hmm... I don't think so.
Too many compilers involved!
I'll take a look at this tomorrow. Have a good evening :)
I don't have a solution yet, but I did find a super annoying bug/feature of automake.
It turns out we weren't actually setting -O0 like we thought...
I found this in the Makefile generated by automake:
CXXFLAGS = -g -O2
...
CXXCOMPILE = $(CXX) ... $(AM_CXXFLAGS) $(CXXFLAGS)
If you put -O0 in AM_CXXFLAGS it would be overridden by CXXFLAGS.
I just put up a diff to fix this that should come to the OSS side soon, but if you want it now, here's all you need: CXXFLAGS = near the top of Makefile.am
Thanks for digging in! Also removing SimpleInlinePass works around the issue for now.