Gentoo Archives: gentoo-user

From: David W Noon <dwnoon@××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: Compiling 32 bit library on x86_64
Date: Fri, 30 Apr 2010 16:30:43
Message-Id: 20100430172942.55e39060@karnak.local
1 On Fri, 30 Apr 2010 15:20:02 +0200, Nikos Chantziaras wrote about
2 [gentoo-user] Re: Compiling 32 bit library on x86_64:
3
4 >On 04/30/2010 03:09 PM, David W Noon wrote:
5 >> On Fri, 30 Apr 2010 12:10:02 +0200, Roger Mason wrote about
6 >> [gentoo-user] Compiling 32 bit library on x86_64:
7 >>
8 >>> Hello,
9 >>>
10 >>> I need to compile a 32 bit version of libtermcap on an x86_64
11 >>> (multilib) system. Can someone tell me how to set up CFLAGS? This
12 >>> is what I have at the moment:
13 >>>
14 >>> CFLAGS="-O2 -m32 -march=native -msse3 -pipe"
15 >>> CXXFLAGS="-O2 -m32 -march=native -msse3 -pipe"
16 >>
17 >> The -march=native will shoot you in the foot. Pick a 32-bit
18 >> architecture and use that instead; e.g. -march=i686
19 >>
20 >> Then, -msse3 could also be problematic, unless the target is a very
21 >> late model Pentium 4. I would ditch that too.
22 >
23 >None of those options are problematic. -march=native has nothing to
24 >do with 32/64 bit. Every 64-bit CPU is 32-bit compatible and has zero
25 >consequence.
26 >
27 >I think you fell into the logical trap that 32-bit CPUs are not 64-bit
28 >compatible but it's OK vice versa :) Meaning you can't use "-m64
29 >-march=i686". But you *can* and *should* use "-m32 -march=core2".
30
31 No, I stand by what I wrote.
32
33 The -march=native option tells the compiler to issue the CPUID
34 instruction to determine the architecture. This means that on an amd64
35 box it will return data for either an AMD K8 or an Intel Pentium D
36 architecture. This, in turn, allows the compiler to generate K8
37 instructions that are not valid on IA32 processors. It even allows
38 the compiler to use 64-bit registers, including the additional
39 registers that were not in an IA32 processor.
40
41 The -m32 option instructs the compiler to generate code with 32-bit
42 pointers and relocation dictionary. It does not constrain the compiler
43 to generate code that will definitely run on an IA32 processor, but it
44 does ensure that the code can be linked with 32-bit libraries.
45
46 So, if one is compiling on, say, a Core2 Duo and one uses -march=native
47 and -m32, the compiler can use all kinds of instructions valid on the
48 Core2 Duo, but limits addressing to 32-bit.
49
50 From the info pages for GCC:
51
52 3.17.14 Intel 386 and AMD x86-64 Options
53 ----------------------------------------
54
55 These `-m' options are defined for the i386 and x86-64 family of
56 computers:
57
58 `-mtune=CPU-TYPE'
59 Tune to CPU-TYPE everything applicable about the generated code,
60 except for the ABI and the set of available instructions. The
61 choices for CPU-TYPE are:
62 _generic_
63 Produce code optimized for the most common IA32/AMD64/EM64T
64 processors. If you know the CPU on which your code will run,
65 then you should use the corresponding `-mtune' option instead
66 of `-mtune=generic'. But, if you do not know exactly what
67 CPU users of your application will have, then you should use
68 this option.
69
70 As new processors are deployed in the marketplace, the
71 behavior of this option will change. Therefore, if you
72 upgrade to a newer version of GCC, the code generated option
73 will change to reflect the processors that were most common
74 when that version of GCC was released.
75
76 There is no `-march=generic' option because `-march'
77 indicates the instruction set the compiler can use, and there
78 is no generic instruction set applicable to all processors.
79 In contrast, `-mtune' indicates the processor (or, in this
80 case, collection of processors) for which the code is
81 optimized.
82
83 _native_
84 This selects the CPU to tune for at compilation time by
85 determining the processor type of the compiling machine.
86 Using `-mtune=native' will produce code optimized for the
87 local machine under the constraints of the selected
88 instruction set. Using `-march=native' will enable all
89 instruction subsets supported by the local machine (hence the
90 result might not run on different machines).
91
92 _i386_
93 Original Intel's i386 CPU.
94
95 _i486_
96 Intel's i486 CPU. (No scheduling is implemented for this
97 chip.)
98
99 _i586, pentium_
100 Intel Pentium CPU with no MMX support.
101
102 _pentium-mmx_
103 Intel PentiumMMX CPU based on Pentium core with MMX
104 instruction set support.
105
106 _pentiumpro_
107 Intel PentiumPro CPU.
108
109 _i686_
110 Same as `generic', but when used as `march' option, PentiumPro
111 instruction set will be used, so the code will run on all
112 i686 family chips.
113
114 _pentium2_
115 Intel Pentium2 CPU based on PentiumPro core with MMX
116 instruction set support.
117
118 _pentium3, pentium3m_
119 Intel Pentium3 CPU based on PentiumPro core with MMX and SSE
120 instruction set support.
121
122 _pentium-m_
123 Low power version of Intel Pentium3 CPU with MMX, SSE and
124 SSE2 instruction set support. Used by Centrino notebooks.
125
126 _pentium4, pentium4m_
127 Intel Pentium4 CPU with MMX, SSE and SSE2 instruction set
128 support.
129
130 _prescott_
131 Improved version of Intel Pentium4 CPU with MMX, SSE, SSE2
132 and SSE3 instruction set support.
133
134 _nocona_
135 Improved version of Intel Pentium4 CPU with 64-bit
136 extensions, MMX, SSE, SSE2 and SSE3 instruction set support.
137
138 _core2_
139 Intel Core2 CPU with 64-bit extensions, MMX, SSE, SSE2, SSE3
140 and SSSE3 instruction set support.
141
142 _k6_
143 AMD K6 CPU with MMX instruction set support.
144
145 _k6-2, k6-3_
146 Improved versions of AMD K6 CPU with MMX and 3dNOW!
147 instruction set support.
148
149 _athlon, athlon-tbird_
150 AMD Athlon CPU with MMX, 3dNOW!, enhanced 3dNOW! and SSE
151 prefetch instructions support.
152
153 _athlon-4, athlon-xp, athlon-mp_
154 Improved AMD Athlon CPU with MMX, 3dNOW!, enhanced 3dNOW! and
155 full SSE instruction set support.
156
157 _k8, opteron, athlon64, athlon-fx_
158 AMD K8 core based CPUs with x86-64 instruction set support.
159 (This supersets MMX, SSE, SSE2, 3dNOW!, enhanced 3dNOW! and
160 64-bit instruction set extensions.)
161
162 _k8-sse3, opteron-sse3, athlon64-sse3_
163 Improved versions of k8, opteron and athlon64 with SSE3
164 instruction set support.
165
166 _amdfam10, barcelona_
167 AMD Family 10h core based CPUs with x86-64 instruction set
168 support. (This supersets MMX, SSE, SSE2, SSE3, SSE4A,
169 3dNOW!, enhanced 3dNOW!, ABM and 64-bit instruction set
170 extensions.)
171
172 _winchip-c6_
173 IDT Winchip C6 CPU, dealt in same way as i486 with additional
174 MMX instruction set support.
175
176 _winchip2_
177 IDT Winchip2 CPU, dealt in same way as i486 with additional
178 MMX and 3dNOW! instruction set support.
179
180 _c3_
181 Via C3 CPU with MMX and 3dNOW! instruction set support. (No
182 scheduling is implemented for this chip.)
183
184 _c3-2_
185 Via C3-2 CPU with MMX and SSE instruction set support. (No
186 scheduling is implemented for this chip.)
187
188 _geode_
189 Embedded AMD CPU with MMX and 3dNOW! instruction set support.
190
191 While picking a specific CPU-TYPE will schedule things
192 appropriately for that particular chip, the compiler will not
193 generate any code that does not run on the i386 without the
194 `-march=CPU-TYPE' option being used.
195
196 `-march=CPU-TYPE'
197 Generate instructions for the machine type CPU-TYPE. The choices
198 for CPU-TYPE are the same as for `-mtune'. Moreover, specifying
199 `-march=CPU-TYPE' implies `-mtune=CPU-TYPE'.
200
201 [snip]
202
203 The above options determine the instruction set and instruction
204 scheduling, and "native" uses whatever hardware platform is used for
205 compilation.
206
207 [continuing]
208
209 `-m32'
210 `-m64'
211 Generate code for a 32-bit or 64-bit environment. The 32-bit
212 environment sets int, long and pointer to 32 bits and generates
213 code that runs on any i386 system. The 64-bit environment sets
214 int to 32 bits and long and pointer to 64 bits and generates code
215 for AMD's x86-64 architecture. For darwin only the -m64 option
216 turns off the `-fno-pic' and `-mdynamic-no-pic' options.
217
218 The above is slightly misleading, as it should say "code that loads on
219 any i386" rather than "code that runs on any i386". It is all about
220 setting the width for pointers and integers.
221 --
222 Regards,
223
224 Dave [RLU #314465]
225 ======================================================================
226 dwnoon@××××××××.com (David W Noon)
227 ======================================================================

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
[gentoo-user] Re: Compiling 32 bit library on x86_64 Nikos Chantziaras <realnc@×××××.de>