summaryrefslogtreecommitdiff
path: root/nacl/okcompilers
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/okcompilers')
-rw-r--r--nacl/okcompilers/abiname.c45
-rw-r--r--nacl/okcompilers/archivers2
-rw-r--r--nacl/okcompilers/c8
-rw-r--r--nacl/okcompilers/cpp8
-rwxr-xr-xnacl/okcompilers/do196
-rw-r--r--nacl/okcompilers/lib.c29
-rw-r--r--nacl/okcompilers/lib.cpp19
-rw-r--r--nacl/okcompilers/main.c25
-rw-r--r--nacl/okcompilers/main.cpp22
9 files changed, 354 insertions, 0 deletions
diff --git a/nacl/okcompilers/abiname.c b/nacl/okcompilers/abiname.c
new file mode 100644
index 00000000..38373201
--- /dev/null
+++ b/nacl/okcompilers/abiname.c
@@ -0,0 +1,45 @@
1#include <stdio.h>
2
3const char *abi(void)
4{
5#if defined(__amd64__) || defined(__x86_64__) || defined(__AMD64__) || defined(_M_X64) || defined(__amd64)
6 return "amd64";
7#elif defined(__i386__) || defined(__x86__) || defined(__X86__) || defined(_M_IX86) || defined(__i386)
8 return "x86";
9#elif defined(__ia64__) || defined(__IA64__) || defined(__M_IA64)
10 return "ia64";
11#elif defined(__SPU__)
12 return "cellspu";
13#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
14 return "ppc64";
15#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
16 return "ppc32";
17#elif defined(__sparcv9__) || defined(__sparcv9)
18 return "sparcv9";
19#elif defined(__sparc_v8__)
20 return "sparcv8";
21#elif defined(__sparc__) || defined(__sparc)
22 if (sizeof(long) == 4) return "sparcv8";
23 return "sparcv9";
24#elif defined(__ARM_EABI__)
25 return "armeabi";
26#elif defined(__arm__)
27 return "arm";
28#elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
29# if defined(_ABIO32)
30 return "mipso32";
31# elif defined(_ABIN32)
32 return "mips32";
33# else
34 return "mips64";
35# endif
36#else
37 return "default";
38#endif
39}
40
41int main(int argc,char **argv)
42{
43 printf("%s %s\n",argv[1],abi());
44 return 0;
45}
diff --git a/nacl/okcompilers/archivers b/nacl/okcompilers/archivers
new file mode 100644
index 00000000..d5851c37
--- /dev/null
+++ b/nacl/okcompilers/archivers
@@ -0,0 +1,2 @@
1ar
2ar -X64
diff --git a/nacl/okcompilers/c b/nacl/okcompilers/c
new file mode 100644
index 00000000..7218da3a
--- /dev/null
+++ b/nacl/okcompilers/c
@@ -0,0 +1,8 @@
1gcc -m64 -O3 -fomit-frame-pointer -funroll-loops
2gcc -m64 -O -fomit-frame-pointer
3gcc -m64 -fomit-frame-pointer
4gcc -m32 -O3 -fomit-frame-pointer -funroll-loops
5gcc -m32 -O -fomit-frame-pointer
6gcc -m32 -fomit-frame-pointer
7spu-gcc -mstdmain -march=cell -O3 -funroll-loops -fomit-frame-pointer -Drandom=rand -Dsrandom=srand
8spu-gcc -mstdmain -march=cell -O -fomit-frame-pointer -Drandom=rand -Dsrandom=srand
diff --git a/nacl/okcompilers/cpp b/nacl/okcompilers/cpp
new file mode 100644
index 00000000..d1b9ae6d
--- /dev/null
+++ b/nacl/okcompilers/cpp
@@ -0,0 +1,8 @@
1g++ -m64 -O3 -fomit-frame-pointer -funroll-loops
2g++ -m64 -O -fomit-frame-pointer
3g++ -m64 -fomit-frame-pointer
4g++ -m32 -O3 -fomit-frame-pointer -funroll-loops
5g++ -m32 -O -fomit-frame-pointer
6g++ -m32 -fomit-frame-pointer
7spu-g++ -mstdmain -march=cell -O3 -funroll-loops -fomit-frame-pointer -Drandom=rand -Dsrandom=srand
8spu-g++ -mstdmain -march=cell -O -fomit-frame-pointer -Drandom=rand -Dsrandom=srand
diff --git a/nacl/okcompilers/do b/nacl/okcompilers/do
new file mode 100755
index 00000000..372b7e00
--- /dev/null
+++ b/nacl/okcompilers/do
@@ -0,0 +1,196 @@
1#!/bin/sh -e
2
3mkdir oldbin
4mkdir bin
5
6for language in c cpp
7do
8 exec <$language
9 exec 9>${language}-works
10
11 while read c options
12 do
13 echo "=== `date` === checking $c $options" >&2
14 rm -f test*
15 (
16 echo "#!/bin/sh"
17 echo 'PATH="'"$PATH"'"'
18 echo 'export PATH'
19 echo "$c" "$options" '"$@"'
20 ) > test-okc
21 chmod 755 test-okc
22 cat lib.c main.c > test.$language || continue
23 ./test-okc -o test test.$language || continue
24 ./test || continue
25 cp main.c test1.$language || continue
26 cp lib.c test2.$language || continue
27 ./test-okc -c test1.$language || continue
28 ./test-okc -c test2.$language || continue
29 ./test-okc -o test1 test1.o test2.o || continue
30 ./test1 || continue
31 echo "=== `date` === success: $c $options is ok"
32 echo "$c $options" >&9
33 done
34
35 mv ${language}-works $language
36done
37
38exec <c
39
40exec 7>oldbin/okabi
41chmod 755 oldbin/okabi
42echo "#!/bin/sh" >&7
43
44while :
45do
46 exec <c
47 read c options || break
48
49 for language in c cpp
50 do
51 exec 8>${language}-compatible
52 exec 9>${language}-incompatible
53 echo "=== `date` === checking compatibility with $c $options" >&2
54 exec <$language
55 while read c2 options2
56 do
57 echo "=== `date` === checking $c2 $options2" >&2
58 works=1
59 rm -f test*
60 (
61 echo "#!/bin/sh"
62 echo 'PATH="'"$PATH"'"'
63 echo 'export PATH'
64 echo "$c" "$options" '"$@"'
65 ) > test-okc
66 chmod 755 test-okc
67 (
68 echo "#!/bin/sh"
69 echo 'PATH="'"$PATH"'"'
70 echo 'export PATH'
71 echo "$c2" "$options2" '"$@"'
72 ) > test-okc2
73 chmod 755 test-okc2
74 if cp main.c test5.c \
75 && cp main.cpp test5.cpp \
76 && cp lib.c test6.c \
77 && ./test-okc2 -c test5.$language \
78 && ./test-okc -c test6.c \
79 && ./test-okc2 -o test5 test5.o test6.o \
80 && ./test5
81 then
82 echo "=== `date` === success: $c2 $options2 is compatible" >&2
83 echo "$c2 $options2" >&8
84 else
85 echo "$c2 $options2" >&9
86 fi
87 done
88 done
89
90 abi=`awk '{print length($0),$0}' < c-compatible \
91 | sort -n | head -1 | sed 's/ *$//' | sed 's/^[^ ]* //' | tr ' /' '__'`
92
93 echo "echo '"$abi"'" >&7
94
95 syslibs=""
96 for i in -lm -lnsl -lsocket -lrt
97 do
98 echo "=== `date` === checking $i" >&2
99 (
100 echo "#!/bin/sh"
101 echo 'PATH="'"$PATH"'"'
102 echo 'export PATH'
103 echo "$c" "$options" '"$@"' "$i" "$syslibs"
104 ) > test-okclink
105 chmod 755 test-okclink
106 cat lib.c main.c > test.c || continue
107 ./test-okclink -o test test.c $i $syslibs || continue
108 ./test || continue
109 syslibs="$i $syslibs"
110 (
111 echo '#!/bin/sh'
112 echo 'echo "'"$syslibs"'"'
113 ) > "oldbin/oklibs-$abi"
114 chmod 755 "oldbin/oklibs-$abi"
115 done
116
117 foundokar=0
118 exec <archivers
119 while read a
120 do
121 echo "=== `date` === checking archiver $a" >&2
122 (
123 echo "#!/bin/sh"
124 echo 'PATH="'"$PATH"'"'
125 echo 'export PATH'
126 echo "$a" '"$@"'
127 ) > test-okar
128 chmod 755 test-okar
129 cp main.c test9.c || continue
130 cp lib.c test10.c || continue
131 ./test-okc -c test10.c || continue
132 ./test-okar cr test10.a test10.o || continue
133 ranlib test10.a || echo "=== `date` === no ranlib; continuing anyway" >&2
134 ./test-okc -o test9 test9.c test10.a || continue
135 ./test9 || continue
136 cp -p test-okar "oldbin/okar-$abi"
137 echo "=== `date` === success: archiver $a is ok" >&2
138 foundokar=1
139 break
140 done
141
142 case $foundokar in
143 0)
144 echo "=== `date` === giving up; no archivers work" >&2
145 exit 111
146 ;;
147 esac
148
149 for language in c cpp
150 do
151 mv ${language}-incompatible ${language}
152 exec <${language}-compatible
153 exec 9>"oldbin/ok${language}-$abi"
154 chmod 755 "oldbin/ok${language}-$abi"
155
156 echo "#!/bin/sh" >&9
157 while read c2 options2
158 do
159 echo "echo '"$c2 $options2"'" >&9
160 done
161 done
162done
163
164exec 7>/dev/null
165
166oldbin/okabi \
167| while read abi
168do
169 oldbin/okc-$abi \
170 | head -1 \
171 | while read c
172 do
173 $c -o abiname abiname.c \
174 && ./abiname "$abi"
175 done
176done > abinames
177
178numabinames=`awk '{print $2}' < abinames | sort -u | wc -l`
179numabis=`oldbin/okabi | wc -l`
180if [ "$numabis" = "$numabinames" ]
181then
182 exec <abinames
183 exec 7>bin/okabi
184 chmod 755 bin/okabi
185 echo '#!/bin/sh' >&7
186 while read oldabi newabi
187 do
188 mv "oldbin/okc-$oldabi" "bin/okc-$newabi"
189 mv "oldbin/okcpp-$oldabi" "bin/okcpp-$newabi"
190 mv "oldbin/okar-$oldabi" "bin/okar-$newabi"
191 mv "oldbin/oklibs-$oldabi" "bin/oklibs-$newabi"
192 echo "echo $newabi" >&7
193 done
194else
195 cp -p oldbin/* bin
196fi
diff --git a/nacl/okcompilers/lib.c b/nacl/okcompilers/lib.c
new file mode 100644
index 00000000..cf2e3790
--- /dev/null
+++ b/nacl/okcompilers/lib.c
@@ -0,0 +1,29 @@
1int not3(int n)
2{
3 return n != 3;
4}
5
6int bytes(int n)
7{
8 return (n + 7) / 8;
9}
10
11long long shr32(long long n)
12{
13 return n >> 32;
14}
15
16double double5(void)
17{
18 return 5.0;
19}
20
21int intbytes(void)
22{
23 return sizeof(int);
24}
25
26int longbytes(void)
27{
28 return sizeof(long);
29}
diff --git a/nacl/okcompilers/lib.cpp b/nacl/okcompilers/lib.cpp
new file mode 100644
index 00000000..ea956244
--- /dev/null
+++ b/nacl/okcompilers/lib.cpp
@@ -0,0 +1,19 @@
1int not3(int n)
2{
3 return n != 3;
4}
5
6int bytes(int n)
7{
8 return (n + 7) / 8;
9}
10
11long long shr32(long long n)
12{
13 return n >> 32;
14}
15
16double double5(void)
17{
18 return 5.0;
19}
diff --git a/nacl/okcompilers/main.c b/nacl/okcompilers/main.c
new file mode 100644
index 00000000..3b7efa25
--- /dev/null
+++ b/nacl/okcompilers/main.c
@@ -0,0 +1,25 @@
1extern int not3(int);
2extern int bytes(int);
3extern long long shr32(long long);
4extern double double5(void);
5extern int longbytes(void);
6extern int intbytes(void);
7
8int main(int argc,char **argv)
9{
10 if (intbytes() != sizeof(int)) return 100;
11 if (longbytes() != sizeof(long)) return 100;
12
13 if (not3(3)) return 100;
14
15 /* on ppc32, gcc -mpowerpc64 produces SIGILL for >>32 */
16 if (!not3(shr32(1))) return 100;
17
18 /* on pentium 1, gcc -march=pentium2 produces SIGILL for (...+7)/8 */
19 if (bytes(not3(1)) != 1) return 100;
20
21 /* on pentium 1, gcc -march=prescott produces SIGILL for double comparison */
22 if (double5() < 0) return 100;
23
24 return 0;
25}
diff --git a/nacl/okcompilers/main.cpp b/nacl/okcompilers/main.cpp
new file mode 100644
index 00000000..6255102c
--- /dev/null
+++ b/nacl/okcompilers/main.cpp
@@ -0,0 +1,22 @@
1extern "C" {
2 extern int not3(int);
3 extern int bytes(int);
4 extern long long shr32(long long);
5 extern double double5(void);
6}
7
8int main(int argc,char **argv)
9{
10 if (not3(3)) return 100;
11
12 /* on ppc32, gcc -mpowerpc64 produces SIGILL for >>32 */
13 if (!not3(shr32(1))) return 100;
14
15 /* on pentium 1, gcc -march=pentium2 produces SIGILL for (...+7)/8 */
16 if (bytes(not3(1)) != 1) return 100;
17
18 /* on pentium 1, gcc -march=prescott produces SIGILL for double comparison */
19 if (double5() < 0) return 100;
20
21 return 0;
22}