LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-13-2007, 11:38 AM   #1
eichmen
LQ Newbie
 
Registered: Mar 2007
Posts: 7

Rep: Reputation: 0
Gcc Assembler And Link


Hello. I have to modify a .c file in assembler of a big application. However I want to know if the gcc can convert many .c files into a only one .s file ( for example, in a Makefile it ;s possible to convert a lot of .c files into a executable file). It's due I have to test the whole application in assembler.
Thank you
 
Old 04-14-2007, 09:38 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
All those .c files are converted into a single executable not by the compiler itself, but by the linker (ld) after the compiler is finished producing one .o file for each .c file.

As far as I know, there is no way to ask the compiler to compile all the .c files, producing assembly language output, and produce one assembly language file.

If this is really important to you, try one of two things. I'll give the more complex thing to try first, then the less complex.

The more complex thing:

Create an empty directory. Put in it a few .c files which, together, form a program. Put two functions in each one. Design the program so that when you run it, every function in every file gets called. (These can be very trivial functions.) Make sure that main() is defined in one and only one file.

Then compile these files and make sure the program runs.

Then compile these files with the -S option. The compiler will go as far as producing assembly language source and then stop.

Examine the assembly language files and see whether there's a way you can massage them into one assembly language file that you can do a "gcc" on and get a runnable program.

Then apply the lessons learned to your larger project.

If you choose to do this, then the yellow brick road you will be walking is a long, long yellow brick road.

The less complex thing:

Combine all your .c files into one .c file. Centralize all your #includes; no need to include any of them more than once. Get rid of any #include that includes one of those .c files you're combining. Compile the combined source file, just to make sure it actually compiles ok.

Then compile it with -s, and you have your source.

Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 04-14-2007 at 09:43 AM.
 
Old 04-15-2007, 10:15 AM   #3
eichmen
LQ Newbie
 
Registered: Mar 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you for your response but it doesnīt resolve my problem.I think I wasnīt very especific in the definition of my problem. I have to change a function in the mpeg2 application. Then I have to modify this function in assembler to change the assembler code for mmx code to accelerate the function. I have the function in mmx assembler but now I donīt now how to insert this assembler mmx code into the whole application to see the improvement of this modification with the gprof.

Thank and Iīm sorry if I didnīt explain very well the first time
 
Old 04-16-2007, 08:43 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Please tell me if I understand this correctly.

Let's say there's a file, fred.c, which consists of the function of interest. You already have the assembler source for that function, carefully handcrafted for optimization.

Put that assembler source in fred.s (or, if you want gcc to do preprocessing on the file to handle #-type stuff such as #include, put it in fred.S (upper case)).

Then compile the whole package, using fred.[sS] instead of fred.c.

Is this any closer?
 
Old 04-17-2007, 08:14 AM   #5
eichmen
LQ Newbie
 
Registered: Mar 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Ok, Thanks you
I insert the assembler code .s into the makefile in the OBJ list and I delete the .o
Then I compile and it works!!!!
Thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use ld to link two .o gcc generated files? thomasmathew Programming 1 04-07-2006 02:39 AM
problem when trying to static link with gcc glvgfz Programming 11 09-18-2005 08:58 PM
How to link a library to gcc? Andrea_81 Programming 6 05-05-2005 05:22 AM
gcc link question eskimo22 Programming 2 03-03-2004 04:09 AM
Link errors from gcc CraigN Programming 2 02-27-2003 08:43 PM


All times are GMT -5. The time now is 10:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration