From a739c85698733ce995b08d94560233b31980739b Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 5 May 2024 09:31:27 -0700 Subject: [PATCH] Fixes in 1986/marshall/compilers.{md,html} --- 1986/marshall/README.md | 3 ++- 1986/marshall/compilers.html | 29 +++++++++++++++-------------- 1986/marshall/compilers.md | 29 +++++++++++++++-------------- 1986/marshall/index.html | 3 ++- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/1986/marshall/README.md b/1986/marshall/README.md index 59c064072..ac2f41510 100644 --- a/1986/marshall/README.md +++ b/1986/marshall/README.md @@ -25,7 +25,8 @@ if nothing else. ## Alternate code: -Due to the different [conflicting problems](compilers.html) with gcc and clang, we +Due to the different [conflicting problems](compilers.html) with `gcc` and +`clang`, we instead offer the problematic code as an alternate version whereas [marshall.c](%%REPO_URL%%/1986/marshall/marshall.c) has both the infinite loop and the complicated arg to `_exit()` commented out, changing the value passed into `_exit()` to `1`. diff --git a/1986/marshall/compilers.html b/1986/marshall/compilers.html index 9968cac27..462d4621f 100644 --- a/1986/marshall/compilers.html +++ b/1986/marshall/compilers.html @@ -378,7 +378,7 @@
As briefly noted in the index.html gcc and clang caused different +
As briefly noted in the 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
@@ -386,7 +386,7 @@ 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.
The alternate code (source code) demonstrates the problem so you can see if your compiler has the problem as described below.
-In some versions of gcc and clang (this was first discovered in fedora linux 38) +
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
@@ -396,25 +396,26 @@ entered. But then removing it would cause other problems as well, including a
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!
-The index.html 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.
+on or off.Clang in macOS also dumped core!
+The 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.
Below we describe the conflicting options that resulted in the need to modify the original code.
With the optimiser disabled GCC compiled the code to enter an infinite loop. -Enabling the optimiser and it worked fine. But if the optimiser is enabled clang -generates code that first prints the text twice (it should print it once) and +
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!
But then there’s that infinite loop. What happens if we remove it?
-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 +
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).
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 +
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()?
The call was:
_exit(argv[(int)*argc-2/cc[1*(int)*argc]|-1<<4]);
@@ -438,7 +439,7 @@ change to _exit().
And that is the tale of a little engine train that
could…eventually! Or perhaps it’s the compilers, optimisers and OSes that
eventually could?
Whichever you wish it to be, it now works with both clang and gcc! Choo choo!
+Whichever you wish it to be, it now works with both clang and cc Choo choo!
Jump to: top