Fixes in html files in 1986/marshall
This includes the compilers.html and index.html file. I also threw in a slight formatting change in the thanks file.
This commit is contained in:
1 parent
75a993e0cd
commit
5931934d8c
6 files changed
+122
-104
No files matched your search
+46
-37
@@ -1,33 +1,35 @@
|
||||
# Conflicting compilers and optimisers that broke this entry in 2023
|
||||
|
||||
As briefly noted in the [index.html](index.html) `gcc` and `clang` caused different
|
||||
problems with this entry depending on the optimiser being enabled or not, where
|
||||
if the optimiser was enabled it would work with one compiler and not the other.
|
||||
But if you then disabled the optimiser the opposite problem would occur: the
|
||||
working compiler would no longer work and the non-functional one would start to
|
||||
work! And then there's the problem of linux versus macOS causing problems.
|
||||
As briefly noted in the [index.html](index.html) `gcc` versus `clang` caused
|
||||
different problems with this entry, depending on the optimiser being enabled or
|
||||
disabled, where if the optimiser was enabled it would work with one compiler but
|
||||
not the other; on the other hand, if you disabled the optimiser the opposite
|
||||
problem would occur: the working compiler would no longer work and the other one
|
||||
would! And then there's the problem of linux versus macOS causing problems.
|
||||
|
||||
The [alternate code](%%REPO_URL%%/1986/marshall/marshall.alt.c) (source code) demonstrates the problem so
|
||||
you can see if your compiler has the problem as described below.
|
||||
Using the [alternate source code](%%REPO_URL%%/1986/marshall/marshall.alt.c)
|
||||
demonstrates the problem so you can see if your compiler has the problem
|
||||
described below.
|
||||
|
||||
In some versions of `gcc` and `clang` (this was first discovered in fedora linux 38)
|
||||
if the compiler was enabled one compiler would generate code that segfaulted but
|
||||
the other one would not. However, when then disabling the optimiser the compiler
|
||||
that had no problem suddenly did and the one that did suddenly did not. But
|
||||
if the optimiser was enabled one compiler would generate code that segfaulted but
|
||||
the other one did not. However, when disabling the optimiser, the compiler
|
||||
that had no problem suddenly _did_ and the one that did suddenly _did not_. But
|
||||
segfaulting was not by any means the only problem.
|
||||
|
||||
Another problem was that depending on the optimiser an infinite loop would be
|
||||
entered. But then removing it would cause other problems as well, including a
|
||||
segfault.
|
||||
segfault!
|
||||
|
||||
It was not only one compiler that dumped core. Both dumped core with other
|
||||
behaviour, depending on what changes in code were made and the optimiser being
|
||||
on or off. `Clang` in macOS also dumped core!
|
||||
behaviour, depending on what changes in code were made, and the optimiser being
|
||||
on or off. `clang` in macOS also dumped core!
|
||||
|
||||
The [marshall.c](%%REPO_URL%%/1986/marshall/marshall.c) has the original fix
|
||||
for `clang` which works with some compilers depending on the optimiser. When we
|
||||
refer to the code below we refer to the alternate code,
|
||||
[marshall.alt.c](%%REPO_URL%%/1986/marshall/marshall.alt.c).
|
||||
for `clang`, which works with some compilers, depending on the optimiser. Below
|
||||
we refer to the [alternate code
|
||||
marshall.alt.c](%%REPO_URL%%/1986/marshall/marshall.alt.c).
|
||||
|
||||
|
||||
## The conflicting compiler problems:
|
||||
|
||||
@@ -36,42 +38,48 @@ the original code.
|
||||
|
||||
### Linux
|
||||
|
||||
With the optimiser disabled `GCC` compiled the code to enter an infinite loop.
|
||||
If the optimiser was enabled it worked fine. But if the optimiser is enabled
|
||||
`clang` generates code that first prints the text twice (it should print it once) and
|
||||
then immediately dumps core!
|
||||
With the optimiser disabled `gcc` compiled the code to enter an infinite loop.
|
||||
If the optimiser was enabled it worked fine, but if the optimiser is enabled
|
||||
`clang` generates code that first prints the text twice (when it should print it
|
||||
only once) and then immediately dumps core!
|
||||
|
||||
But then there's that infinite loop. What happens if we remove it?
|
||||
But then there's that infinite loop. What happens if we fix it?
|
||||
|
||||
Once the loop is removed if we compile with `clang` and the optimiser is disabled
|
||||
Once the loop is removed, if we compile with `clang` and the optimiser is disabled
|
||||
all is okay. If however we compile with `gcc` and the optimiser is disabled the
|
||||
string is printed once and then the program dumps core! Why is this? It is
|
||||
because of the call to `_exit()` (see below).
|
||||
because of the call to the `_exit(2)` syscall (see below).
|
||||
|
||||
`Clang` works fine with the loop removed and the optimiser disabled. If however we
|
||||
enable the optimiser `clang` will generate code that prints the string twice and
|
||||
dumps core just like before! What about the call to `_exit()`?
|
||||
`clang` works fine with the loop removed if the optimiser is disabled. Once we
|
||||
enable it, though, it will generate code that prints the string twice and
|
||||
dumps core, just like before!
|
||||
|
||||
The call was:
|
||||
|
||||
<div id="exit">
|
||||
### What about the call to the `_exit(2)` syscall?
|
||||
</div>
|
||||
|
||||
The call _was_:
|
||||
|
||||
|
||||
``` <!---c-->
|
||||
_exit(argv[(int)*argc-2/cc[1*(int)*argc]|-1<<4]);
|
||||
```
|
||||
|
||||
Changing it to not refer to these variables and just exit 1 and the problems
|
||||
disappear!
|
||||
In the fixed code, these variables are simply commented out so the code does
|
||||
`_exit(1)`.
|
||||
|
||||
|
||||
### macOS
|
||||
|
||||
But then there was macOS which had another problem!
|
||||
Now as for macOS, _another problem_ existed!
|
||||
|
||||
If the infinite loop is not removed/commented out and the optimiser is enabled
|
||||
it works fine but if it's disabled it prints out the string and then enters an
|
||||
infinite loop!
|
||||
If the code that resulted in an infinite loop is _NOT_ commented out _AND_ the
|
||||
optimiser is enabled it works fine; but if it [the optimiser] is disabled, it
|
||||
prints out the string and then enters that infinite loop!
|
||||
|
||||
After we fix the infinite loop if we change the `_exit()` call in macOS and
|
||||
disable the optimiser we might get something like:
|
||||
After we fix the infinite loop issue, if we change the call to the `_exit(2)`
|
||||
syscall in macOS and disable the optimiser we might get something like:
|
||||
|
||||
``` <!---sh-->
|
||||
$ ./marshall
|
||||
@@ -83,7 +91,8 @@ Observe how it doesn't print it twice. But of course it segfaults so it's not
|
||||
right either.
|
||||
|
||||
If the optimiser is enabled, however, we will see that it works fine before the
|
||||
change to `_exit()`.
|
||||
change to the call to the `_exit(2)` syscall.
|
||||
|
||||
|
||||
## Summary
|
||||
|
||||
|
||||
Reference in new issue
Block a user