ragg2 failing to assemble ARM code
Author: davidgivenCreated Mar 17, 2026Updated Aug 24, 2026
Environment
Tue 17 Mar 21:30:16 CET 2026
radare2 6.1.1 +1 abi:72 @ linux-x86_64
birth: git.6.1.1 2026-03-01__23:00:28
commit: 2a980007f585442dbe8d9e2f580b6f520e00a042
options: gpl -O? cs:5 cl:2 make
Linux x86_64Description
Trying to use ragg2 to assemble a small egg program for ARM produces code which fails to assemble.
Test
Here's my test program:
printf@fastcall(0x1fa0b4)
main@global(0,16) {
printf("fnord\n");
}And here's the output. 16-bit mode:
$ ragg2 -a arm -b 16 dumper.r
ERROR: Cannot assemble 'push {fp,lr}' at line 1
ERROR: r_asm_assemble has failed push {fp,lr}
.global main
main:
push {fp,lr}
add fp, sp, $4
sub sp, 32
# rcc_fun 1 (printf)
# encode filtered string (fnord\n) (printf)
add pc, 4
.string "fnord\n"
.fill 1, 1, 0
sub r0, pc, 16
str r0, [sp, 7]
# call in egg->lang.mode 0
ldr r0, [sp, 7]
bl printf
add sp, fp, 32
pop {fp,pc}
ERROR: r_egg_assemble: invalid assembly32-bit mode:
$ ragg2 -a arm -b 32 dumper.r
ERROR: Cannot assemble 'push {fp,lr}' at line 1
ERROR: r_asm_assemble has failed push {fp,lr}
.global main
main:
push {fp,lr}
add fp, sp, $4
sub sp, 32
# rcc_fun 1 (printf)
# encode filtered string (fnord\n) (printf)
add pc, 4
.string "fnord\n"
.fill 1, 1, 0
sub r0, pc, 16
str r0, [sp, 7]
# call in egg->lang.mode 0
ldr r0, [sp, 7]
bl printf
add sp, fp, 32
pop {fp,pc}
ERROR: r_egg_assemble: invalid assemblyAnd 64-bit mode:
$ ragg2 -a arm -b 64 dumper.r
ERROR: Cannot assemble 'add pc, 4' at line 5
ERROR: r_asm_assemble has failed
.global main
main:
add x29, sp, 8
sub sp, sp, 32
# rcc_fun 1 (printf)
# encode filtered string (fnord\n) (printf)
add pc, 4
.string "fnord
"
.fill 1, 1, 0
sub x0, pc, 16
str x0, [sp, 7]
# call in egg->lang.mode 0
ldr x0, [sp, 7]
bl printf
add sp, fp, 32
ERROR: r_egg_assemble: invalid assemblyThere are some bad instructions (the wrong instructions for the given mode being emitted?), but also that offset of 7 for the temporary variable is very wrong.
Source: radareorg/radare2