I do not agree

This is clearly a mistake in interfacing with inline assembly. By explicitly 
ising a dual-register type in the output section of an __asm__ statement, but 
only passing a 32 bit reference, this is a misuse of the inline 
assembly interface guidelines.


The equivalent in C would be to pass a pointer to a 32 bit structure, with a 
cast, to a function accepting a  pointer to a 64 bit structure. Do not expect 
the compiler to fix it.

Regards.


----- Message d'origine ----
De : Andy Polyakov via RT <[email protected]>
À : [email protected]
Cc : [email protected]
Envoyé le : Jeu 8 juillet 2010, 10h 22min 38s
Objet : Re: [openssl.org #2296] misuse of rdtsc and registers in embedded 
assembly language

>> There is a lovely potential register mismatch issue, which can be
>> reproduced easily with the following setup
>>
>> using gcc 3.3.3 (SuSe linux)
>> When compiled with gcc –O0 to gcc –O2, register eax is used
>> When compiled with gcc –O3 and higher, register edx is used
>>
>>        asm volatile("rdtsc":"=A" (tsc));                                     
>>   
>>//<--- BUG HERE
> 
> http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints
>  

>    "A" - The a and d registers, as a pair (for instructions that return 
> half the result in one and half in the other).
> 
> 
> I'm surprised by the difference -O3 makes, I'd have thought for 
> something like this would not change behavior.

It shouldn't. Behaviour change with optimization level is more than
likely a compiler bug. Well, one can argue that "=A"(32-bit) is pushing
the luck with implicit type conversion, but on the other hand the
compiler should have said that it's pushing the luck (e.g. by failing to
compile with internal error), not generated invalid code.

In other words I wouldn't say it's OpenSSL bug, but compiler one. And it
*should* be reported to gcc people. Though it doesn't necessarily mean
that we will refuse to compensate for it. It happened before in
"might-be-pushing-the-luck" situations.

http://cvs.openssl.org/chngview?cn=19745. A.





______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to