diff --git a/2001/bellard/.gitignore b/2001/bellard/.gitignore index baa3302b3..52488cedd 100644 --- a/2001/bellard/.gitignore +++ b/2001/bellard/.gitignore @@ -1,2 +1,3 @@ bellard bellard.otccex +otccelf diff --git a/2001/bellard/Makefile b/2001/bellard/Makefile index 0bda56ef2..be3c93379 100644 --- a/2001/bellard/Makefile +++ b/2001/bellard/Makefile @@ -38,7 +38,7 @@ include ../../var.mk # Common C compiler warnings to silence # -CSILENCE= #-Wno-bitwise-op-parentheses -Wno-error -Wno-implicit-function-declaration \ +CSILENCE= -Wno-bitwise-op-parentheses -Wno-error -Wno-implicit-function-declaration \ -Wno-implicit-int -Wno-int-conversion -Wno-int-to-pointer-cast \ -Wno-parentheses -Wno-return-type @@ -55,7 +55,7 @@ CSTD= -std=gnu99 # Some entries require 32-bitness: ARCH= -m32 # Some entries require 64-bitness: ARCH= -m64 # -ARCH= +ARCH= -m32 # Defines that are needed to compile # @@ -71,7 +71,7 @@ OPT= -O3 # Default flags for ANSI C compilation # -CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} -rdynamic +CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} -rdynamic -fno-pie # Libraries needed to build # diff --git a/2001/bellard/README.md b/2001/bellard/README.md index 63bec7fd0..09335561a 100644 --- a/2001/bellard/README.md +++ b/2001/bellard/README.md @@ -19,17 +19,30 @@ make ``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) partially fixed this -but he notes that this will not work without some possibly serious debugging. As -it is it segfaults. He fixed an earlier segfault so that at least the file can -be opened and he also changed some of the macro uses to what they expanded to -but mostly he kept it the same. He also fixed -[bellard.otccex.c](bellard.otccex.c) so it does not -segfault and seemingly works okay (it did not work at all). The author stated -that they used [gcc +but he notes that this will not work without (according to the author) i386 +linux or else some skill in resolving the portability issues. As it is it +segfaults in 64-bit linux (and as expected macOS). He fixed an earlier segfault +so that at least the file can be opened (but perhaps that will be wrong in i386 +linux?) and he also changed some of the macro used to what they evaluate to but +mostly he kept it the same. He also fixed [bellard.otccex.c](bellard.otccex.c) +so it does not segfault and seemingly works okay (it did not work at all) but +still this appears to not work in 64-bit linux. See below portability notes. +Thank you Cody for your assistance! + +### Portability notes: + +With a tip from [Yusuke Endoh](/winners.html#Yusuke_Endoh) we rediscovered the +author's [web page for this program](https://bellard.org/otcc/) where it is +stated that this will only work in i386 linux. The author also stated in the +remarks in this document that they used that they used [gcc 2.95.2](https://ftp.gnu.org/gnu/gcc/gcc-2.95.2/gcc-everything-2.95.2.tar.gz) but -we don't know if that's relevant or not. Thank you Cody for your assistance! Can -you fix the entry? We welcome your help! If you can please look at -[bugs.md](/bugs.md) for more information. Thank you! +we don't know if that's relevant or not. + +Yusuke offered a modification which is not needed with gcc but with some +versions of `clang` it is. With `gcc` we can get away with `-rdynamic -fno-pie +-Wl,-z,execstack` which solves the problem of execution in memory but any +compiler that does not support this would not work. Thus we use the modification +by Yusuke. Thank you Yusuke! ## Try: @@ -40,7 +53,7 @@ you fix the entry? We welcome your help! If you can please look at ## Judges' remarks: - :-) +\ :-) ## Author's remarks: diff --git a/2001/bellard/bellard.c b/2001/bellard/bellard.c index 53b45e216..9871b95a2 100644 --- a/2001/bellard/bellard.c +++ b/2001/bellard/bellard.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #define k *(int*) #define a if( #define c ad() @@ -8,7 +10,7 @@ #define p while( #define x *(char*) #define b == -#define V =calloc(1,99999) +#define V =mmap(NULL, 99999, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) #define f () #define J return #define l ae( diff --git a/2001/bellard/otccelf.c b/2001/bellard/otccelf.c new file mode 100644 index 000000000..713127096 --- /dev/null +++ b/2001/bellard/otccelf.c @@ -0,0 +1,621 @@ +#include +#include +#include +#include +#include +#define r *(char*) +#define b if( +#define t *(int*) +#define k else +#define u while( +#define g av() +#define c ax( +#define f == +#define aj =mmap(NULL, 99999, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) +#define j () +#define O return +#define l a) +#define A int +#define n 0) +#define o aw( +#define p 1) +#define q s) +A e,C,J,m,T,U,K,v,P,i,ak,Q,D,V,al,Z,G,R,y; +L(l{ +r D++=a; +} +w j{ +b V){ +m=r V++; +b m f 2){ +V=0; +m=al; +} +} +k m=fgetc(ak); +} +am j{ +O isalnum(m)|m f 95; +} +an j{ +b m f 92){ +w j; +b m f 110)m=10; +} +} +g{ +A a,s,h; +u isspace(m)|m f 35){ +b m f 35){ +w j; +g; +b e f 536){ +g; +L(32); +t e=1; +t(e+4)=D; +} +u m!=10){ +L(m); +w j; +} +L(m); +L(2); +} +w j; +} +J=0; +e=m; +b am j){ +L(32); +Z=D; +u am j){ +L(m); +w j; +} +b isdigit(e)){ +C=strtol(Z,0,n; +e=2; +} +k{ +r D=32; +e=strstr(Q,Z-p-Q; +r D=0; +e=e*8+256; +b e>536){ +e=T+e; +b t e f p{ +V=t(e+4); +al=m; +w j; +g; +} +} +} +} +k{ +w j; +b e f 39){ +e=2; +an j; +C=m; +w j; +w j; +} +k b e f 47&m f 42){ +w j; +u m){ +u m!=42)w j; +w j; +b m f 47)m=0; +} +w j; +g; +} +k{ +a="++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b"; +u s=r a++){ +h=r a++; +C=0; +u(J=r a++-98)>8; +} +} +E(a,d){ +r a++=d; +r a++=d>>8; +r a++=d>>16; +r a++=d>>24; +} +ao(l{ +A d; +return(r a&255)|(r(a+p&255)<<8|(r(a+2)&255)<<16|(r(a+3)&255)<<24; +} +ap(a,z){ +A d; +u l{ +d=ao(l; +b r(a-p f 5){ +b z>=G&&z8){ +h=aa(a,h); +X(q; +} +k{ +o 80); +X(q; +o 89); +b s f 4|s f 5){ +aq(l; +} +k{ +o l; +b d f 37)o 146); +} +} +} +b h&&s>8){ +h=aa(a,h); +M(a^p; +I(5); +H(h); +M(l; +} +} +} +B j{ +X(11); +} +ac j{ +B j; +O aa(0,n; +} +S(q{ +A h,d,a; +b e f 288){ +g; +g; +h=ac j; +g; +S(q; +b e f 312){ +g; +d=I(n; +H(h); +S(q; +H(d); +} +k{ +H(h); +} +} +k b e f 352|e f 504){ +a=e; +g; +g; +b a f 352){ +d=v; +h=ac j; +} +k{ +b e!=59)B j; +g; +d=v; +h=0; +b e!=59)h=ac j; +g; +b e!=41){ +a=I(n; +B j; +I(d-v-5); +H(l; +d=a+4; +} +} +g; +S(&h); +I(d-v-5); +H(h); +} +k b e f 123){ +g; +ar(p; +u e!=125)S(q; +g; +} +k{ +b e f 448){ +g; +b e!=59)B j; +U=I(U); +} +k b e f 400){ +g; +t s=I(t q; +} +k b e!=59)B j; +g; +} +} +ar(q{ +A h; +u e f 256|e!=-1&!q{ +b e f 256){ +g; +u e!=59){ +b q{ +P=P+4; +t e=-P; +} +k{ +t e=i; +i=i+4; +} +g; +b e f 44)g; +} +g; +} +k{ +t e=v; +g; +g; +h=8; +u e!=41){ +t e=h; +h=h+4; +g; +b e f 44)g; +} +g; +U=P=0; +o 15042901); +h=x(60545,n; +S(n; +H(U); +o 50121); +E(h,P); +} +} +} +c d){ +E(i,d); +i=i+4; +} +ad(d,l{ +c d); +d=d+134512640; +c d); +c d); +c l; +c l; +} +ae(q{ +A a,h,d,N,z,F; +N=0; +a=Q; +u p{ +a++; +h=a; +u r a!=32&&a