From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ma1-aaemail-dr-lapp03.apple.com (ma1-aaemail-dr-lapp03.apple.com [17.171.2.72]) by mx.groups.io with SMTP id smtpd.web09.21785.1655404577009090879 for ; Thu, 16 Jun 2022 11:36:17 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=nGGoVeP2; spf=pass (domain: apple.com, ip: 17.171.2.72, mailfrom: afish@apple.com) Received: from pps.filterd (ma1-aaemail-dr-lapp03.apple.com [127.0.0.1]) by ma1-aaemail-dr-lapp03.apple.com (8.16.0.42/8.16.0.42) with SMTP id 25GIDoxm050616; Thu, 16 Jun 2022 11:36:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=20180706; bh=wpxONI6GL+jWqpAfsT0f5a5vFlkP0jXk9RQ/g9FBirs=; b=nGGoVeP2EYuFSC7SE6batfGFaOoomcdJfRezCqyPGMmX+IvWmgUyIiIAAbsJhSsX8cCu ciUqf+ylfGQJF8abTvFfG0gPlU1RyIvz9x7/jDCQBjWe5mVu3cst34+L6PveswnPFgsg H3vAafHdmitVOK+qccFlWVfZBwQuibcRT1m1zAZp+5uLuqdQjAUqh+8QMh3J2K1jeBup Rm8PWNFEphgh24tJiGCY3EGAmcCTULca9ei9PHS4IFC3P2wF+ZH1UD1/IpQ1sQbTelzi /bAzZHpS3NsaNWyQcOz2qalDCnqBtLOcbtGW1ZWm8diLzqnGuXqfCAIplNrt6fbECQ2X 3Q== Received: from rn-mailsvcp-mta-lapp04.rno.apple.com (rn-mailsvcp-mta-lapp04.rno.apple.com [10.225.203.152]) by ma1-aaemail-dr-lapp03.apple.com with ESMTP id 3gmt1xb761-16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 16 Jun 2022 11:36:16 -0700 Received: from rn-mailsvcp-mmp-lapp02.rno.apple.com (rn-mailsvcp-mmp-lapp02.rno.apple.com [17.179.253.15]) by rn-mailsvcp-mta-lapp04.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPS id <0RDL00GKO2CF47B0@rn-mailsvcp-mta-lapp04.rno.apple.com>; Thu, 16 Jun 2022 11:36:15 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp02.rno.apple.com by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) id <0RDL00L001XXGG00@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Thu, 16 Jun 2022 11:36:15 -0700 (PDT) X-Va-A: X-Va-T-CD: 42bcc3738539b68059edd2bc024c3397 X-Va-E-CD: ae56633ac0988984d8019726b6970051 X-Va-R-CD: f240623b8d30901faf9b42b76cdd6616 X-Va-CD: 0 X-Va-ID: 8ad3d46d-ebcf-4552-936b-67881a5d15f0 X-V-A: X-V-T-CD: 42bcc3738539b68059edd2bc024c3397 X-V-E-CD: ae56633ac0988984d8019726b6970051 X-V-R-CD: f240623b8d30901faf9b42b76cdd6616 X-V-CD: 0 X-V-ID: fd570def-307d-4e1e-9c5f-06965c09b405 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-16_14:2022-06-16,2022-06-16 signatures=0 Received: from smtpclient.apple (unknown [17.235.40.218]) by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.18.20220407 64bit (built Apr 7 2022)) with ESMTPSA id <0RDL00TA32CEP700@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Thu, 16 Jun 2022 11:36:15 -0700 (PDT) MIME-version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Subject: Re: [edk2-devel] Does edk2 also link to crt0-efi like GNU-EFI From: "Andrew Fish" In-reply-to: Date: Thu, 16 Jun 2022 11:36:14 -0700 Cc: Michael Kubacki , Mike Kinney , Jiewen Yao , jabeena.b.gaibusab@intel.com Message-id: <4410FE99-43C7-4331-AB96-42ADB294AE30@apple.com> References: To: edk2-devel-groups-io , ayushdevel1325@gmail.com X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517,18.0.883 definitions=2022-06-16_14:2022-06-16,2022-06-16 signatures=0 Content-type: text/plain; charset=utf-8 Content-transfer-encoding: quoted-printable > On Jun 16, 2022, at 7:20 AM, Ayush Singh wrote= : >=20 > Hello everyone, I wanted to ask if the edk2 build system also links to > crt0-efi, like GNU-EFI? >=20 > 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, >=20 The general answer for edk2 is and library that a `CONSTRUCTOR =3D` stateme= nt in its INF that lib constructor will get called when the Driver/App is s= tarted.=20 The actually entry point for a Driver/App is _ModuleEntryPoint(). The typic= al way it is done is this is implemented in a phase specific library[1]. Th= is phase specific basically calls 3 C functions that got generated by the b= uild: ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and P= rocessLibraryDestructorList(). The library constructor/destructors function= s call the lib constructor/destructors function based in the sequence of t= he dependency graph of the libraries that get pulled in.=20 > 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. >=20 If you look in the build output of an edk2 C driver/app you will see an Aut= oGen.h and AutoGen.c file. This was the C code the build system autogenerat= ed to glue everything together. It manages gluing in the libs, abstracting = the PCD implementation, and adding C constants for EFI_GUID values.=20 Sorry I don=E2=80=99t 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=E2=80=99m not sure how you manage dealing with C includes in Rust? With = C++ you can just decorate them.=20 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=20 > My blog post [1] shows how we currently use the `efi_main` function. >=20 > Yours sincerely, > Ayush Singh >=20 > [1]: (https://www.programmershideaway.xyz/post5/) >=20 >=20 [1] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/UefiApplic= ationEntryPoint/ApplicationEntryPoint.c Thanks, Andrew Fish >=20 >=20 >=20