Re: editing ELF file

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

 





On Tue, May 6, 2008 at 6:17 PM, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote:


On Wed, May 7, 2008 at 5:20 AM, tejas khatiwala <socretez@xxxxxxxxx> wrote:


On Tue, May 6, 2008 at 7:34 AM, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote:
First at the hardware level:   AMD64 has a few mode, among them pure
64-bit, pure 32bit, mixed 64-32-bit, and etc.   So theoretically at
the assembly level, u can still run 32bit assembly a 64-bit CPU.

2nd, at the software level (essentially:  it is possible to run 32bit
in 64bit environment.....done by the different distros as below):

http://www.redhat.com/magazine/009jul05/features/multilib/
http://www.debian-administration.org/articles/534
http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.2/suselinux-adminguide_en/ch06.html
http://www.scribd.com/doc/363677/Benchmarks-AMD64-in-32bit-mode-vs-64bit-mode-Ubuntu
https://help.ubuntu.com/community/32bit_and_64bit

How all these work (*I think*) is basically having a 64-bit shell
(windows is called WOW64 http://en.wikipedia.org/wiki/WOW64) that can
switch to 32 bit mode to run the program, and therefore everything
inside that process are running at 32bit, and vice versa.   Some
binary-only applications (like Flash) may not have 64-bit version, and
therefore the browser have to be 32bit.

But all kernel modules/kernel development (*I think*) must be done in
a 64bit environment....unless there exists a 32bit kernel wrapper in
64bit kernel which i am not aware of.

I suspect I may have misunderstood u...in view of what is written
above please elaborate your requirements????

I am working on a 32-bit BIOS that is running on 32-bit hardware and as further development we want to test 64-bit processors (new

BIOS!!!   So I guessed u don't have the luxury of system call like "fork()" or "exec()" API in C right?   But if u call your BIOS test program at the command line level, then u have a shell.....and so inside your C u can do a fork().

I'm not sure if I can use fork and exec but assuming that I can, I still need to have the 64-bit executable somewhere in the BIOS file. So I will have to copy that file manually to final BIOS file so that my 32-bit file can jump to that (already known) address.


(because if u have ....then inside a 32bit program, just call fork() on a 64bit program....and all the loading stuff is handled at the shell level....64bit loader will load the binary + 64bit libraries and create the 64 bit elf image etc.  )

Alternatively, if u are running it straight from bootup, then u can compile your codes as 32bit STATIC program (so all 32bit libraries are included), and then compile 64bit as STATIC as well.   And combine two together....lots of details when combining...

This combining is same as option 3) I mentioned in earlier email. I know and have tested little bit of combining 2 binary image and make it work and both of your solutions seem to be "combining" solutions. But if you mean "linking" by combining then I'd be really interested.

thanks,

/tejas
 
but we can discuss this privately....
 
Xeon chips). The problem is, I cannot recompile BIOS to 64-bit mode due to compatibility reasons. So the requirement is to call 64-bit code from a 32-bit code. There were 3 ways I could have made this work:

1) Compile 32-bit BIOS and 64-bit code separately and try to link them with some modification (if any) I asked earlier in this forum.
2) Call an assembly file from 32-bit code. This assembly file will make transition from 32-bit to 32e (64-bit) mode and call the function in 64-bit code, comes back and makes the transition back to 32-bit mode. Here, again the problem remains the same. The assembly file will be compiled either 32-bit or 64-bit and there's no way I can link all 3 files together.
3) Compile and lijnk 32-bit C and asm files as one file; compile 64-bit C file separately and put the object code into a file at known addresses. Make the 32-bit linked file jump to the address of 64-bit file and come back.

Though, I haven't tried but I think I can make 3) work but that is my last resort and I want to find out some way to be able to compile and link 32-bit and 64-bit mode code together or be able to call 64-bit code (64 or 32-bit ELF header) from 32-bit code (32-bit ELF header).

Please help me with this and correct me if I have some misunderstanding about ELF headers.

/tejas



On Tue, May 6, 2008 at 2:14 AM, tejas khatiwala <socretez@xxxxxxxxx> wrote:
> Hello,
>
> This is not exactly relevant to Linux kernel but I'm gonna ask any way.
>
> Is there any way I can modify a 64-bit ELF object file to make it look like
> 32-bit ELF object file and link it (using `ld`) with 32-bit ELF file?
>
> I tried libelf but was unsuccessful. I had this pretty link
> http://people.freebsd.org/~jkoshy/download/libelf/article.html from Freebsd
> website and it seems like the libelf library on Freebsd system is not
> similar to that on Linux system as it complained for "vis.h" headerfile and
> few library calls such as `elf_setshstrndx()`
>



--
Regards,
Peter Teoh


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux