Error while linking with gnuefi

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

Error while linking with gnuefi

Post 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
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Error while linking with gnuefi

Post 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).
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

Re: Error while linking with gnuefi

Post 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.
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Error while linking with gnuefi

Post 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.
Post Reply