<div dir="ltr"><div>Right. But as I said, GCC and Clang depend on 4 standard C library functions. This behavior is documented, and has been stable for probably the past decade or more. These are not intrinsics, but bog standard functions you can totally redirect to the existing UEFI ones. I talked with the LLVM people on IRC and they confirmed that that was essentially the reason why it used a memcpy call.<br></div><div><div>It's, in my opinion, OK to fix this particular issue if for example Visual Studio does something fancier or requires actual intrinsics, but having support for this would probably better solidify future compilation using GNU-like toolchains.</div></div><div><br></div><div>Slightly offtopic, but I would dare to say that moving towards memcpy() and others(versus CopyMem(), etc) would benefit EDK2 generated ASM quality as the compiler has more of an idea of what you want to accomplish, if you pass -fbuiltin and let it assume your standard C library has the correct behavior; and indeed, GCC and Clang can, for instance, transform memcpy() calls into rep movsb's or whatnot based on the CPU microarch it's compiling for, or completely alias them if it sees you're doing it because of pointer aliasing.</div><div><br></div><div>Thanks,</div><div>Pedro<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 25, 2022 at 11:58 PM Yao, Jiewen <<a href="mailto:jiewen.yao@intel.com">jiewen.yao@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div style="overflow-wrap: break-word;" lang="EN-US">
<div class="gmail-m_2383285523218063014WordSection1">
<p class="MsoNormal">“Don’t use structure assignment” is our best known method to avoid compiler intrinsic in EDKII coding style since the project is created.<u></u><u></u></p>
<p class="MsoNormal">A third part library may include structure assignment, then we have to link intrinsic.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">If you only talk about memcpy, that is easy. But there might be others. The problem is: We don’t know how many intrinsic should be there. It is fully based upon compiler.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Gerd proposed to move to intrinsic from cryptopkg to mdepkg. But it is not done yet.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">To me, using MemCopy is much easier to resolve this problem.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thank you<u></u><u></u></p>
<p class="MsoNormal">Yao Jiewen<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> <a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a> <<a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a>> <b>
On Behalf Of </b>Pedro Falcato<br>
<b>Sent:</b> Thursday, May 26, 2022 6:48 AM<br>
<b>To:</b> Yao, Jiewen <<a href="mailto:jiewen.yao@intel.com" target="_blank">jiewen.yao@intel.com</a>><br>
<b>Cc:</b> Ard Biesheuvel <<a href="mailto:ardb@kernel.org" target="_blank">ardb@kernel.org</a>>; edk2-devel-groups-io <<a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a>>; Rebecca Cran <<a href="mailto:quic_rcran@quicinc.com" target="_blank">quic_rcran@quicinc.com</a>>; Ard Biesheuvel <<a href="mailto:ardb%2Btianocore@kernel.org" target="_blank">ardb+tianocore@kernel.org</a>>; Justen, Jordan L <<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>>; Gerd Hoffmann <<a href="mailto:kraxel@redhat.com" target="_blank">kraxel@redhat.com</a>><br>
<b>Subject:</b> Re: [edk2-devel] OvmfPkgX64 doesn't build with CLANG38 (clang 14.0.3) NOOPT - undefined reference to `memcpy'<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Is there a legitimate reason not to define memcpy? It'd be easier to do so and comply to the compiler's requirements.<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, 25 May 2022, 23:38 Yao, Jiewen, <<a href="mailto:jiewen.yao@intel.com" target="_blank">jiewen.yao@intel.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi<u></u><u></u></p>
<p class="MsoNormal">Would you please use CopyMem() for the structure assignment?<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:Consolas;color:rgb(36,41,47);background:rgb(255,248,197) none repeat scroll 0% 0%">VgpuGop-></span><span class="gmail-m_2383285523218063014m-3430618123631817974pl-smi"><span style="font-size:9pt;font-family:Consolas;color:rgb(36,41,47)">GopModeInfo</span></span><span style="font-size:9pt;font-family:Consolas;color:rgb(36,41,47);background:rgb(255,248,197) none repeat scroll 0% 0%"> 
 = *GopModeInfo;</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">That is best known method to resolve memcpy symbol issue.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:Consolas;color:rgb(36,41,47);background:rgb(255,248,197) none repeat scroll 0% 0%">Thank you</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:Consolas;color:rgb(36,41,47);background:rgb(255,248,197) none repeat scroll 0% 0%">Yao Jiewen</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Pedro Falcato <<a href="mailto:pedro.falcato@gmail.com" target="_blank">pedro.falcato@gmail.com</a>>
<br>
<b>Sent:</b> Thursday, May 26, 2022 1:01 AM<br>
<b>To:</b> Ard Biesheuvel <<a href="mailto:ardb@kernel.org" target="_blank">ardb@kernel.org</a>><br>
<b>Cc:</b> edk2-devel-groups-io <<a href="mailto:devel@edk2.groups.io" target="_blank">devel@edk2.groups.io</a>>; Rebecca Cran <<a href="mailto:quic_rcran@quicinc.com" target="_blank">quic_rcran@quicinc.com</a>>; Ard Biesheuvel <<a href="mailto:ardb%2Btianocore@kernel.org" target="_blank">ardb+tianocore@kernel.org</a>>;
 Yao, Jiewen <<a href="mailto:jiewen.yao@intel.com" target="_blank">jiewen.yao@intel.com</a>>; Justen, Jordan L <<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>>; Gerd Hoffmann <<a href="mailto:kraxel@redhat.com" target="_blank">kraxel@redhat.com</a>><br>
<b>Subject:</b> Re: [edk2-devel] OvmfPkgX64 doesn't build with CLANG38 (clang 14.0.3) NOOPT - undefined reference to `memcpy'<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Wed, May 25, 2022 at 5:45 PM Ard Biesheuvel <<a href="mailto:ardb@kernel.org" target="_blank">ardb@kernel.org</a>> wrote:<u></u><u></u></p>
<div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal">On Wed, 25 May 2022 at 18:44, Pedro Falcato <<a href="mailto:pedro.falcato@gmail.com" target="_blank">pedro.falcato@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Wed, May 25, 2022 at 4:50 PM Ard Biesheuvel <<a href="mailto:ardb@kernel.org" target="_blank">ardb@kernel.org</a>> wrote:<br>
>><br>
>> On Wed, 25 May 2022 at 17:08, Rebecca Cran <<a href="mailto:quic_rcran@quicinc.com" target="_blank">quic_rcran@quicinc.com</a>> wrote:<br>
>> ><br>
>> > I noticed OvmfPkg/OvmfPkgX64.dsc doesn't build with `-t CLANG38 -b<br>
>> > NOOPT` (with clang version 14.0.2) with the latest edk2 master<br>
>> > (07c0c2eb0a5970db614ebce1060fc79d6904bdfd):<br>
>> ><br>
>> > make: Nothing to be done for 'tbuild'.<br>
>> > /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value:<br>
>> > 0x23<br>
>> > /home/bcran/src/upstream/uefi/edk2/Build/OvmfX64/NOOPT_CLANG38/X64/OvmfPkg/VirtioGpuDxe/VirtioGpu/OUTPUT/VirtioGpuDxe.lib(Gop.obj):<br>
>> > in function `GopSetMode':<br>
>> > Gop.c:(.text.GopSetMode+0x418): undefined reference to `memcpy'<br>
>><br>
>> Can you dump the object file to see where the memcpy() call is emitted?<br>
><br>
> I think I found the smoking gun: <a href="https://github.com/tianocore/edk2/blob/916f90baa547b3ebef8fa87c530e2f0c8e35e1e3/OvmfPkg/VirtioGpuDxe/Gop.c#L512" target="_blank">
https://github.com/tianocore/edk2/blob/916f90baa547b3ebef8fa87c530e2f0c8e35e1e3/OvmfPkg/VirtioGpuDxe/Gop.c#L512</a><br>
<br>
Indeed. We don't support struct assignment in Tianocore code, exactly<br>
for this reason.<u></u><u></u></p>
</blockquote>
</div>
<div>
<p class="MsoNormal">Note: We should think about providing some basic libc functions in base EDK2 as some are required by the clang/GCC compilers (see
<a href="https://gcc.gnu.org/onlinedocs/gcc/Standards.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/Standards.html</a>, grep for memcpy or freestanding).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Passing -ffreestanding would also be a good idea as to let the compiler know it's dealing with a freestanding environment vs a hosted user-space one.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">All the best,<u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Pedro<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<div>
<p class="MsoNormal"><u></u></p>
</div>
</div>
</div>
</div>



  

<p></p><p></p></blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Pedro Falcato</div></div>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/90021">View/Reply Online (#90021)</a> |    |  <a target="_blank" href="https://groups.io/mt/91335000/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>