m8pple / arch2-2019-cw

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gcc compiler for MIPS relying on undefined behavior?

MarcoSelvatici opened this issue · comments

Is it possible that the gcc compiler for mips produces binaries that rely on undefined behaviors? I.e. can we trust that a code compiled from C will for sure have to run fine on a correct simulator ("run fine" means give same result of that the C code gives when compiled for x86)?

That is because we have a C compiled code that runs fine on some simulators, while doesn't on some others. Therefore we are unsure whether this could be due to different implementations of undefined behaviors (or whether the fails are just related to bugs in the simulators).

commented

It shouldn't (although see #46 for a counterexample!). If you find any, please do let me know. The MIPS vs x86 comparison doesn't seem valid since there are ISA differences that result in different behaviours (e.g. handling of division by zero).

The most likely explanation for the differences in behaviour you're seeing does seem to be buggy implementations, but without knowing the specifics I can't rule out the alternative (different, but equally valid, interpretations of undefined behaviours). Note that I cannot test for "correct" implementation-defined behaviour.

Don't forget that you can disassemble your binaries to see exactly what instructions will be executed. I included the %.mips.s rule in my makefile to allow you to do this.