[edk2-devel] Does edk2 also link to crt0-efi like GNU-EFI

Andrew Fish via groups.io afish=apple.com at groups.io
Thu Jun 16 18:36:14 UTC 2022



> On Jun 16, 2022, at 7:20 AM, Ayush Singh <ayushdevel1325 at gmail.com> wrote:
> 
> Hello everyone, I wanted to ask if the edk2 build system also links to
> crt0-efi, like GNU-EFI?
> 
> If yes, I would also like to see how that is actually implemented. If
> not, how does edk2 support custom entry functions? It is possible with
> llvm backend but I am not sure how it is done in GCC and am curious,
> 

The general answer for edk2 is and library that a `CONSTRUCTOR =` statement in its INF that lib constructor will get called when the Driver/App is started. 

The actually entry point for a Driver/App is _ModuleEntryPoint(). The typical way it is done is this is implemented in a phase specific library[1]. This phase specific basically calls 3 C functions that got generated by the build: ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and ProcessLibraryDestructorList(). The library constructor/destructors functions call the lib  constructor/destructors function based in the sequence of the dependency graph of the libraries that get pulled in. 

> Currently, rust does not support the custom implementation of
> `lang_start` (which is started by crt0 in most platforms), so I was
> trying to find ways to be able to use custom crt0 which sets up
> `SystemTable` and `SystemHandler` and start the `lang_start` from it.
> This way, the user will be able to call the normal `main` function
> rather than using the `no_main` feature.
> 

If you look in the build output of an edk2 C driver/app you will see an AutoGen.h and AutoGen.c file. This was the C code the build system autogenerated to glue everything together. It manages gluing in the libs, abstracting the PCD implementation, and adding C constants for EFI_GUID values. 

Sorry I don’t know Rust yet. Is it possible to call C, EFIABI, from Rust code? If yes maybe what you need is a Rust ModuleEntryPoint that can call the C library constructor and a C EFIABI entry function for your Rust. I’m not sure how you manage dealing with C includes in Rust? With C++ you can just decorate them. 

I guess the other 100% Rust option is to know the INF is building Rust (INF has Code.rs files) and build Rust (or Rust compatible) AutoGen 

> My blog post [1] shows how we currently use the `efi_main` function.
> 
> Yours sincerely,
> Ayush Singh
> 
> [1]: (https://www.programmershideaway.xyz/post5/)
> 
> 

[1] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c

Thanks,

Andrew Fish


> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#90554): https://edk2.groups.io/g/devel/message/90554
Mute This Topic: https://groups.io/mt/91800012/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list