Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will gcc work correctly if "+m" is used as an output constraint?

According to the gcc docs on extended assembler:

You should only use read-write operands when the constraints for the operand [...] allow a register.

This seems to be to be pretty unambiguous: You cannot use +m for an output.

However, I've seen it being done a number of times. In fact, Linus Torvalds is on record as saying

The gcc docs are secondary. They're not updated, they aren't correct, they don't reflect reality, and they don't matter. The only correct thing to use is "+m" for things like this

I don't want to use +m if the compiler is going to end up screwing up my code. And even examining the output asm to see if it is working doesn't mean that tomorrow when I change some seemingly unrelated thing it will still work. Or that it will still work when I get the next update to gcc.

If the docs are right and I can't depend on this working correctly, I want to know that so I can pursue other options (most of which are unpleasantly painful). If the docs are wrong, please let me know how to get them corrected.

like image 285
David Wohlferd Avatar asked Mar 23 '13 22:03

David Wohlferd


1 Answers

As it turns out, the problem is the docs (see the email). In case the link dies:

That part of the docs has been wrong for a while. The doc was corrected for 4.8, but it was wrong for earlier versions too.

Since I am using rubenvb's x64 compiler which reports version 4.7.2, that's the version of the docs I was reading. However, the actual code checkin was in 2004, so I'm feeling pretty confident that change is included in the code I'm running.

like image 160
David Wohlferd Avatar answered Oct 31 '22 04:10

David Wohlferd