Gentoo Archives: gentoo-user

From: Nikos Chantziaras <realnc@×××××.de>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: Compiling 32 bit library on x86_64
Date: Sat, 01 May 2010 08:40:41
Message-Id: hrgpcq$e21$1@dough.gmane.org
In Reply to: Re: [gentoo-user] Re: Compiling 32 bit library on x86_64 by David W Noon
1 On 04/30/2010 07:29 PM, David W Noon wrote:
2 > On Fri, 30 Apr 2010 15:20:02 +0200, Nikos Chantziaras wrote about
3 > [gentoo-user] Re: Compiling 32 bit library on x86_64:
4 >
5 >> On 04/30/2010 03:09 PM, David W Noon wrote:
6 >>> On Fri, 30 Apr 2010 12:10:02 +0200, Roger Mason wrote about
7 >>> [gentoo-user] Compiling 32 bit library on x86_64:
8 >>>
9 >>>> Hello,
10 >>>>
11 >>>> I need to compile a 32 bit version of libtermcap on an x86_64
12 >>>> (multilib) system. Can someone tell me how to set up CFLAGS? This
13 >>>> is what I have at the moment:
14 >>>>
15 >>>> CFLAGS="-O2 -m32 -march=native -msse3 -pipe"
16 >>>> CXXFLAGS="-O2 -m32 -march=native -msse3 -pipe"
17 >>>
18 >>> The -march=native will shoot you in the foot. Pick a 32-bit
19 >>> architecture and use that instead; e.g. -march=i686
20 >>>
21 >>> Then, -msse3 could also be problematic, unless the target is a very
22 >>> late model Pentium 4. I would ditch that too.
23 >>
24 >> None of those options are problematic. -march=native has nothing to
25 >> do with 32/64 bit. Every 64-bit CPU is 32-bit compatible and has zero
26 >> consequence.
27 >>
28 >> I think you fell into the logical trap that 32-bit CPUs are not 64-bit
29 >> compatible but it's OK vice versa :) Meaning you can't use "-m64
30 >> -march=i686". But you *can* and *should* use "-m32 -march=core2".
31 >
32 > No, I stand by what I wrote.
33
34 You are wrong.
35
36
37 > The -march=native option tells the compiler to issue the CPUID
38 > instruction to determine the architecture. This means that on an amd64
39 > box it will return data for either an AMD K8 or an Intel Pentium D
40 > architecture. This, in turn, allows the compiler to generate K8
41 > instructions that are not valid on IA32 processors. It even allows
42 > the compiler to use 64-bit registers, including the additional
43 > registers that were not in an IA32 processor.
44
45 The OP was not interested whether the code runs on all IA32 processors.
46 Just on his. Yes, if you compile with "-m32 -march=native" the code
47 will not run everywhere else. But I fail to see what this has to do
48 with 32-bit vs 64-bit; it also happens if you omit "-m32".
49
50
51 > The -m32 option instructs the compiler to generate code with 32-bit
52 > pointers and relocation dictionary. It does not constrain the compiler
53 > to generate code that will definitely run on an IA32 processor, but it
54 > does ensure that the code can be linked with 32-bit libraries.
55 >
56 > So, if one is compiling on, say, a Core2 Duo and one uses -march=native
57 > and -m32, the compiler can use all kinds of instructions valid on the
58 > Core2 Duo, but limits addressing to 32-bit.
59
60 Yes, which is what we want. Again, the OP was not interested whether
61 the code runs on other machines. If that was the case, he would not
62 have used -march=native in the first place.
63
64 And I have proof too. Compile whatever you want with -m32
65 -march=native. It will work just fine.