MD5 is always 0000000000000000 on PPC Mac...?


#1

I made a simple example below:

[code]#include <stdio.h>
#include <juce.h>

int main (int argc, char * const argv[])
{
char a[] = “A”;
MD5 mMD5(a, 1);
::printf("%s\n", (const char*)mMD5.toHexString());
return 0;
}[/code]

On Intel-Macs, the result is 7fc56270e7a70fa81a5935b72eacbe29 both with Debug/Release settings.

But the result is not correct when compilied as PPC with Release setting. The result is always 00000000000000000000000000000000 regardless of the value. With Debug setting, the result is correct, it’s the same as Intel-Macs.

I’m using the .xcconfig file comes with juce v1.38.

I saw the source code of MD5 in juce but there seems be no difference between Debug/Release…

Are there any endian issue or am I missing something?

Best regards,
Masa


#2

Ugh! This is a compiler bug - it’s trying too hard to optimise, and putting things into the wrong order, so it’s calculating the result before the work has actually been done…

I’m a bit stumped for a workaround… the problem seems to be mostly in the finish() method, and adding debugging printouts fixes it, but sometimes makes it produce other, random results, depending on where the printfs are. I’ve not found any other tricks that make any difference though.

Apart from turning off optimisation, I’m a bit puzzled by what to do. I guess this is fixed in gcc4.0, which is why it works in the intel builds.


#3

Ahh… maybe we should inform Apple about this thing using Bug Reporter?

There are compiler engineers in Apple and I sent some bug reports regarding compiler. (almost all of them are regarding inline assembly code though)

I will try this, maybe we can modify the optimization flag only for the MD5 source code in Xcode.

Thanks,
Masa


#4

I tried a kin of negative workaround…

By specifying “-O0” option to juce_MD5.cpp, I got the same result on PPC.
(in Xcode, press Command-I on juce_MD5.cpp in the groups and files, then click the “build” tab then write “-O0”)

However, the code is not optimized on both PPC and Intel…

It seems there are no way to specify “GCC_OPTIMIZATION_LEVEL_ppc = 0” for each file.

Masa


#5

It’s a really annoying problem, especially in this file, which you want to be optimised. I tried splitting parts of the code into different functions to try to persuade it not to optimise, but had no luck.


#6