uefi: undefined reference to [EFI functions] when linking
Posted: Fri Nov 06, 2020 2:49 pm
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:
My compile options:
Quite stumped on this issue, didn't have this issue in my original UEFI app.
GitHub repo: https://github.com/microNET-OS/microCORE
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'
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
GitHub repo: https://github.com/microNET-OS/microCORE