Good question. If you insist on including binutils in the flow one thing that seems to work on both new and older versions is to always use gas and ld:
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 -Us system.pas
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 uefimain.pas
x86_64-w64-mingw32-ld --gc-sections --oformat pei-x86-64 uefimain.o uefi.o system.o -e efi_main -o MAIN.EFI
That works here with -Cg and -r as well:
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 -Cg -Us system.pas
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 -Cg uefimain.pas
x86_64-w64-mingw32-ld --gc-sections -r --oformat pei-x86-64 uefimain.o uefi.o system.o -e efi_main -o MAIN.EFI
Thank you,I edited your shell code and my UEFI program successfully show "Hello UEFI!"(Must use x86_64-w64-mingw32-ld to link all object files to PE dll,and then use objcopy to create UEFI bootable file to execute in the bare UEFI machine).My edited code is based on the code your post,It Is:
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 -Cg -Us system.pas
fpc -XPx86_64-w64-mingw32- -Aas -n -O4 -Si -Sc -Sg -Xd -CX -XXs -Px86_64 -Rintel -Twin64 -Cg uefimain.pas
x86_64-w64-mingw32-ld --gc-sections -shared -Bsymbolic -nostdlib --oformat pei-x86-64 uefimain.o uefi.o system.o -e efi_main -o main.dll
objcopy -I pei-x86-64 -O efi-app-x86_64 main.dll bootx64.efi
(-Bsymbolic and -nostdlib is optional)