$ make
ld -nostdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic -L /usr/lib -L /usr/lib /usr/lib/crt0-efi-x86_64.o main.o -o hello.so -lefi -lgnuefi
ld: /usr/lib/crt0-efi-x86_64.o: relocation R_X86_64_PC32 against undefined symbol `efi_main' can not be used when making a shared object; recompile with -fPIC
ld: final link failed: Bad value
Makefile:25: recipe for target 'hello.so' failed
make: *** [hello.so] Error 1
$ cat main.cpp
#include <efi.h>
#include <efilib.h>
EFI_STATUS b(ImageHandle, SystemTable);
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
InitializeLi
Print(L"Hello, world!\n");
return EFI_SUCCESS;
}
$ cat Makefile 86,ia32, )
ARCH = $(shell uname -m | sed s,i[3456789]
OBJS = main.o
TARGET = hello.efi
EFIINC = /usr/include/efi /protocol /crt0-efi- $(ARCH) .o /elf_$( ARCH)_efi. lds
EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)
LIB = /usr/lib
EFILIB = /usr/lib
EFI_CRT_OBJS = $(EFILIB)
EFI_LDS = $(EFILIB)
CXXFLAGS = $(EFIINCS) -fno-stack- protector -fpic \
-fshort- wchar -mno-red-zone -Wall WRAPPER
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_
endif
LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
-Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
all: $(TARGET)
hello.so: $(OBJS)
ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
%.efi: %.so
--target= efi-app- $(ARCH) $^ $@
objcopy -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
clean :
rm -rf $(TARGET) $(OBJS)
realclean: clean
$ make elf_x86_ 64_efi. lds -shared -Bsymbolic -L /usr/lib -L /usr/lib /usr/lib/ crt0-efi- x86_64. o main.o -o hello.so -lefi -lgnuefi crt0-efi- x86_64. o: relocation R_X86_64_PC32 against undefined symbol `efi_main' can not be used when making a shared object; recompile with -fPIC
ld -nostdlib -znocombreloc -T /usr/lib/
ld: /usr/lib/
ld: final link failed: Bad value
Makefile:25: recipe for target 'hello.so' failed
make: *** [hello.so] Error 1