1 |
I tested your script on P4 and Athlon XP Gentoo machines |
2 |
built from stage1 with these CFLAGS: |
3 |
|
4 |
P4 CFLAGS="-march=i686 -O3 -pipe" |
5 |
AMD-XP CFLAGS="-march=athlon-xp -O3 -pipe" |
6 |
|
7 |
Received the same answer: |
8 |
|
9 |
$ bin/analyse-x86 /bin/bash |
10 |
Checking vendor_id string... GenuineIntel ( or AuthenticAMD ) |
11 |
Disassembling /bin/bash, please wait... |
12 |
i486: 0 i586: 0 mmx: 0 sse: 0 3dnow: 0 ext3dnow: 0 |
13 |
/bin/bash will run on 80386 or compatible (i386) or higher processor. |
14 |
|
15 |
So something is wrong ... |
16 |
|
17 |
noro |
18 |
|
19 |
|
20 |
|
21 |
Tavis Ormandy wrote: |
22 |
|
23 |
>Hey, this is an x86 port of a script i wrote (with some help from |
24 |
>wwoods) to identify what processor an alpha binary would work on. |
25 |
> |
26 |
>I think its pretty cool, and had some good feedback so im posting it |
27 |
>here :) |
28 |
> |
29 |
>Example: |
30 |
> |
31 |
>$ ./analyse-x86 /bin/ls |
32 |
>Checking vendor_id string...GenuineIntel |
33 |
>Disassembling /bin/ls, please wait... |
34 |
>i486: 0 i586: 0 ppro: 15 mmx: 0 sse: 8 sse2: 0 |
35 |
>/bin/ls will run on Pentium III (pentium3) or higher processor. |
36 |
> |
37 |
> |
38 |
> |
39 |
>------------------------------------------------------------------------ |
40 |
> |
41 |
>#!/bin/sh |
42 |
># Tavis Ormandy <taviso@g.o> 2003 |
43 |
># Improvments by Will Woods <wwoods@g.o> |
44 |
># |
45 |
># Identify instruction set used in binary. |
46 |
># |
47 |
> |
48 |
># initialize everything to zero. |
49 |
>eval {i486,i586,ppro,mmx,sse,sse2,amd,amd2,cpuid}=0 |
50 |
> |
51 |
># unfortunately there are mnemonic collissions between vendor sets |
52 |
># so check vendor_id string, and enable relevant sets. |
53 |
>printf "Checking vendor_id string..." |
54 |
>if ! test "${1%=*}" == "--vendor"; then |
55 |
> case "`grep -Em1 '^vendor_id.*: ' /proc/cpuinfo | cut -d" " -f2`" in |
56 |
> *GenuineIntel*) vendor=intel; printf "GenuineIntel\n";; |
57 |
> *AuthenticAMD*) vendor=amd; printf "AuthenticAMD\n";; |
58 |
> *CyrixInstead*) vendor=cyrix; printf "CyrixInstead\n";; |
59 |
> *GenuineTMx86*) vendor=transmeta; printf "GenuineTMx86\n";; |
60 |
> *) vendor=other; printf "other\n";; |
61 |
> esac |
62 |
>else |
63 |
> # allow vendor to be overridden |
64 |
> vendor=${1#*=}; shift |
65 |
> printf "%s\n" $vendor |
66 |
>fi |
67 |
> |
68 |
># quick sanity tests. |
69 |
>if ! test "$1"; then |
70 |
> printf "usage: %s [--vendor=intel|amd|cyrix|transmeta] /path/to/binary\n" $0 1>&2 |
71 |
> exit 1 |
72 |
>elif ! test -e "$1"; then |
73 |
> printf "error: %s does not exist.\n" "$1" 1>&2 |
74 |
> exit 1 |
75 |
>elif ! test -r "$1"; then |
76 |
> printf "error: cant read %s.\n" "$1" 1>&2 |
77 |
> exit 1 |
78 |
>fi |
79 |
> |
80 |
>printf "Disassembling %s, please wait...\n" $1 |
81 |
> |
82 |
># initialize screen output |
83 |
>case "$vendor" in |
84 |
> *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ |
85 |
> $i486 $i586 $ppro $mmx $sse $sse2;; |
86 |
> *amd*) printf "i486: %4u i586: %4u mmx: %4u sse: %4u 3dnow: %4u ext3dnow: %4u\r" \ |
87 |
> $i486 $i586 $mmx $sse $amd $amd2;; |
88 |
> *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \ |
89 |
> $i486 $i586 $mmx;; |
90 |
> *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \ |
91 |
> $i486 $i586 $mmx;; |
92 |
> *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ |
93 |
> $i486 $i586 $ppro $mmx $sse $sse2;; |
94 |
>esac |
95 |
> |
96 |
># do the disassembling. |
97 |
>objdump -d $1 | cut -f3 | cut -d" " -f1 | ( |
98 |
> while read instruction; do |
99 |
> case "$instruction" in |
100 |
> "cmpxchg"|"xadd"|"bswap"|"invd"|"wbinvd"|"invlpg") let ++i486; print=1;; |
101 |
> "rdmsr"|"wrmsr"|"rdtsc"|"cmpxch8B"|"rsm") let ++i586; print=1;; |
102 |
> "cmovcc"|"fcmovcc"|"fcomi"|"fcomip"|"fucomi"|"fucomip"|"rdpmc"|"ud2") let ++ppro; print=1;; |
103 |
> "emms"|"movd"|"movq"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pmaddwd"|"pmulhw"|"pmullw"|"por"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"pxor") let ++mmx; print=1;; |
104 |
> "addps"|"addss"|"andnps"|"andps"|"cmpps"|"cmpss"|"comiss"|"cvtpi2ps"|"cvtps2pi"|"cvtsi2ss"|"cvtss2si"|"cvttps2pi"|"cvttss2si"|"divps"|"divss"|"fxrstor"|"fxsave"|"ldmxcsr"|"maxps"|"maxss"|"minps"|"minss"|"movaps"|"movhlps"|"movhps"|"movlhps"|"movlps"|"movmskps"|"movss"|"movups"|"mulps"|"mulss"|"orps"|"pavgb"|"pavgw"|"psadbw"|"rcpps"|"rcpss"|"rsqrtps"|"rsqrtss"|"shufps"|"sqrtps"|"sqrtss"|"stmxcsr"|"subps"|"subss"|"ucomiss"|"unpckhps"|"unpcklps"|"xorps"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"pshufw"|"maskmovq"|"movntps"|"movntq"|"prefetch"|"sfence") let ++sse; print=1;; |
105 |
> "addpd"|"addsd"|"andnpd"|"andpd"|"clflush"|"cmppd"|"cmpsd"|"comisd"|"cvtdq2pd"|"cvtdq2ps"|"cvtpd2pi"|"cvtpd2pq"|"cvtpd2ps"|"cvtpi2pd"|"cvtps2dq"|"cvtps2pd"|"cvtsd2si"|"cvtsd2ss"|"cvtsi2sd"|"cvtss2sd"|"cvttpd2pi"|"cvttpd2dq"|"cvttps2dq"|"cvttsd2si"|"divpd"|"divsd"|"lfence"|"maskmovdqu"|"maxpd"|"maxsd"|"mfence"|"minpd"|"minsd"|"movapd"|"movd"|"movdq2q"|"movdqa"|"movdqu"|"movhpd"|"movlpd"|"movmskpd"|"movntdq"|"movnti"|"movntpd"|"movq"|"movq2dq"|"movsd"|"movupd"|"mulpd"|"mulsd"|"orpd"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddq"|"paddq"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pause"|"pavgb"|"pavgw"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pextrw"|"pinsrw"|"pmaddwd"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhw"|"pmulhuw"|"pmullw"|"pmuludq"|"pmuludq"|"por"|"psadbw"|"pshufd"|"pshufhw"|"pshuflw"|"pslldq"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrldq"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubq"|"psubq"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"psubsb"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpckhqdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"punpcklqdq"|"pxor"|"shufpd"|"sqrtpd"|"sqrtsd"|"subpd"|"subsd"|"ucomisd"|"unpckhpd"|"unpcklpd"|"xorpd") let ++sse2; print=1;; |
106 |
> "pavgusb"|"pfadd"|"pfsub"|"pfsubr"|"pfacc"|"pfcmpge"|"pfcmpgt"|"pfcmpeq"|"pfmin"|"pfmax"|"pi2fw"|"pi2fd"|"pf2iw"|"pf2id"|"pfrcp"|"pfrsqrt"|"pfmul"|"pfrcpit1"|"pfrsqit1"|"pfrcpit2"|"pmulhrw"|"pswapw"|"femms"|"prefetch") let ++amd; print=1;; |
107 |
> "pf2iw"|"pfnacc"|"pfpnacc"|"pi2fw"|"pswapd"|"maskmovq"|"movntq"|"pavgb"|"pavgw"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"prefetchnta"|"prefetcht0"|"prefetcht1"|"prefetcht2"|"psadbw"|"pshufw"|"sfence") let ++amd2; print=1;; |
108 |
> "cpuid") let ++cpuid ++i586; print=1;; |
109 |
> esac |
110 |
> # check if screen needs updating. |
111 |
> if test "$print"; then |
112 |
> case "$vendor" in |
113 |
> *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ |
114 |
> $i486 $i586 $ppro $mmx $sse $sse2;; |
115 |
> *amd*) printf "i486: %4u i586: %4u mmx: %4u sse: %4u 3dnow: %4u ext3dnow: %4u\r" \ |
116 |
> $i486 $i586 $mmx $sse $amd $amd2;; |
117 |
> *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \ |
118 |
> $i486 $i586 $mmx;; |
119 |
> *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \ |
120 |
> $i486 $i586 $mmx;; |
121 |
> *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ |
122 |
> $i486 $i586 $ppro $mmx $sse $sse2;; |
123 |
> esac |
124 |
> unset print |
125 |
> fi |
126 |
> done |
127 |
> |
128 |
># print a newline |
129 |
>echo |
130 |
> |
131 |
># cpuid instruction could mean the application checks to see |
132 |
># if an instruction is supported before executing it. This might |
133 |
># mean it will work on anything over a pentium. |
134 |
>if test $cpuid -gt 0; then |
135 |
> printf "\nThis binary was found to contain the cpuid instruction.\n" |
136 |
> printf "It may be able to conditionally execute instructions if\n" |
137 |
> printf "they are supported on the host (i586+).\n\n" |
138 |
>fi |
139 |
> |
140 |
># print minimum required processor, if there are collissions |
141 |
># use the vendor to decide what to print. |
142 |
>if test $sse2 -gt 0; then |
143 |
> subarch="Pentium IV (pentium4)" |
144 |
>elif test $sse -gt 0; then |
145 |
> if test "$vendor" == "intel"; then |
146 |
> subarch="Pentium III (pentium3)" |
147 |
> elif test "$vendor" == "amd"; then |
148 |
> subarch="AMD Athlon 4 (athlon-4)" |
149 |
> else |
150 |
> subarch="Pentium III (pentium3)" |
151 |
> fi |
152 |
>elif test "$vendor" == "amd" -a $amd2 -gt 0; then |
153 |
> subarch="AMD Athlon (athlon)" |
154 |
>elif test "$vendor" == "amd" -a $amd -gt 0; then |
155 |
> subarch="AMD K6 III (k6-3)" |
156 |
>elif test $mmx -gt 0; then |
157 |
> if test "$vendor" == "intel"; then |
158 |
> if $ppro -gt 0; then |
159 |
> subarch="Pentium II (pentium2)" |
160 |
> else |
161 |
> subarch="Intel Pentium MMX [P55C] (pentium-mmx)" |
162 |
> fi |
163 |
> elif test "$vendor" == "amd"; then |
164 |
> subarch="AMD K6 (k6)" |
165 |
> elif test "$vendor" == "cyrix"; then |
166 |
> subarch="Cyrix 6x86MX / MII (pentium-mmx)" |
167 |
> else |
168 |
> subarch="Intel Pentium MMX [P55C] (pentium-mmx)" |
169 |
> fi |
170 |
>elif test $ppro -gt 0; then |
171 |
> subarch="Pentium Pro (i686 or pentiumpro)" |
172 |
>elif test $i586 -gt 0; then |
173 |
> subarch="Pentium or compatible (i586) (i586 or pentium)" |
174 |
>elif test $i486 -gt 0; then |
175 |
> subarch="80486 or comaptible (i486)" |
176 |
>else |
177 |
> subarch="80386 or compatible (i386)" |
178 |
>fi |
179 |
> |
180 |
># print message and exit. |
181 |
>printf "%s will run on %s or higher processor.\n" "$1" "$subarch"; ) |
182 |
> |
183 |
> |
184 |
> |
185 |
>------------------------------------------------------------------------ |
186 |
> |
187 |
>-- |
188 |
>gentoo-dev@g.o mailing list |
189 |
> |
190 |
|
191 |
|
192 |
-- |
193 |
gentoo-dev@g.o mailing list |