uefi: undefined reference to [EFI functions] when linking

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
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

uefi: undefined reference to [EFI functions] when linking

Post by austanss »

I copied someone's UEFI bootloader from GitHub. Now before you go telling me how I should just use GRUB or something else instead, let me explain that I copied it so I could have easy access to the source, while having a minimal bootloader. As well, this bootloader came with an example kernel that explained how to print text, so yay.

However when compiling the bootloader I get numerous link errors:

Code: Select all

/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x67): undefined reference to `VSPrint'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0xae): undefined reference to `Print'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0xcd): undefined reference to `VPrint'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x130): undefined reference to `efi_call5'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x1a0): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x20e): undefined reference to `efi_call5'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x2ce): undefined reference to `InitializeLib'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x301): undefined reference to `efi_call4'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x35c): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x434): undefined reference to `efi_call6'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x516): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x63f): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/main.o:main.c:(.text+0x712): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x8e): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x10a): undefined reference to `efi_call4'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x18a): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x1f3): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x262): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x2bc): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x353): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x6b2): undefined reference to `efi_call5'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x771): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x880): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x8da): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/loader.o:loader.c:(.text+0x931): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0x9da): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xa95): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xafa): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xbbc): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xc29): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xc8b): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xd02): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xd67): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/elf.o:elf.c:(.text+0xdc9): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/error.o:error.c:(.text+0x1b): undefined reference to `StatusToString'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/fs.o:fs.c:(.text+0x43): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/graphics.o:graphics.c:(.text+0x27): undefined reference to `efi_call1'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/graphics.o:graphics.c:(.text+0x269): undefined reference to `efi_call4'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/graphics.o:graphics.c:(.text+0x383): undefined reference to `efi_call5'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/graphics.o:graphics.c:(.text+0x447): undefined reference to `efi_call2'
/usr/bin/x86_64-w64-mingw32-ld: /usr/lib/crt0-efi-x86_64.o: in function `_start':
(.text+0x9): undefined reference to `ImageBase'
/usr/bin/x86_64-w64-mingw32-ld: (.text+0x10): undefined reference to `_DYNAMIC'
/usr/bin/x86_64-w64-mingw32-ld: (.text+0x19): undefined reference to `_relocate'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/serial.o:serial.c:(.text+0x58): undefined reference to `efi_call7'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/serial.o:serial.c:(.text+0xd8): undefined reference to `efi_call3'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/serial.o:serial.c:(.text+0x18b): undefined reference to `StrLen'
/usr/bin/x86_64-w64-mingw32-ld: bin/obj/serial.o:serial.c:(.text+0x1eb): undefined reference to `efi_call3'
My compile options:

Code: Select all

bootloader:
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/loader.c -o $(OBJ_DIR)/loader.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/data.c -o $(OBJ_DIR)/data.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/elf.c -o $(OBJ_DIR)/elf.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/error.c -o $(OBJ_DIR)/error.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/fs.c -o $(OBJ_DIR)/fs.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/graphics.c -o $(OBJ_DIR)/graphics.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/main.c -o $(OBJ_DIR)/main.o
	$(MINGW) -c $(BOOTLOADER_SRC_DIR)/serial.c -o $(OBJ_DIR)/serial.o
	# ld  -nostdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic -L /usr/lib -l:libgnuefi.a -l:libefi.a -o main.so
	# objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc --target=efi-app-x86_64 main.so main.efi
	x86_64-w64-mingw32-gcc -nostdlib -shared -Wl,--subsystem,10 -e efi_main -o bootloader.efi $(OBJ_DIR)/main.o $(OBJ_DIR)/loader.o $(OBJ_DIR)/data.o $(OBJ_DIR)/elf.o $(OBJ_DIR)/error.o $(OBJ_DIR)/fs.o $(OBJ_DIR)/graphics.o /usr/lib/crt0-efi-x86_64.o $(OBJ_DIR)/serial.o -lgcc
Quite stumped on this issue, didn't have this issue in my original UEFI app.

GitHub repo: https://github.com/microNET-OS/microCORE
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: uefi: undefined reference to [EFI functions] when linkin

Post by Octocontrabass »

You're using a PE toolchain with the Microsoft ABI, but gnu-efi is designed for an ELF toolchain with the System V ABI.

You'll need to adapt the code to work without gnu-efi. Mostly that means replacing uefi_call_wrapper() with direct function calls, but you might also need to find (or write) new UEFI headers.
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: uefi: undefined reference to [EFI functions] when linkin

Post by austanss »

I fixed the compiling options but now I get this error:
Attachments
unknown.png
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: uefi: undefined reference to [EFI functions] when linkin

Post by nexos »

Run QEMU with -net none. Then it will drop you to the EFI shell.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: uefi: undefined reference to [EFI functions] when linkin

Post by austanss »

I try to manually run my EFI application, I get this error:
unknown.png
I believe it is a compiling error, I simplified the code to a simple "Hello" and it still doesn't work.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: uefi: undefined reference to [EFI functions] when linkin

Post by zaval »

I fixed the compiling options
seems, you didn't. show your boobs compiling options. your qemu is qemu-system-x86_64?

PS. 232 bytes, man, I bet it's not even a proper PE file. are you on Windows? try dumpbin /headers on your "efi" file.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: uefi: undefined reference to [EFI functions] when linkin

Post by austanss »

zaval wrote:
I fixed the compiling options
seems, you didn't. show your boobs compiling options. your qemu is qemu-system-x86_64?

PS. 232 bytes, man, I bet it's not even a proper PE file. are you on Windows? try dumpbin /headers on your "efi" file.
No, I'm using Linux (ubuntu).

The new compiling options are on GitHub, yes my qemu is x86_64
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: uefi: undefined reference to [EFI functions] when linkin

Post by austanss »

OK, I'm just stupppuid. I forgot to link the object files together omfg. it loads and starts now i just have some runtime errors i need to fix
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
Post Reply