Sujet : Re: Joy of this, Joy of that
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.os.linux.miscDate : 26. Nov 2024, 06:29:52
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vi3mcg$3asln$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
186282@ud0s4.net <
186283@ud0s4.net> wrote:
On 11/25/24 4:07 AM, Richard Kettlewell wrote:
"186282@ud0s4.net" <186283@ud0s4.net> writes:
Note though ... almost NO compu-geeks these days
know ASM. As such they will not be enlightened
about 'C' in that fashion. Today's geeks mostly
start with Python and MIGHT go a little further,
likely Rust.
>
Just sayin'
>
Things changed between 1984 and 2024.
>
We Old Guys can kinda look at 'C' and see
the ASM it's going to become. Later gens
do not.
It’s a common mental model for C, but it’s not accurate. The language
spec leaves an awful lot of wiggle room for the generated code to
diverge from the “I can see the assembler” model and compilers take full
advantage of it.
A simple example, based on a historical Linux kernel vulnerability
(CVE-2009-1897):
int f(int *xp) {
int x = *xp;
if(!xp)
return 0;
return x;
}
In the “assembler” model it would compile to something like this:
mov eax,dword ptr [rdi]
cmp rdi,0
jne L1
mov eax,0
L1:
ret
In fact at -O2 the test on xp is optimized out:
mov eax, dword ptr [rdi]
ret
https://godbolt.org/z/caKeTMTxf to play further.
...
That final example shows how tight that particular bit CAN be made.
How the compiler figures that out - NO idea !
Did you miss the forest for the trees. The final example is incorrect
based upon the plain meaning (albeit incorrect) of the input C source.
The check for a null "xp" value that is present in the C code has
disappeared in the output Assembly. The f() function has become
f(int *xp) { return *xp; }. Zero will only return from it when what xp
points at contains zero.
Granted, the C code is also wrong, in that "xp" is dereferenced before
it is checked to see if is null.
How the compiler 'figure[ed] that out' is that the C standard says
dereferencing a null pointer is undefined. So the compiler writers
decided that if the author wrote the dereference, they were also
asserting that "xp" would never be null at that point in their code.
Therefore there was no need to check for "xp" being null on the next
line, as it can't be null there, because the programmer already said it
was not null by dereferencing it on the prior line (because the
programmer should know not to do that). And the optimizer removed the
entire if statement as dead code that can never execute.
Date | Sujet | # | | Auteur |
19 Nov 24 | Joy of this, Joy of that | 806 | | root |
20 Nov 24 |  Re: Joy of this, Joy of that | 4 | | Lawrence D'Oliveiro |
20 Nov 24 |   Re: Joy of this, Joy of that | 3 | | root |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | rbowman |
20 Nov 24 |  Re: Joy of this, Joy of that | 801 | | 186282@ud0s4.net |
20 Nov 24 |   Re: Joy of this, Joy of that | 193 | | Rich |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
21 Nov 24 |    Re: Joy of this, Joy of that | 191 | | 186282@ud0s4.net |
21 Nov 24 |     Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
14 Jan 25 |      Re: Joy of this, Joy of that | 1 | | Bozo User |
21 Nov 24 |     Re: Joy of this, Joy of that | 187 | | The Natural Philosopher |
22 Nov 24 |      Re: Joy of this, Joy of that | 186 | | Don_from_AZ |
22 Nov 24 |       Re: Joy of this, Joy of that | 185 | | Lawrence D'Oliveiro |
23 Nov 24 |        Re: Joy of this, Joy of that | 184 | | 186282@ud0s4.net |
23 Nov 24 |         Re: Joy of this, Joy of that | 5 | | Lawrence D'Oliveiro |
24 Nov 24 |          Re: Joy of this, Joy of that | 4 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
24 Nov 24 |            Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 1 | | rbowman |
23 Nov 24 |         Re: Joy of this, Joy of that | 178 | | The Natural Philosopher |
23 Nov 24 |          Re: Joy of this, Joy of that | 1 | | rbowman |
23 Nov 24 |          Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
24 Nov 24 |          Re: Joy of this, Joy of that | 174 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 1 | | rbowman |
24 Nov 24 |           Re: Joy of this, Joy of that | 172 | | Rich |
24 Nov 24 |            Re: Joy of this, Joy of that | 168 | | The Natural Philosopher |
24 Nov 24 |             Re: Joy of this, Joy of that | 159 | | Rich |
24 Nov 24 |              Re: Joy of this, Joy of that | 158 | | D |
25 Nov 24 |               Re: Joy of this, Joy of that | 157 | | rbowman |
25 Nov 24 |                Re: Joy of this, Joy of that | 156 | | D |
25 Nov 24 |                 Re: Joy of this, Joy of that | 155 | | The Natural Philosopher |
25 Nov 24 |                  Re: Joy of this, Joy of that | 15 | | D |
26 Nov 24 |                   Re: Joy of this, Joy of that | 14 | | rbowman |
26 Nov 24 |                    Re: Joy of this, Joy of that | 1 | | D |
26 Nov 24 |                    Re: Joy of this, Joy of that | 12 | | Pancho |
26 Nov 24 |                     Re: Joy of this, Joy of that | 11 | | Rich |
26 Nov 24 |                      Re: Joy of this, Joy of that | 2 | | Chris Ahlstrom |
27 Nov 24 |                       Re: Joy of this, Joy of that | 1 | | Pancho |
26 Nov 24 |                      Re: Joy of this, Joy of that | 8 | | rbowman |
26 Nov 24 |                       Re: Joy of this, Joy of that | 4 | | D |
27 Nov 24 |                        Re: Joy of this, Joy of that | 1 | | Rich |
27 Nov 24 |                        Re: Joy of this, Joy of that | 2 | | rbowman |
27 Nov 24 |                         Re: Joy of this, Joy of that | 1 | | D |
27 Nov 24 |                       Re: Joy of this, Joy of that | 3 | | The Natural Philosopher |
27 Nov 24 |                        Re: Joy of this, Joy of that | 2 | | rbowman |
28 Nov 24 |                         Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
25 Nov 24 |                  Re: Joy of this, Joy of that | 139 | | Lawrence D'Oliveiro |
27 Nov 24 |                   Re: Joy of this, Joy of that | 138 | | 186282@ud0s4.net |
27 Nov 24 |                    Re: Joy of this, Joy of that | 137 | | Lawrence D'Oliveiro |
28 Nov 24 |                     Re: Joy of this, Joy of that | 136 | | 186282@ud0s4.net |
28 Nov 24 |                      Re: Joy of this, Joy of that | 133 | | rbowman |
28 Nov 24 |                       Re: Joy of this, Joy of that | 132 | | 186282@ud0s4.net |
28 Nov 24 |                        Re: Joy of this, Joy of that | 3 | | rbowman |
29 Nov 24 |                         Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
29 Nov 24 |                          Re: Joy of this, Joy of that | 1 | | rbowman |
28 Nov 24 |                        Re: Joy of this, Joy of that | 128 | | Lawrence D'Oliveiro |
29 Nov 24 |                         Re: Joy of this, Joy of that | 127 | | 186282@ud0s4.net |
29 Nov 24 |                          Re: Joy of this, Joy of that | 116 | | rbowman |
30 Nov 24 |                           Re: Joy of this, Joy of that | 115 | | 186282@ud0s4.net |
30 Nov 24 |                            Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
30 Nov 24 |                            Re: Joy of this, Joy of that | 113 | | rbowman |
30 Nov 24 |                             Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
1 Dec 24 |                              Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
1 Dec 24 |                             Re: Joy of this, Joy of that | 110 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 5 | | The Natural Philosopher |
1 Dec 24 |                               Re: Joy of this, Joy of that | 2 | | Rich |
3 Dec 24 |                                Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | D |
2 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
3 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 102 | | rbowman |
3 Dec 24 |                               Re: Joy of this, Joy of that | 101 | | 186282@ud0s4.net |
3 Dec 24 |                                Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
3 Dec 24 |                                 Re: Joy of this, Joy of that | 1 | | rbowman |
3 Dec 24 |                                Re: Joy of this, Joy of that | 98 | | rbowman |
5 Dec 24 |                                 Re: Joy of this, Joy of that | 97 | | 186282@ud0s4.net |
5 Dec 24 |                                  Re: Joy of this, Joy of that | 92 | | D |
6 Dec 24 |                                   Re: Joy of this, Joy of that | 91 | | 186282@ud0s4.net |
6 Dec 24 |                                    Re: Joy of this, Joy of that | 37 | | rbowman |
6 Dec 24 |                                     Re: Joy of this, Joy of that | 34 | | D |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
7 Dec 24 |                                       Re: Joy of this, Joy of that | 1 | | D |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 17 | | 186282@ud0s4.net |
7 Dec 24 |                                       Re: Joy of this, Joy of that | 16 | | D |
7 Dec 24 |                                        Re: Joy of this, Joy of that | 14 | | Rich |
7 Dec 24 |                                         Re: Joy of this, Joy of that | 13 | | D |
7 Dec 24 |                                          Re: Joy of this, Joy of that | 12 | | Rich |
7 Dec 24 |                                           Re: Joy of this, Joy of that | 10 | | D |
8 Dec 24 |                                            Re: Joy of this, Joy of that | 7 | | Rich |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 5 | | rbowman |
8 Dec 24 |                                              Re: Joy of this, Joy of that | 4 | | Rich |
8 Dec 24 |                                               Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
9 Dec 24 |                                                Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
8 Dec 24 |                                               Re: Joy of this, Joy of that | 1 | | rbowman |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 1 | | D |
8 Dec 24 |                                            Re: Joy of this, Joy of that | 2 | | Robert Riches |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 1 | | D |
7 Dec 24 |                                           Re: Joy of this, Joy of that | 1 | | D |
8 Dec 24 |                                        Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 14 | | D |
7 Dec 24 |                                     Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
6 Dec 24 |                                    Re: Joy of this, Joy of that | 53 | | D |
5 Dec 24 |                                  Re: Joy of this, Joy of that | 4 | | Lawrence D'Oliveiro |
29 Nov 24 |                          Re: Joy of this, Joy of that | 10 | | Lawrence D'Oliveiro |
28 Nov 24 |                      Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
25 Nov 24 |             Re: Joy of this, Joy of that | 8 | | vallor |
24 Nov 24 |            Re: Joy of this, Joy of that | 3 | | D |
24 Nov 24 |          Re: Joy of this, Joy of that | 1 | | Rich |
21 Nov 24 |     Re: Joy of this, Joy of that | 1 | | Rich |
20 Nov 24 |   Re: Joy of this, Joy of that | 606 | | John Ames |
20 Nov 24 |   Re: Joy of this, Joy of that | 1 | | rbowman |