Fix 2001/anonymous - it now works!
This was a fun one to figure out. There were a few steps. Amongst them was adding the include for mmap(). Another part that might or might not be relevant was having main() call a new function rather than main() itself. This seemingly solved an infinite recursion call to main() (according to gcc). I changed the third arg in the call to mmap() to be PROT_READ|PROT_WRITE. This might not have been necessary as it might evaluate to 3 which is what it was. I regret that some macros were removed and some formatting was changed. This was not intentional but I want to get the fix in and then I can fix the formatting and macros (or try to - some of it might or might not cause a problem). Note that it will crash on any binary that's not 32-bit/x86. In other words this won't work in macOS unless you have an old enough Mac that supports 32-bit binaries. With gcc (which is clang in macOS so that won't work either) one can do -m32 and that's what is done for anonymous.ten. It probably should be built by default but it's currently not.
This commit is contained in:
1 parent
1685f8e2ee
commit
efdee208a2
5 files changed
+61
-482
No files matched your search
@@ -1030,92 +1030,6 @@ fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing))! :-) ).
|
||||
# 2001
|
||||
|
||||
|
||||
## [2001/anonymous](2001/anonymous/anonymous.c) ([README.md](2001/anonymous/README.md))
|
||||
## STATUS: known bug - please help us fix
|
||||
|
||||
This entry seems to no longer work and we would appreciate any help from anyone
|
||||
who can fix this. [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) has
|
||||
the following hints that might help but he has no system where he could test
|
||||
it. [Yusuke Endoh](/winners.html#Yusuke_Endoh) [wrote a little bit about
|
||||
it](https://mame-github-io.translate.goog/ioccc-ja-spoilers/2001/anonymous.html?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp) that
|
||||
might or might not help but he too could not get it to work.
|
||||
|
||||
Tips from Cody:
|
||||
|
||||
- The original main() started like: `main (char *ck, char **k)` but we made it
|
||||
compilable for clang by changing it to be: `main (int cka, char **k) { char *ck
|
||||
= (char *)cka;` which might or might not be good.
|
||||
|
||||
- `gcc` reports an infinite recursive call of `main()`. My (Cody's) guess is
|
||||
that this is the root of the problem of the crash but it might be other things.
|
||||
I'm not sure how to stop this from happening. This happens before and after the
|
||||
above fix for `clang`!
|
||||
|
||||
- Try a beautifier on the original C code. This might or might not work; see
|
||||
next point.
|
||||
|
||||
- Use `cpp -E` (see [cpp.c](2001/anonymous/cpp.c)) and clean it up first. I
|
||||
(Cody) did this for convenience though there are still macros. This is because
|
||||
it was done via a hackish make rule:
|
||||
|
||||
cpp: ${PROG}.c
|
||||
@echo "NOTE: this entry seems to no longer work."
|
||||
magic='cpp ${CFLAGS} -E'; \
|
||||
X='-DA(X)=#X'; \
|
||||
$$magic -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
||||
$< ${LIBS} > anonymous.cpp.c
|
||||
|
||||
|
||||
- (If beautifying) After beautifying it try changing references of the macros
|
||||
(where not too complicated) to their definitions. For instance in vim you might
|
||||
do: `:%s/\<l\>/int */g` and then delete the line that was changed to `#define
|
||||
int * int*` (or else do a range substitute so it's not changed). You might not
|
||||
need this if you use the cpp. This might be useful anyway to more easily test
|
||||
things.
|
||||
|
||||
- If your system has a `setarch` tool that might or might not be of help (I'm
|
||||
not too familiar with its internals).
|
||||
|
||||
- The code appears to do everything from one call to `exit(3)` but it makes use
|
||||
of the ternary operator and possibly the comma operator Check the Makefile for
|
||||
the defines but also observe that those are in the source file. It appears that
|
||||
the entry might try compiling as well but that's from a quick glance.
|
||||
|
||||
- The author warns that only simple source (once compiled) would work so make
|
||||
use of the provided source file
|
||||
[2001/anonymous/anonymous.ten.c](2001/anonymous/anonymous.ten.c). To compile try
|
||||
`make anonymous.ten` from the entry directory which you can then run the entry
|
||||
on. Note that it needs to be compiled as a x86 program.
|
||||
|
||||
- The `Tr` macro appears (at a glance when very tired) to create another
|
||||
function and when C pre-processed it seems like at least the function `L()` is
|
||||
there twice. However this is actually a bit different: one is `L##i()` and the
|
||||
other is `L()`. `L##i()` calls itself and `L()` calls `L##i()`. You might have luck
|
||||
renaming it e.g. `Li()` instead but I (Cody) had some problems renaming some of
|
||||
these functions (some but not all).
|
||||
|
||||
- Pray, cast a spell or just wish yourself good luck, depending on your
|
||||
beliefs/personality/whatever! :-) It seems you'll need it! :-) (and also :-( )
|
||||
|
||||
Here are some additional warnings on different platforms:
|
||||
|
||||
```c
|
||||
anonymous.c:12:13: warning: operation on 'P' may be undefined [-Wsequence-point]
|
||||
#define I (P+=4,*L(P-4,0))
|
||||
^
|
||||
```
|
||||
|
||||
With `gdb` I determined that in the function `Runi()` appears to be NULL. I'm
|
||||
not sure if this is relevant or not.
|
||||
|
||||
With `gdb` it appears that the crash happens with:
|
||||
|
||||
```
|
||||
V (v@entry=<optimized out>) at anonymous.c:44
|
||||
44 return E (B[v]);
|
||||
```
|
||||
|
||||
(see [cpp.c](cpp.c)).
|
||||
|
||||
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md))
|
||||
## STATUS: probable bug (possibly depending on system) - please help test and if necessary fix
|
||||
|
||||
Reference in new issue
Block a user