So I've been exploring the 12 chapter in the picoCTF primer and suddenly saw difference in my assembly of the program and the picoCTF's in the end of main function, where the stack canary is being checked.
Their is xor rdx,QWORD PTR fs:0x28 and mine is sub rdx,QWORD PTR fs:0x28
I have AMD processor and my assembly uses the sub instruction to check the equality, but in their assembly there is xor. It does the same thing, I understand, but why is it like that? Isn't the xor operation more efficient and is it even because of the processor?
xorinstead ofsubwas a missed-optimization, fixed in GCC10 after I reported it. gcc.gnu.org/bugzilla/show_bug.cgi?id=90568 . (They're not necessarily equal, @TimRoberts, because we're not still using 486 CPUs. Intel since Sandybridge can macro-fusesub/jccinto a single uop, but can't forxor. Recent AMD CPUs can do the same. But yes,subis not worse anywhere.)