Linking - How to link 32bit and 64bit x86 code into one image
Learned something new from TJ over at Codegen today, he solved a problem where we needed to have 32bit code linked with 64bit code but the linker wouldn’t do it. Apparently this use to work without doing anything, but with the latest linker (ld) code it doesn’t. TJ figured out all that needed to be done was use objcopy to convert the 32bit format to 64bit format:
objcopy -O elf64-x86_64 32bit.o 64bit.o
One other noteworthy element to determine the output formats that objcopy supports use objcopy –info or objcopy –help
wink@ic2d1:$ objcopy --info BFD header file version (GNU Binutils for Ubuntu) 2.18elf64-x86-64 (header little endian, data little endian) i386 elf32-i386 (header little endian, data little endian) i386 a.out-i386-linux (header little endian, data little endian) i386 efi-app-ia32 (header little endian, data little endian) i386 efi-app-x86_64 (header little endian, data little endian) i386 elf64-little (header little endian, data little endian) i386 elf64-big (header big endian, data big endian) i386 elf32-little (header little endian, data little endian) i386 elf32-big (header big endian, data big endian) i386 srec (header endianness unknown, data endianness unknown) i386 symbolsrec (header endianness unknown, data endianness unknown) i386 tekhex (header endianness unknown, data endianness unknown) i386 binary (header endianness unknown, data endianness unknown) i386 ihex (header endianness unknown, data endianness unknown) i386 elf64-x86-64 elf32-i386 a.out-i386-linux efi-app-ia32 i386 elf64-x86-64 elf32-i386 a.out-i386-linux efi-app-ia32efi-app-x86_64 elf64-little elf64-big elf32-little elf32-big i386 efi-app-x86_64 elf64-little elf64-big elf32-little elf32-bigsrec symbolsrec tekhex binary ihex i386 srec symbolsrec tekhex binary ihex