Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHIM fork for native DLL compilation #151

Open
rusnikola opened this issue Oct 30, 2018 · 2 comments
Open

SHIM fork for native DLL compilation #151

rusnikola opened this issue Oct 30, 2018 · 2 comments

Comments

@rusnikola
Copy link

rusnikola commented Oct 30, 2018

Hi

Just wanted to make an announcement that I created a new branch: https://github.com/rusnikola/shim which enables native DLL compilation and completely removes any dependencies on gnu-efi, libgcc, etc. I added all required library functions (printf, memcpy, memset, StrCpy, StrCat, etc), changed Makefiles to use clang to compile PE/COFF DLLs. Then I also included the FwImage tool which I have ported long time ago from Windows to Linux/POSIX which converts DLL to EFI.
I have tested compilation for X64 and IA32; ARM/AArch64 should probably be OK. I have done some testing on X64.

One of the biggest advantages is that it uses official TianoCore headers rather than gnu-efi. Also, file sizes are greatly reduced now. Compiled files are truly PE/COFF per UEFI spec rather than ELFs hidden inside PE/COFF stubs. Compiled shim is now ~425Kb (instead of 1Mb) due to much better elimination of unused OpenSSL code during linking!

See all distinctive features below. If there is any interest to merge changes in one way or another to the main (official) branch, please let me know. (e.g., creating shim-experimental or something like this)

Make sure to use clang 7.0 or higher. Edit Makefiles accordingly to specify correct paths to clang and lld-link.

Note: It uses EFIAPI / MS ABI calling convention for all platforms other than IA32. For IA32, it uses -mregparm=3 -mrtd for internal functions and EFIAPI for external ones. To preserve backward compatibility when overriding security policy, it uses SysV calling convention for X64 for those 3 exported functions only.

Distinctive Features:

  1. Completely standalone, i.e. does not require the gnu-efi library. To access
    UEFI interfaces, it is using official Edk2/TianoCore headers.
  2. Native UEFI PE/COFF (DLL) compilation using out-of-box clang/llvm
    (or, potentially, the mingw-gcc cross-compiler) instead of creating
    internally relocatable ELF objects with PE/COFF wrapper stubs (gnu-efi).
  3. The Edk's FwImage tool (which I ported from Windows to Linux/POSIX)
    converts DLL to EFI.
  4. Using smarter linking with llvm's PE/COFF lld-link to prune all unused
    functions/objects in the OpenSSL library.
  5. Added own printf, string, memory, etc implementations to substitute
    functions previously imported from gnu-efi.
  6. As the result, substantially reduced footprints of EFI files
    (e.g., 425Kb vs 1Mb for shimx64.efi compiled with -Os).
  7. Fixed some bugs, removed a lot of copy&paste code from TianoCore
    (official TianoCore headers are now used anyway) and added other
    improvements to the code.

Requirements:
clang/llvm/lld 7.0.0+ (needs the -mno-stack-arg-probe flag)
Official binaries for various Linux distributions are available at
http://releases.llvm.org/download.html

  • Ruslan Nikolaev
@rusnikola rusnikola changed the title SHIM fork with native DLL compilation SHIM fork for native DLL compilation Oct 30, 2018
@rusnikola
Copy link
Author

I have merged latest rhboot's master changes.

@rusnikola
Copy link
Author

Merged latest master branch changes and created a pull request:
#235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant