[cfe-dev] Clang, LTO and linking x86_64 with i386

Anatol Pomozov via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 6 10:24:14 PDT 2017


Hi folks

I have an OS for x86_64. Intel hardware has a requirement that early
boot stage can use 32bit instructions only. So I have a boot.c file
that I compile with -m32. Now I want to link it with 64bit code that
the rest of the OS uses. Linkers (at least LD) does not allow to link
different architectures. Thus I have to use a trick with 'objcopy' to
convert elf32 object file into elf64 (objcopy -O elf64-x86-64). It
works with clang if I do not use LTO (I tested the output binary with
KVM/VmWare and bare metal).

Now I want to enable LTO for my project. Unfortunately object files
compiled with 'clang -flto' have different type:

 file arch/x86/start.o32
 arch/x86/start.o32: LLVM IR bitcode

And it confuses 'objcopy'

objcopy:start.o32: File format not recognized


So my question here: is there a way to enable LTO in a project that
tries to link 32bit and 64bit object files? Is there other way to
achieve it without using 'objcopy'?



More information about the cfe-dev mailing list