From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id F0A74D80127 for ; Tue, 15 Aug 2023 21:26:29 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6GzVKeky5+v3HAQC7m29AMq/kLfw+C9Quv7YItUULQM=; c=relaxed/simple; d=groups.io; h=From:Message-id:MIME-version:Subject:Date:In-reply-to:Cc:To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-type; s=20140610; t=1692134788; v=1; b=PxCb1FP5bLuUSxVmjCDj6JOkq+CmF+mXoQp5pmRxR+9b7/AdvFJlwuHOcbTCaciB0Vmm479h pHlNr5pnV7k3Z69znfFeq9JhdxnKzEYJ9Jt8777X/pG0TEARFZm/S+59JA9Qg1KWN4gNGgE6cO6 tjCbKSBmDnze/UQbVlqhZgGw= X-Received: by 127.0.0.2 with SMTP id GBBOYY7687511xXXsq1FCPw6; Tue, 15 Aug 2023 14:26:28 -0700 X-Received: from ma-mailsvcp-mx-lapp02.apple.com (ma-mailsvcp-mx-lapp02.apple.com [17.32.222.23]) by mx.groups.io with SMTP id smtpd.web10.146141.1692134787845132099 for ; Tue, 15 Aug 2023 14:26:28 -0700 X-Received: from rn-mailsvcp-mta-lapp04.rno.apple.com (rn-mailsvcp-mta-lapp04.rno.apple.com [10.225.203.152]) by ma-mailsvcp-mx-lapp02.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0RZG0065HBK2TM20@ma-mailsvcp-mx-lapp02.apple.com> for devel@edk2.groups.io; Tue, 15 Aug 2023 14:26:27 -0700 (PDT) X-Proofpoint-ORIG-GUID: 6wU0h50W3koA7HTE6asLnbaqwTgRAgkD X-Proofpoint-GUID: 6wU0h50W3koA7HTE6asLnbaqwTgRAgkD X-Received: from rn-mailsvcp-mmp-lapp03.rno.apple.com (rn-mailsvcp-mmp-lapp03.rno.apple.com [17.179.253.16]) by rn-mailsvcp-mta-lapp04.rno.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0RZG00P47BK1WTN0@rn-mailsvcp-mta-lapp04.rno.apple.com>; Tue, 15 Aug 2023 14:26:26 -0700 (PDT) X-Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp03.rno.apple.com by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) id <0RZG00L00BDE7U00@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Tue, 15 Aug 2023 14:26:25 -0700 (PDT) X-Va-A: X-Va-T-CD: e3a01273e9031741a0757006fb277e8b X-Va-E-CD: a79fd2dfc6232e7fdb69a3f9586137f7 X-Va-R-CD: e4c78c371ebf7c6b093b9a3c3edfe85c X-Va-ID: 3d6c7755-a3c0-4c99-9172-9de8be0191ff X-Va-CD: 0 X-V-A: X-V-T-CD: e3a01273e9031741a0757006fb277e8b X-V-E-CD: a79fd2dfc6232e7fdb69a3f9586137f7 X-V-R-CD: e4c78c371ebf7c6b093b9a3c3edfe85c X-V-ID: b0ecd4c3-c94c-4e1d-9d70-fd7dba7cd8c8 X-V-CD: 0 X-Received: from smtpclient.apple (unknown [17.115.2.193]) by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPSA id <0RZG00Q45BJXRZ00@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Tue, 15 Aug 2023 14:26:25 -0700 (PDT) From: "Andrew Fish via groups.io" Message-id: <0F79F614-3F6B-4262-93A6-26DF5FB8C11A@apple.com> MIME-version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: [edk2-devel] About EDK2 supports Self Modifying Code Date: Tue, 15 Aug 2023 14:26:11 -0700 In-reply-to: Cc: Pedro Falcato , lichao@loongson.cn, Liming Gao , Bob Feng , Yuwei Chen To: edk2-devel-groups-io , Ard Biesheuvel References: <22642530-3177-d5d9-426a-d5a68ebfe8c6@loongson.cn> <4EB062B0-6C13-480F-A2CC-95C715A08ECD@apple.com> <0026aa43-c2d6-92bf-77a0-391a608e8b22@loongson.cn> <30CC4A49-0827-4960-A8F5-F44F534051F9@apple.com> <360DC97D-9F0F-4B86-B441-1C9789912AC6@apple.com> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,afish@apple.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ahjmnRk43h4SKsED3kmjj48ax7686176AA= Content-type: multipart/alternative; boundary="Apple-Mail=_8450E8D4-E90D-459F-BDEF-DD08A5CD190C" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=PxCb1FP5; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none --Apple-Mail=_8450E8D4-E90D-459F-BDEF-DD08A5CD190C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 15, 2023, at 11:48 AM, Ard Biesheuvel wrote: >=20 > On Tue, 15 Aug 2023 at 18:31, Andrew Fish via groups.io > > wrote: >>=20 >>=20 >>=20 >>> On Aug 15, 2023, at 8:39 AM, Pedro Falcato wr= ote: >>>=20 >>> On Tue, Aug 15, 2023 at 4:05=E2=80=AFPM Andrew Fish via groups.io >>> wrote: >>>>=20 >>>> Chao, >>>>=20 >>>> From a quick google it looks like CSR* is used to access banks of regi= sters that relate to things like performance counters and debug infrastruct= ure and the number of banks of these register sets is likely implementation= defined. Seems like we could introduce some Fixed At Build PCD values that= define the maximum number of elements in a given bank. >>>>=20 >>>> If we are forced to use assembler it might be possible to write some m= acros that used the fixed at build values to only generate functions for ba= nks that are needed for a given build. Then I think it becomes an exercise = in dead code stripping the assembler. Most compilers generate assembler tha= t contains functions that can be stripped as long as those functions follow= certain rules. >>>>=20 >>>> As a side note it would be good for us to have an FAQ/Wiki entry for t= he dead code stripping rules for the various flavors of assembler. I know t= he Apple assembler has a unique take on this. >>>=20 >>> FWIW, I'm almost positive there's no DCE in GNU as (or llvm-as as >>> well). Unless you use something ffunction-sections >>> -fdata-sections-like, but then you're relying on the linker + >>> gc-sections to take care of it, just like GCC/clang would. >>>=20 >>=20 >> I guess I usually think of DCE as a linker job, since the linker knows t= he functions that are NOT called. At least from the Apple tools the DCE has= the same rules if you are using Link Time Optimization or not. It is basic= ally a flag in the object that tells the inker it is OK to follow the DCE r= ules around labels and remove stuff. >>=20 >> Worst case it seems like we could have macros that generate assembly fil= es based on build time constants so we have one function per file. This mig= ht take a tweak to the build system, but I=E2=80=99d rather do that than ha= ve library functions that magically turn on Self Modifying Code. >>=20 >> Regardless of the answer I think documenting the rules is a useful exerc= ises since needing to save size in firmware images is not an uncommon task. >>=20 >=20 > There is already prior art in MdePkg where code targeting both GCC and > VS uses inline asm, so I don't see why we would make our lives > difficult and deviate from that for LoongArch. >=20 If you look at the BaseLib you can see an example of the INF file[1] using = C inline assembler for the GCC family[2] of compilers and NASM for the MSFT= [3] tools. Maybe you can plan on using a similar pattern. [1] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/Ba= seLib.inf#L321 [2] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X6= 4/GccInline.c [3] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseLib/X6= 4/CpuPause.nasm Thanks, Andrew Fish >=20 >=20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107772): https://edk2.groups.io/g/devel/message/107772 Mute This Topic: https://groups.io/mt/100751724/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --Apple-Mail=_8450E8D4-E90D-459F-BDEF-DD08A5CD190C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Aug 15, 2023, at 11:48 AM, Ard Biesheuvel <ardb@kernel.org= > wrote:

On Tue, 15 Aug 2023 at 18:31, Andrew Fish via groups.io=
<afish=3Dapple.com@groups.io> wrote:



On Aug 15, 2023, at 8:39 AM, Pedro Falcato <pedro.falcato@gmail.com= > wrote:

On Tue, Aug 15, 2023 at 4:05=E2=80=AFPM Andrew Fish via = groups.io
<afish=3Dapple.com@groups.io> wrote:

Chao,

From a quick google it looks like CSR* is used t= o access banks of registers that relate to things like performance counters= and debug infrastructure and the number of banks of these register sets is= likely implementation defined. Seems like we could introduce some Fixed At= Build PCD values that define the maximum number of elements in a given ban= k.

If we are forced to use assembler it might be possible to write s= ome macros that used the fixed at build values to only generate functions f= or banks that are needed for a given build. Then I think it becomes an exer= cise in dead code stripping the assembler. Most compilers generate assemble= r that contains functions that can be stripped as long as those functions f= ollow certain rules.

As a side note it would be good for us to have = an FAQ/Wiki entry for the dead code stripping rules for the various flavors= of assembler. I know the Apple assembler has a unique take on this.

FWIW, I'm almost positive there's no DCE in GNU as (or llvm-a= s as
well). Unless you use something ffunction-sections
-fdata-sectio= ns-like, but then you're relying on the linker +
gc-sections to take car= e of it, just like GCC/clang would.


I guess I usual= ly think of DCE as a linker job, since the linker knows the functions that = are NOT called. At least from the Apple tools the DCE has the same rules if= you are using Link Time Optimization or not. It is basically a flag in the= object that tells the inker it is OK to follow the DCE rules around labels= and remove stuff.

Worst case it seems like we could have macros tha= t generate assembly files based on build time constants so we have one func= tion per file. This might take a tweak to the build system, but I=E2=80=99d= rather do that than have library functions that magically turn on Self Mod= ifying Code.

Regardless of the answer I think documenting the rules = is a useful exercises since needing to save size in firmware images is not = an uncommon task.


There is already p= rior art in MdePkg where code targeting both GCC and
difficult and deviate from that for LoongArch.


If you look at the BaseLib you can see an example of the INF file[1] = using C inline assembler for the GCC family[2] of compilers and NASM for th= e MSFT [3] tools. Maybe you can plan on using a similar pattern.
=

Thanks,

<= div>Andrew Fish



_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#107772) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--Apple-Mail=_8450E8D4-E90D-459F-BDEF-DD08A5CD190C--