RE: How to compile and link 32 bit c code with 64 bit c code‏

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Subject: Re: How to compile and link 32 bit c code with 64 bit c code‏
> From: plantz@xxxxxxxx
> To: qinggwang@xxxxxxxxxxx
> CC: gcc-help@xxxxxxxxxxx
> 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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux