Skip to content

Instantly share code, notes, and snippets.

@abhinav92003
Last active June 1, 2021 17:18
Show Gist options
  • Save abhinav92003/c878379478b6c8ce2ebc50096986a1db to your computer and use it in GitHub Desktop.
Save abhinav92003/c878379478b6c8ce2ebc50096986a1db to your computer and use it in GitHub Desktop.
DynamoRIO/i#4930: unnecessary aflags spills due to wrongly live aflags
before instrumentation:
TAG 0x0000ffff9775db78
+0 L3 @0x0000fffd5782b9e0 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+4 L3 @0x0000fffd57842598 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+8 L3 @0x0000fffd57803c28 d2be0005 movz $0xf000 lsl $0x10 -> %x5
+12 L3 @0x0000fffd57807428 d51b4205 msr %x5 -> %nzcv
+16 L3 @0x0000fffd578422b0 d503201f nop
+20 L3 @0x0000fffd57806590 14000001 b $0x0000ffff9775db90
END 0x0000ffff9775db78
after app2app:
TAG 0x0000000000000000
+0 L3 @0x0000fffd5782b9e0 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+4 L3 @0x0000fffd57842598 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+8 m4 @0x0000fffd57845030 00000000 <label>
+8 L3 @0x0000fffd57803c28 d2be0005 movz $0xf000 lsl $0x10 -> %x5
+12 L3 @0x0000fffd57807428 d51b4205 msr %x5 -> %nzcv
+16 m4 @0x0000fffd57806510 f900a780 str %x0 -> +0x0148(%x28)[8byte]
+20 m4 @0x0000fffd57804578 f900a780 <label>
+20 m4 @0x0000fffd57842b30 d53b4200 mrs %nzcv -> %x0
+24 m4 @0x0000fffd578267f8 f900ab80 str %x0 -> +0x0150(%x28)[8byte] // app2app: spill app aflags
+28 m4 @0x0000fffd578297e0 f900ab80 <label>
+28 m4 @0x0000fffd5782aa40 f940a780 ldr +0x0148(%x28)[8byte] -> %x0
+32 m4 @0x0000fffd57807940 f940a780 <label>
+32 m4 @0x0000fffd57842ab0 d29579a5 movz $0x0000abcd lsl $0x0000000000000000 -> %x5
+36 m4 @0x0000fffd5782d040 d51b4205 msr %x5 -> %nzcv // app2app: write some val to aflags, which is never read, so aflags should be dead and shouldn't need to save in insertion phase
+40 L3 @0x0000fffd578422b0 d503201f nop
+44 m4 @0x0000fffd5782ff28 f900a780 str %x0 -> +0x0148(%x28)[8byte]
+48 m4 @0x0000fffd5782e118 f900a780 <label>
+48 m4 @0x0000fffd57845868 f940ab80 ldr +0x0150(%x28)[8byte] -> %x0
+52 m4 @0x0000fffd57806710 f940ab80 <label>
+52 m4 @0x0000fffd5782d4a8 d51b4200 msr %x0 -> %nzcv // app2app: restore app aflags
+56 m4 @0x0000fffd578279a0 f940a780 ldr +0x0148(%x28)[8byte] -> %x0
+60 m4 @0x0000fffd5782d710 f940a780 <label>
+60 L3 @0x0000fffd57806590 14000001 b $0x0000ffff9775db90
END 0x0000000000000000
after instrumentation:
TAG 0x0000ffff9775db78
+0 m4 @0x0000fffd57827170 d53b4204 mrs %nzcv -> %x4
+4 m4 @0x0000fffd57807b28 f9000380 str %x0 -> (%x28)[8byte]
+8 m4 @0x0000fffd57829b30 f9401f80 ldr +0x38(%x28)[8byte] -> %x0
+12 m4 @0x0000fffd57806ca8 f9001804 str %x4 -> +0x30(%x0)[8byte]
+16 m4 @0x0000fffd57808d40 f9400380 ldr (%x28)[8byte] -> %x0
+20 m4 @0x0000fffd57830cc8 f9400380 <label>
+20 m4 @0x0000fffd57829560 f9401f84 ldr +0x38(%x28)[8byte] -> %x4
+24 m4 @0x0000fffd57846268 f9401884 ldr +0x30(%x4)[8byte] -> %x4
+28 m4 @0x0000fffd57845130 d51b4204 msr %x4 -> %nzcv
+32 m4 @0x0000fffd57807d10 f9401f84 ldr +0x38(%x28)[8byte] -> %x4
+36 m4 @0x0000fffd57806078 f9401884 ldr +0x30(%x4)[8byte] -> %x4
+40 m4 @0x0000fffd57827d88 f9401884 <label>
+40 m4 @0x0000fffd578069c0 d51b4204 msr %x4 -> %nzcv
+44 L3 @0x0000fffd5782b9e0 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+48 L3 @0x0000fffd57842598 d29e22a4 movz $0xf115 lsl $0x00 -> %x4
+52 m4 @0x0000fffd57845030 d51b4204 <label>
+52 L3 @0x0000fffd57803c28 d2be0005 movz $0xf000 lsl $0x10 -> %x5
+56 L3 @0x0000fffd57807428 d51b4205 msr %x5 -> %nzcv
+60 m4 @0x0000fffd57806510 f900a780 str %x0 -> +0x0148(%x28)[8byte]
+64 m4 @0x0000fffd57804578 f900a780 <label>
+64 m4 @0x0000fffd57842b30 d53b4200 mrs %nzcv -> %x0
+68 m4 @0x0000fffd578267f8 f900ab80 str %x0 -> +0x0150(%x28)[8byte] // app2app: spill app aflags
+72 m4 @0x0000fffd578297e0 f900ab80 <label>
+72 m4 @0x0000fffd5782aa40 f940a780 ldr +0x0148(%x28)[8byte] -> %x0
+76 m4 @0x0000fffd57807940 f940a780 <label>
+76 m4 @0x0000fffd57842ab0 d29579a5 movz $0x0000abcd lsl $0x0000000000000000 -> %x5
+80 m4 @0x0000fffd5782d040 d51b4205 msr %x5 -> %nzcv // app2app: write some val to aflags, which is never read, so aflags should be dead and shouldn't need to save in insertion phase
+84 m4 @0x0000fffd57845930 f9000f80 str %x0 -> +0x18(%x28)[8byte]
+88 m4 @0x0000fffd578063a8 f9000f80 <label>
+88 m4 @0x0000fffd578309c8 d53b4200 mrs %nzcv -> %x0
+92 m4 @0x0000fffd5782b3c8 f9000b80 str %x0 -> +0x10(%x28)[8byte] // insertion: save app2app aflags. didn't need to
+96 m4 @0x0000fffd5782aaa8 f9000b80 <label>
+96 m4 @0x0000fffd57828be8 d29579a5 movz $0x0000abcd lsl $0x0000000000000000 -> %x5
+100 m4 @0x0000fffd57807e78 d51b4205 msr %x5 -> %nzcv
+104 m4 @0x0000fffd578300a8 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+108 m4 @0x0000fffd5782c0b0 d51b4200 msr %x0 -> %nzcv
+112 m4 @0x0000fffd57830578 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+116 m4 @0x0000fffd578295e0 f9400f80 <label>
+116 L3 @0x0000fffd578422b0 d503201f nop
+120 m4 @0x0000fffd5782ebd0 f9000f80 str %x0 -> +0x18(%x28)[8byte]
+124 m4 @0x0000fffd57805b28 f9000f80 <label>
+124 m4 @0x0000fffd5782f0a0 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+128 m4 @0x0000fffd57804490 d51b4200 msr %x0 -> %nzcv
+132 m4 @0x0000fffd5782b160 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+136 m4 @0x0000fffd57805e10 f9400f80 <label>
+136 m4 @0x0000fffd5782ff28 f900a780 str %x0 -> +0x0148(%x28)[8byte]
+140 m4 @0x0000fffd5782c598 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+144 m4 @0x0000fffd57842948 d51b4200 msr %x0 -> %nzcv
+148 m4 @0x0000fffd5782e118 d51b4200 <label>
+148 m4 @0x0000fffd57844018 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+152 m4 @0x0000fffd57842498 d51b4200 msr %x0 -> %nzcv
+156 m4 @0x0000fffd57845868 f940ab80 ldr +0x0150(%x28)[8byte] -> %x0
+160 m4 @0x0000fffd578282b8 f9000f80 str %x0 -> +0x18(%x28)[8byte]
+164 m4 @0x0000fffd5782fc40 f9000f80 <label>
+164 m4 @0x0000fffd5782cf58 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+168 m4 @0x0000fffd57844830 d51b4200 msr %x0 -> %nzcv
+172 m4 @0x0000fffd57804e60 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+176 m4 @0x0000fffd57808078 f9400f80 <label>
+176 m4 @0x0000fffd57806710 f9400f80 <label>
+176 m4 @0x0000fffd57807710 f900ab80 str %x0 -> +0x0150(%x28)[8byte]
+180 m4 @0x0000fffd57844898 f900ab80 <label>
+180 m4 @0x0000fffd57804128 f9400b80 ldr +0x10(%x28)[8byte] -> %x0
+184 m4 @0x0000fffd5782cb70 d51b4200 msr %x0 -> %nzcv
+188 m4 @0x0000fffd5782cd58 f940ab80 ldr +0x0150(%x28)[8byte] -> %x0
+192 m4 @0x0000fffd57831400 f940ab80 <label>
+192 m4 @0x0000fffd5782d4a8 d51b4200 msr %x0 -> %nzcv
+196 m4 @0x0000fffd57807aa8 f900ab80 str %x0 -> +0x0150(%x28)[8byte]
+200 m4 @0x0000fffd57844f30 f900ab80 <label>
+200 m4 @0x0000fffd578296e0 d53b4200 mrs %nzcv -> %x0
+204 m4 @0x0000fffd5782b6b0 f9000f80 str %x0 -> +0x18(%x28)[8byte]
+208 m4 @0x0000fffd57843630 f9000f80 <label>
+208 m4 @0x0000fffd57827a20 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+212 m4 @0x0000fffd57844a60 d51b4200 msr %x0 -> %nzcv
+216 m4 @0x0000fffd578279a0 f940a780 ldr +0x0148(%x28)[8byte] -> %x0
+220 m4 @0x0000fffd57845218 f900ab80 str %x0 -> +0x0150(%x28)[8byte]
+224 m4 @0x0000fffd57808e28 f900ab80 <label>
+224 m4 @0x0000fffd57843860 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+228 m4 @0x0000fffd57827920 d51b4200 msr %x0 -> %nzcv
+232 m4 @0x0000fffd5782d710 d51b4200 <label>
+232 m4 @0x0000fffd57828980 f9400f80 ldr +0x18(%x28)[8byte] -> %x0
+236 m4 @0x0000fffd57804228 d51b4200 msr %x0 -> %nzcv
+240 m4 @0x0000fffd57830960 f940ab80 ldr +0x0150(%x28)[8byte] -> %x0
+244 m4 @0x0000fffd57804d78 f940ab80 <label>
+244 L3 @0x0000fffd57806590 14000001 b $0x0000ffff9775db90
END 0x0000ffff9775db78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment