Page 1 of 1

Error while linking with gnuefi

Posted: Sat May 14, 2016 2:44 pm
by heat
Hello OSDevers,

Today I went experimenting with UEFI for a new OS I'm writting. Everything went pretty well until just after I added code to read the disk to load the kernel, that stuff started to go wrong. My linker refused to link with this error:

Code: Select all

/usr/local/lib/libefi.a(dpath.o): could not read symbols: Invalid operation
I searched around for solutions to the error, but all I could find was wrong link order and people forgetting the library in the command line. I tried changing the link order but nothing worked.

The command used for linking is this:

Code: Select all

x86_64-w64-mingw32-gcc -Iinc -Iinc/x86_64 -Iinc/protocol -L/usr/local/lib -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -o BOOTX64.EFI entry.c kernel_loader.c  -lefi -lgnuefi -lgcc
I even recompiled the gnuefi and tried to use that instead of the fedora package(that's why the -L/usr/local/lib is there), but it made no difference.
I should mention that I'm compiling for x86_64 with the mingw compiler supplied by my distro's package(so there should be no problems there).

Thanks alot,
TheRussianFail

Re: Error while linking with gnuefi

Posted: Sat May 14, 2016 3:20 pm
by max
That error can for example occur when you compiled the objects for a different architecture than the one you're trying to link for.

You should build a cross toolchain and then build gnuefi with that toolchain. Don't use the mingw32 supplied compiler, that's not what you want for compiling freestanding stuff (like your kernel).

Re: Error while linking with gnuefi

Posted: Sat May 14, 2016 3:35 pm
by heat
max wrote:That error can for example occur when you compiled the objects for a different architecture than the one you're trying to link for.

You should build a cross toolchain and then build gnuefi with that toolchain. Don't use the mingw32 supplied compiler, that's not what you want for compiling freestanding stuff (like your kernel).
I didn't build a cross-compiler because I don't know what is the target for UEFI. Mingw32 was used in the UEFI bare-bones so I tried using it. But now it makes sense. Gnuefi is built for elf IIRC.

Re: Error while linking with gnuefi

Posted: Fri May 20, 2016 5:44 am
by jnc100
The mingw toolchains are an appropriate choice for UEFI development, as per the bare bones pages. If you're doing it that way, you only need the header files from gnuefi, rather than the library itself. If you want to use functions (e.g. DevicePath stuff) from the Intel EDK library (as is included in the lib/ subdirectory of the gnu-efi sources), then you can simply include the appropriate .c files in your project.

Don't try and use libgnuefi directly - it is specifically designed to compile as an ELF, link with an ELF kernel and then be objcopied to a PE file within the gnuefi toolchain.

Regards,
John.