C undefined behavior fix
<<But even in the case of the compiler reading more (and writing anyway), I think it is the compiler burden to prove that the extra stuff "read" is not observable (in the sense of external
effect) at execution. In a memory-mapped I/O architecture where there is a distinction on external effects between a byte read and a word read (eg: a crash :), the compiler can't get very far IMHO (if it accepts the declaration of course).
Quoted 1 line
Quoted 1 line
External effects are well defined in Ada, see 1.1.3(8) of the RM. The case you mention is not explicitly listed here, so is not an external effect in the Ada sense. The rule is not that anything observable be unaffected (after all performance is observable), but that the six explicit items in section 1.1.3(8) are not observable. Here they are for those who do not have the Ada RM at hand (it is not that Ada is so significant here, as that perhaps we can get some clues for the desirable behavior in GNU C)
9 Any interaction with an external file (see A.7);
10 The execution of certain code_statements (see 13.8); which code_
statements cause external interactions is implementation defined.
11 Any call on an imported subprogram (see Annex B), including any
parameters passed to it;
12 Any result returned or exception propagated from a main
subprogram (see 10.2) or an exported subprogram (see Annex B) to an external caller;
13 Any read or update of an atomic or volatile object (see C.6);
14 The values of imported and exported objects (see Annex B) at the
time of any other interaction with the external environment.
Quoted 6 lines
I think it is the compiler burden to prove that the extra stuff "read" is not observable (in the sense of external
effect) at execution. In a memory-mapped I/O architecture where there is a distinction on external effects between a byte read and a word read (eg: a crash :), the compiler can't get very far IMHO (if it accepts the declaration of course).
In the Linux case mmio isn't a problem. The rules for mmio in the portable code require you use architecture dependant macros (readb etc) and that the mmio space is mapped via ioremap.
Our ioremap/mmio stuff does a whole variety of things on different platforms including simple memory accesses, adding I/O fences, motherboard specific function calls, and tlb bypass.
That side of things is all nicely and cleanly handled.
Quoted 4 lines
In the Linux case mmio isn't a problem. The rules for mmio in the portable code require you use architecture dependant macros (readb etc) and that the mmio space is mapped via ioremap.
I haven't done my homework, but I assume the code behind readb use inline assembly and not C on most platforms?
May be GNU C could get some of the idea behind the Linux macros to define the needed extension (portable within GNU C architectures wherever possible).
Signature · 1 line
Laurent Guerby <[email protected]>
Quoted 2 lines
I haven't done my homework, but I assume the code behind readb use inline assembly and not C on most platforms?
It depends on the platform. Its all nicely wrapped in platform specific macros and using things like volatile to get the right results. Whatever gcc invents we can cope with for a weird port because we can make them asm