public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to compile and link 32 bit c code with 64 bit c code‏
@ 2010-01-05  3:47 Qing Wang
  2010-01-05 17:59 ` Bob Plantz
  0 siblings, 1 reply; 5+ messages in thread
From: Qing Wang @ 2010-01-05  3:47 UTC (permalink / raw)
  To: gcc-help


Hi, 
 
I am making a 32 bit project to call some 64 bit functions.
So, I have most of c files which will be compiled and linked into 32 bit binary.And I have some c files including those functions which will be compiled into 64 bit binary.
Of course, I will call into assembly first to set up 64 bit mode, and then call those 64 bit functions, finally I will return to assembly to get back to 32 bit mode. 
 
Now I have a problem how to compile and link those 32 bit code with those 64 bit code together into one object file (like xxx.gz) 
Unlike assembly, which is easy to embed ".code32" or ".code64" in assembly to distinguish 32 bit code and 64 bit code, (see the document "Using as The GNU Assembler"), how can I achieve this for c files? Or are there any examples to tell me to achieve this? 
 
Thanks.
Qing  		 	   		  
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmailآ®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compile and link 32 bit c code with 64 bit c  code‏
  2010-01-05  3:47 How to compile and link 32 bit c code with 64 bit c code‏ Qing Wang
@ 2010-01-05 17:59 ` Bob Plantz
  2010-01-06  6:21   ` Qing Wang
  2010-01-06  6:29   ` Qing Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Bob Plantz @ 2010-01-05 17:59 UTC (permalink / raw)
  To: Qing Wang; +Cc: gcc-help

On Tue, 2010-01-05 at 11:47 +0800, Qing Wang wrote:
> Hi, 
>  
> I am making a 32 bit project to call some 64 bit functions.
> So, I have most of c files which will be compiled and linked into 32 bit binary.And I have some c files including those functions which will be compiled into 64 bit binary.
> Of course, I will call into assembly first to set up 64 bit mode, and then call those 64 bit functions, finally I will return to assembly to get back to 32 bit mode. 
>  
> Now I have a problem how to compile and link those 32 bit code with those 64 bit code together into one object file (like xxx.gz) 
> Unlike assembly, which is easy to embed ".code32" or ".code64" in assembly to distinguish 32 bit code and 64 bit code, (see the document "Using as The GNU Assembler"), how can I achieve this for c files? Or are there any examples to tell me to achieve this? 
>  
> Thanks.
> Qing  		 	   		  

What architecture?

What do you mean by "32 bit c code" versus "64 bit c code"? If I compile
with the -m32 option I get 32-bit code, and with -m64 I get 64-bit code.

If you are using the x86 architecture, mixing 32-bit functions with
64-bit functions simply does not work. Arguments are passed on the stack
in 32-bit, but in registers (the first six arguments) in 64-bit.

--Bob


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: How to compile and link 32 bit c code with 64 bit c code‏
  2010-01-05 17:59 ` Bob Plantz
@ 2010-01-06  6:21   ` Qing Wang
  2010-01-06  6:29   ` Qing Wang
  1 sibling, 0 replies; 5+ messages in thread
From: Qing Wang @ 2010-01-06  6:21 UTC (permalink / raw)
  To: plantz; +Cc: gcc-help


> Subject: Re: How to compile and link 32 bit c code with 64 bit c codeأ¾
> From: plantz@cds1.net
> To: qinggwang@hotmail.com
> CC: gcc-help@gcc.gnu.org
> Date: Tue, 5 Jan 2010 09:58:33 -0800
>
> On Tue, 2010-01-05 at 11:47 +0800, Qing Wang wrote:
>> Hi,
>>
>> I am making a 32 bit project to call some 64 bit functions.
>> So, I have most of c files which will be compiled and linked into 32 bit binary.And I have some c files including those functions which will be compiled into 64 bit binary.
>> Of course, I will call into assembly first to set up 64 bit mode, and then call those 64 bit functions, finally I will return to assembly to get back to 32 bit mode.
>>
>> Now I have a problem how to compile and link those 32 bit code with those 64 bit code together into one object file (like xxx.gz)
>> Unlike assembly, which is easy to embed ".code32" or ".code64" in assembly to distinguish 32 bit code and 64 bit code, (see the document "Using as The GNU Assembler"), how can I achieve this for c files? Or are there any examples to tell me to achieve this?
>>
>> Thanks.
>> Qing
>
> What architecture?
>
> What do you mean by "32 bit c code" versus "64 bit c code"? If I compile
> with the -m32 option I get 32-bit code, and with -m64 I get 64-bit code.
>
> If you are using the x86 architecture, mixing 32-bit functions with
> 64-bit functions simply does not work. Arguments are passed on the stack
> in 32-bit, but in registers (the first six arguments) in 64-bit.
>
> --Bob
>
>
Thank you for the response.
I am sorry. Maybe I explained unclearly.

I am using x86 system, under 2.6.23.1-42.fc8 x86_64, and using gcc to compile the probject by "-m32". However, I have some code compiled as 64 bit by -m64, because I need to switch into 64 mode and call some functions in 64 bit code. The purpose is I need the functions to access the memory above 64G, as you know in 32 bit mode, the memory above 64G can't be accessed.
 
If they are not c files but assembly, I can use .code64 to distinguish some code compiled as 64 bit.
I wish to find a way for c files, which has the same functionality as .code16/.code32/.code64 in assembly.
 
Just curious, does putting asm(".code64") in the beginning of c files work? I saw some code is written like this.
 
Thanks.
Qing 		 	   		  
_________________________________________________________________
Keep your friends updatedآ—even when youآ’re not signed in.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: How to compile and link 32 bit c code with 64 bit c code‏
  2010-01-05 17:59 ` Bob Plantz
  2010-01-06  6:21   ` Qing Wang
@ 2010-01-06  6:29   ` Qing Wang
  2010-01-06  9:17     ` Andrew Haley
  1 sibling, 1 reply; 5+ messages in thread
From: Qing Wang @ 2010-01-06  6:29 UTC (permalink / raw)
  To: plantz; +Cc: gcc-help


Oh, PS:
 
I noticed that if some c files are compiled as 32 bit code by -m32, and others are compiled as 64 bit code by -m64, they will not work together.
But can I add something in the c files (say asm(".code64")) and compile all of c files by -m32, and then when the program switches into 64 bit mode from 32 bit mode, those ".code64" code can work properly (i.e. access the memory above 64G)?
 
Thanks.
Qing

----------------------------------------
> From: qinggwang@hotmail.com
> To: plantz@cds1.net
> CC: gcc-help@gcc.gnu.org
> Subject: RE: How to compile and link 32 bit c code with 64 bit c codeأ¾
> Date: Wed, 6 Jan 2010 14:21:32 +0800
>
>
>> Subject: Re: How to compile and link 32 bit c code with 64 bit c codeأ¾
>> From: plantz@cds1.net
>> To: qinggwang@hotmail.com
>> CC: gcc-help@gcc.gnu.org
>> Date: Tue, 5 Jan 2010 09:58:33 -0800
>>
>> On Tue, 2010-01-05 at 11:47 +0800, Qing Wang wrote:
>>> Hi,
>>>
>>> I am making a 32 bit project to call some 64 bit functions.
>>> So, I have most of c files which will be compiled and linked into 32 bit binary.And I have some c files including those functions which will be compiled into 64 bit binary.
>>> Of course, I will call into assembly first to set up 64 bit mode, and then call those 64 bit functions, finally I will return to assembly to get back to 32 bit mode.
>>>
>>> Now I have a problem how to compile and link those 32 bit code with those 64 bit code together into one object file (like xxx.gz)
>>> Unlike assembly, which is easy to embed ".code32" or ".code64" in assembly to distinguish 32 bit code and 64 bit code, (see the document "Using as The GNU Assembler"), how can I achieve this for c files? Or are there any examples to tell me to achieve this?
>>>
>>> Thanks.
>>> Qing
>>
>> What architecture?
>>
>> What do you mean by "32 bit c code" versus "64 bit c code"? If I compile
>> with the -m32 option I get 32-bit code, and with -m64 I get 64-bit code.
>>
>> If you are using the x86 architecture, mixing 32-bit functions with
>> 64-bit functions simply does not work. Arguments are passed on the stack
>> in 32-bit, but in registers (the first six arguments) in 64-bit.
>>
>> --Bob
>>
>>
> Thank you for the response.
> I am sorry. Maybe I explained unclearly.
>
> I am using x86 system, under 2.6.23.1-42.fc8 x86_64, and using gcc to compile the probject by "-m32". However, I have some code compiled as 64 bit by -m64, because I need to switch into 64 mode and call some functions in 64 bit code. The purpose is I need the functions to access the memory above 64G, as you know in 32 bit mode, the memory above 64G can't be accessed.
>
> If they are not c files but assembly, I can use .code64 to distinguish some code compiled as 64 bit.
> I wish to find a way for c files, which has the same functionality as .code16/.code32/.code64 in assembly.
>
> Just curious, does putting asm(".code64") in the beginning of c files work? I saw some code is written like this.
>
> Thanks.
> Qing 		 	   		  
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmailآ®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compile and link 32 bit c code with 64 bit c code‏
  2010-01-06  6:29   ` Qing Wang
@ 2010-01-06  9:17     ` Andrew Haley
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2010-01-06  9:17 UTC (permalink / raw)
  To: gcc-help

On 01/06/2010 06:29 AM, Qing Wang wrote:

> I noticed that if some c files are compiled as 32 bit code by -m32,
> and others are compiled as 64 bit code by -m64, they will not work
> together.

> But can I add something in the c files (say asm(".code64")) and
> compile all of c files by -m32, and then when the program switches
> into 64 bit mode from 32 bit mode, those ".code64" code can work
> properly (i.e. access the memory above 64G)?

This is impossible for lots of reasons, even if you could change the
processor ito 64-bit mode.  You'll only be linking against one libgcc,
and it'll be either the 32- or 64-bit one.  The shared library loader
will expect either 32- or 64-bit code, and so on.  It's easy to
communicate between 32- and 64-bit processes with pipes or shared
memory.

Andrew.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-06  9:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-05  3:47 How to compile and link 32 bit c code with 64 bit c code‏ Qing Wang
2010-01-05 17:59 ` Bob Plantz
2010-01-06  6:21   ` Qing Wang
2010-01-06  6:29   ` Qing Wang
2010-01-06  9:17     ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).