LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-18-2009, 01:32 PM   #1
celticfutballer
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Rep: Reputation: 0
converting compiled 'o' files to another format


I have a library containing numerous *.o files. These are files that were written by a coworker some time back and the source code has since been lost. They work fine with my current linux distro but I'd like to use these on another platform.

These files are compiled for elf32-i386 architecture. What I'd like to do is make them work on an ARM platform which requires they be elf32-littlearm. Is there any hope of doing this? (I basically used objdump to figure out the architectures and tried to use objcopy to convert them)

I'd rather not rewrite the code as it took this guy quite some time to get all the bugs out and quite frankly, I don't think I could recreate what he did.
 
Old 12-18-2009, 02:11 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
Will objcopy help; it claims it can translates object files http://linux.die.net/man/1/objcopy and http://sourceware.org/binutils/docs/...s/objcopy.html.

Last edited by harry edwards; 12-18-2009 at 02:13 PM.
 
Old 12-18-2009, 02:31 PM   #3
celticfutballer
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
That the command I've been really trying to figure out. I've got two versions of the command, one that comes stock with my distro, the other came with the ARM system I'm using.

I can't do a straight conversion from elf32-i386 to elf32-littlearm because the standard objcopy doesn't support the arm architecture. So I've to use the standard objcopy to convert to elf32-little and then the other objcopy to convert that to elf32-littlearm

The problem is that the standard objcopy returns with a segmentation fault with the following command

objcopy -I elf32-i386 -O elf32-little /PATHTOFILETOCONVERT /PATHTOUTPUT

My next thought was to convert to binary first and then binary to elf32-little, but that failed as well. the commands ran, but the output files were not any good (i.e. all the symbol info was gone).

I've considered decompilers as well, but the only that looked promising (boomerang) and worked on other code did not work on this code (I think it only works on c, not c++). I've not found any other decompilers that would work.

So yes, I think objcopy is the way to go, I just can't get it to do what I want. I've also tried the 'strip' command but had similar results.

It may just be that I'm not understanding the commands so any other input on objcopy to meat this end would be welcome.

or any other methods would be welcome too.
 
Old 12-18-2009, 03:01 PM   #4
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
What about objdump. This can disassemble .o files into assembly. You may be able to compile the assembly on your new machine http://wiki.multimedia.cx/index.php?title=Objdump
 
Old 12-18-2009, 05:34 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by harry edwards View Post
What about objdump. This can disassemble .o files into assembly. You may be able to compile the assembly on your new machine http://wiki.multimedia.cx/index.php?title=Objdump
Unlikely. The instruction set for the i386 CPU is different from the ARM CPU. Disassembly of object code will only get you assembler code for the '368. Converting that to ARM assembly code will be significantly difficult. The easiest solution to the OP's problem is probably to re-write from scratch.
The file format of the object code is only a small part of the compatibility issue.
--- rod.
 
Old 12-19-2009, 02:22 PM   #6
celticfutballer
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
ok, so the difference between the architectures is not just a format thing, but an instruction set thing as well?

That makes sense when I step back and think about it. I was hoping it would be a matter of simply rearranging bits but if I've also to interpret the varying commands, it probably would be better to just do a rewrite.

As I played around with this, I've made some good progress for c code (as opposed to c++) on this end. I've been able to use a decompiler to get c files of a 386 'o' file and then recompile it using my arm cross compiler. However, the o files I've got are c++ I've determined, so without a c++ decompiler, I'll be stuck with a rewrite I think.

Thanks for the tips, if theres any other ideas let me know, this is one of the problems that is fun to play with.
 
Old 12-19-2009, 07:04 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
That is right. If it were any other way, we would not need cross compilers. The beauty of Java is that it does run java bytecode on any platform, as long as it has a Java virtual machine to run it.
--- rod.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a compiled program in tgz format into an rpm package. xode Linux - Software 1 01-04-2008 12:54 PM
LXer: Converting All Your MS Outlook PST Files To Maildir Format LXer Syndicated Linux News 0 06-15-2007 01:31 PM
Converting .bin/.cue files into .iso/.cdr format Iltbreg Linux - General 3 08-25-2006 05:30 PM
converting image files to eepic format natashadams Linux - Software 0 02-15-2006 04:55 PM
converting files to pdf format? vendemmian Linux - General 2 05-23-2001 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration