* [edk2-devel] question about MSFT compiler/link option
@ 2020-08-04 9:34 Tiger Liu(BJ-RD)
2020-08-04 15:20 ` Liming Gao
0 siblings, 1 reply; 7+ messages in thread
From: Tiger Liu(BJ-RD) @ 2020-08-04 9:34 UTC (permalink / raw)
To: devel@edk2.groups.io
Hi, Experts:
I have a question about MSFT compiler/link option.
I wrote a PEIM, which had a large global data array definition in a C file.
Such as:
PRI_DATA_STRUCT PdataStructTable[] = {
{01, 0x75, 0xF0, 0x0, 0x0, 0x0 },
{02, 0x77, 0xF0, 0x0, 0x0, 0x0 },
{03, 0x79, 0xF0, 0x0, 0x0, 0x0 },
{04, 0x7B, 0xF0, 0x0, 0x0, 0x0 },
{05, 0x7D, 0xF0, 0x0, 0x0, 0x0 },
{06, 0x7F, 0xF0, 0x0, 0x0, 0x0 },
......
};
This global data array is very large, about 20KB.
But I found the PEIM's compiled size is about 5KB, it seems not include this global data array in the efi binary statically.
Even the release version PEIM's size is larger than debug version.
I found when compiling release version, the link option has : /MERGE:.rdata=.data
It seems release binary included the global data array in the final efi image.
So, my question is:
Will the global data array be in linked into the final efi binary image when compiling debug version?
Thanks
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
2020-08-04 9:34 Tiger Liu(BJ-RD)
@ 2020-08-04 15:20 ` Liming Gao
0 siblings, 0 replies; 7+ messages in thread
From: Liming Gao @ 2020-08-04 15:20 UTC (permalink / raw)
To: devel@edk2.groups.io, tigerliu@zhaoxin.com
If this global variable is used by code, it will be linked into the final EFI image. You can check whether the generate map file includes it.
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Tiger Liu(BJ-RD)
> Sent: Tuesday, August 4, 2020 5:34 PM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] question about MSFT compiler/link option
>
> Hi, Experts:
> I have a question about MSFT compiler/link option.
>
> I wrote a PEIM, which had a large global data array definition in a C file.
> Such as:
> PRI_DATA_STRUCT PdataStructTable[] = {
> {01, 0x75, 0xF0, 0x0, 0x0, 0x0 },
> {02, 0x77, 0xF0, 0x0, 0x0, 0x0 },
> {03, 0x79, 0xF0, 0x0, 0x0, 0x0 },
> {04, 0x7B, 0xF0, 0x0, 0x0, 0x0 },
> {05, 0x7D, 0xF0, 0x0, 0x0, 0x0 },
> {06, 0x7F, 0xF0, 0x0, 0x0, 0x0 },
> ......
> };
>
> This global data array is very large, about 20KB.
>
> But I found the PEIM's compiled size is about 5KB, it seems not include this global data array in the efi binary statically.
> Even the release version PEIM's size is larger than debug version.
>
> I found when compiling release version, the link option has : /MERGE:.rdata=.data
> It seems release binary included the global data array in the final efi image.
>
> So, my question is:
> Will the global data array be in linked into the final efi binary image when compiling debug version?
>
> Thanks
>
>
> 保密声明:
> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
> CONFIDENTIAL NOTE:
> This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized
> review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
@ 2020-08-05 6:33 Tiger Liu(BJ-RD)
2020-08-05 15:17 ` Michael D Kinney
0 siblings, 1 reply; 7+ messages in thread
From: Tiger Liu(BJ-RD) @ 2020-08-05 6:33 UTC (permalink / raw)
To: devel@edk2.groups.io, liming.gao@intel.com
Hi, Liming:
Thanks for your reply!
I checked map file, not find this global data array.
I found if added this build option in this PEIM's inf, then it seems ok.
[BuildOptions]
MSFT:*_*_IA32_CC_FLAGS = /Gw-
Thanks
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Liming Gao
发送时间: 2020年8月4日 23:21
收件人: devel@edk2.groups.io; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>
主题: Re: [edk2-devel] question about MSFT compiler/link option
If this global variable is used by code, it will be linked into the final EFI image. You can check whether the generate map file includes it.
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Tiger
> Liu(BJ-RD)
> Sent: Tuesday, August 4, 2020 5:34 PM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] question about MSFT compiler/link option
>
> Hi, Experts:
> I have a question about MSFT compiler/link option.
>
> I wrote a PEIM, which had a large global data array definition in a C file.
> Such as:
> PRI_DATA_STRUCT PdataStructTable[] = {
> {01, 0x75, 0xF0, 0x0, 0x0, 0x0 },
> {02, 0x77, 0xF0, 0x0, 0x0, 0x0 },
> {03, 0x79, 0xF0, 0x0, 0x0, 0x0 },
> {04, 0x7B, 0xF0, 0x0, 0x0, 0x0 },
> {05, 0x7D, 0xF0, 0x0, 0x0, 0x0 },
> {06, 0x7F, 0xF0, 0x0, 0x0, 0x0 },
> ......
> };
>
> This global data array is very large, about 20KB.
>
> But I found the PEIM's compiled size is about 5KB, it seems not include this global data array in the efi binary statically.
> Even the release version PEIM's size is larger than debug version.
>
> I found when compiling release version, the link option has :
> /MERGE:.rdata=.data It seems release binary included the global data array in the final efi image.
>
> So, my question is:
> Will the global data array be in linked into the final efi binary image when compiling debug version?
>
> Thanks
>
>
> 保密声明:
> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
> CONFIDENTIAL NOTE:
> This email contains confidential or legally privileged information and
> is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
>
>
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
2020-08-05 6:33 Tiger Liu(BJ-RD)
@ 2020-08-05 15:17 ` Michael D Kinney
0 siblings, 0 replies; 7+ messages in thread
From: Michael D Kinney @ 2020-08-05 15:17 UTC (permalink / raw)
To: devel@edk2.groups.io, tigerliu@zhaoxin.com, Gao, Liming,
Kinney, Michael D
Hi,
I think you are seeing the impact of compiler optimizations.
If a global variable is never referenced after optimizing the
code, then the global variable will be optimized away. This
type of optimization is important for size constrained
environment like firmware.
By using the /Gw- flag, you are disabling the ability of the
compiler to optimize away unreferenced global variables.
If you update the code in your example to guarantee the
global variable is always accessed for all types of builds,
then I suspect you will always see the global in the map.
Thanks,
Mike
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On
> Behalf Of Tiger Liu(BJ-RD)
> Sent: Tuesday, August 4, 2020 11:34 PM
> To: devel@edk2.groups.io; Gao, Liming
> <liming.gao@intel.com>
> Subject: Re: [edk2-devel] question about MSFT
> compiler/link option
>
> Hi, Liming:
> Thanks for your reply!
>
> I checked map file, not find this global data array.
>
> I found if added this build option in this PEIM's inf,
> then it seems ok.
> [BuildOptions]
> MSFT:*_*_IA32_CC_FLAGS = /Gw-
>
> Thanks
>
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表
> Liming Gao
> 发送时间: 2020年8月4日 23:21
> 收件人: devel@edk2.groups.io; Tiger Liu(BJ-RD)
> <TigerLiu@zhaoxin.com>
> 主题: Re: [edk2-devel] question about MSFT compiler/link
> option
>
> If this global variable is used by code, it will be
> linked into the final EFI image. You can check whether
> the generate map file includes it.
>
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On
> Behalf Of Tiger
> > Liu(BJ-RD)
> > Sent: Tuesday, August 4, 2020 5:34 PM
> > To: devel@edk2.groups.io
> > Subject: [edk2-devel] question about MSFT
> compiler/link option
> >
> > Hi, Experts:
> > I have a question about MSFT compiler/link option.
> >
> > I wrote a PEIM, which had a large global data array
> definition in a C file.
> > Such as:
> > PRI_DATA_STRUCT PdataStructTable[] = {
> > {01, 0x75, 0xF0, 0x0, 0x0,
> 0x0 },
> > {02, 0x77, 0xF0, 0x0, 0x0,
> 0x0 },
> > {03, 0x79, 0xF0, 0x0, 0x0,
> 0x0 },
> > {04, 0x7B, 0xF0, 0x0, 0x0,
> 0x0 },
> > {05, 0x7D, 0xF0, 0x0, 0x0,
> 0x0 },
> > {06, 0x7F, 0xF0, 0x0, 0x0,
> 0x0 },
> > ......
> > };
> >
> > This global data array is very large, about 20KB.
> >
> > But I found the PEIM's compiled size is about 5KB, it
> seems not include this global data array in the efi
> binary statically.
> > Even the release version PEIM's size is larger than
> debug version.
> >
> > I found when compiling release version, the link
> option has :
> > /MERGE:.rdata=.data It seems release binary included
> the global data array in the final efi image.
> >
> > So, my question is:
> > Will the global data array be in linked into the final
> efi binary image when compiling debug version?
> >
> > Thanks
> >
> >
> > 保密声明:
> > 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内
> 容做任何未经授权的查阅、使用、复制或转发。
> > CONFIDENTIAL NOTE:
> > This email contains confidential or legally privileged
> information and
> > is for the sole use of its intended recipient. Any
> unauthorized review, use, copying or forwarding of this
> email or the content of this email is strictly
> prohibited.
> >
> >
>
>
>
>
>
>
> 保密声明:
> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容
> 做任何未经授权的查阅、使用、复制或转发。
> CONFIDENTIAL NOTE:
> This email contains confidential or legally privileged
> information and is for the sole use of its intended
> recipient. Any unauthorized review, use, copying or
> forwarding of this email or the content of this email is
> strictly prohibited.
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
@ 2020-08-06 3:31 Tiger Liu(BJ-RD)
2020-08-06 3:46 ` Andrew Fish
0 siblings, 1 reply; 7+ messages in thread
From: Tiger Liu(BJ-RD) @ 2020-08-06 3:31 UTC (permalink / raw)
To: devel@edk2.groups.io, michael.d.kinney@intel.com, Gao, Liming
Hi, Michael:
I wrote this sentence in C file:
pTmp = (VOID*)& PdataStructTable;
tried to reference the table being generated to prevent the optimizer from removing the data structure from the executable.
But it is still being optimized away.
I used MSTF VS2015.
Thanks
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Michael D Kinney
发送时间: 2020年8月5日 23:18
收件人: devel@edk2.groups.io; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>; Gao, Liming <liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>
主题: Re: [edk2-devel] question about MSFT compiler/link option
Hi,
I think you are seeing the impact of compiler optimizations.
If a global variable is never referenced after optimizing the code, then the global variable will be optimized away. This type of optimization is important for size constrained environment like firmware.
By using the /Gw- flag, you are disabling the ability of the compiler to optimize away unreferenced global variables.
If you update the code in your example to guarantee the global variable is always accessed for all types of builds, then I suspect you will always see the global in the map.
Thanks,
Mike
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Tiger
> Liu(BJ-RD)
> Sent: Tuesday, August 4, 2020 11:34 PM
> To: devel@edk2.groups.io; Gao, Liming
> <liming.gao@intel.com>
> Subject: Re: [edk2-devel] question about MSFT compiler/link option
>
> Hi, Liming:
> Thanks for your reply!
>
> I checked map file, not find this global data array.
>
> I found if added this build option in this PEIM's inf, then it seems
> ok.
> [BuildOptions]
> MSFT:*_*_IA32_CC_FLAGS = /Gw-
>
> Thanks
>
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表
> Liming Gao
> 发送时间: 2020年8月4日 23:21
> 收件人: devel@edk2.groups.io; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>
> 主题: Re: [edk2-devel] question about MSFT compiler/link option
>
> If this global variable is used by code, it will be linked into the
> final EFI image. You can check whether the generate map file includes
> it.
>
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On
> Behalf Of Tiger
> > Liu(BJ-RD)
> > Sent: Tuesday, August 4, 2020 5:34 PM
> > To: devel@edk2.groups.io
> > Subject: [edk2-devel] question about MSFT
> compiler/link option
> >
> > Hi, Experts:
> > I have a question about MSFT compiler/link option.
> >
> > I wrote a PEIM, which had a large global data array
> definition in a C file.
> > Such as:
> > PRI_DATA_STRUCT PdataStructTable[] = {
> > {01, 0x75, 0xF0, 0x0, 0x0,
> 0x0 },
> > {02, 0x77, 0xF0, 0x0, 0x0,
> 0x0 },
> > {03, 0x79, 0xF0, 0x0, 0x0,
> 0x0 },
> > {04, 0x7B, 0xF0, 0x0, 0x0,
> 0x0 },
> > {05, 0x7D, 0xF0, 0x0, 0x0,
> 0x0 },
> > {06, 0x7F, 0xF0, 0x0, 0x0,
> 0x0 },
> > ......
> > };
> >
> > This global data array is very large, about 20KB.
> >
> > But I found the PEIM's compiled size is about 5KB, it
> seems not include this global data array in the efi binary statically.
> > Even the release version PEIM's size is larger than
> debug version.
> >
> > I found when compiling release version, the link
> option has :
> > /MERGE:.rdata=.data It seems release binary included
> the global data array in the final efi image.
> >
> > So, my question is:
> > Will the global data array be in linked into the final
> efi binary image when compiling debug version?
> >
> > Thanks
> >
> >
> > 保密声明:
> > 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内
> 容做任何未经授权的查阅、使用、复制或转发。
> > CONFIDENTIAL NOTE:
> > This email contains confidential or legally privileged
> information and
> > is for the sole use of its intended recipient. Any
> unauthorized review, use, copying or forwarding of this email or the
> content of this email is strictly prohibited.
> >
> >
>
>
>
>
>
>
> 保密声明:
> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容
> 做任何未经授权的查阅、使用、复制或转发。
> CONFIDENTIAL NOTE:
> This email contains confidential or legally privileged information and
> is for the sole use of its intended recipient. Any unauthorized
> review, use, copying or forwarding of this email or the content of
> this email is strictly prohibited.
>
>
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
2020-08-06 3:31 Tiger Liu(BJ-RD)
@ 2020-08-06 3:46 ` Andrew Fish
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Fish @ 2020-08-06 3:46 UTC (permalink / raw)
To: edk2-devel-groups-io, tigerliu; +Cc: Mike Kinney, Gao, Liming
[-- Attachment #1: Type: text/plain, Size: 6073 bytes --]
> On Aug 5, 2020, at 8:31 PM, Tiger Liu(BJ-RD) <tigerliu@zhaoxin.com> wrote:
>
> Hi, Michael:
> I wrote this sentence in C file:
> pTmp = (VOID*)& PdataStructTable;
>
Tiger,
Working around optimization is complicated. You likely added a statement that got optimized away as the value of pTmp could be ignored and your program could still get the same result.
You would need to do some meaningful work with pTmp or make pTmp a volatile variable to force the compiler to NOT optimize it away. The better the optimizer, the more layers of abstraction it can see and optimize away.
Thanks,
Andrew Fish
> tried to reference the table being generated to prevent the optimizer from removing the data structure from the executable.
>
> But it is still being optimized away.
>
> I used MSTF VS2015.
>
> Thanks
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <mailto:devel@edk2.groups.io> <devel@edk2.groups.io <mailto:devel@edk2.groups.io>> 代表 Michael D Kinney
> 发送时间: 2020年8月5日 23:18
> 收件人: devel@edk2.groups.io <mailto:devel@edk2.groups.io>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com <mailto:TigerLiu@zhaoxin.com>>; Gao, Liming <liming.gao@intel.com <mailto:liming.gao@intel.com>>; Kinney, Michael D <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com>>
> 主题: Re: [edk2-devel] question about MSFT compiler/link option
>
> Hi,
>
> I think you are seeing the impact of compiler optimizations.
>
> If a global variable is never referenced after optimizing the code, then the global variable will be optimized away. This type of optimization is important for size constrained environment like firmware.
>
> By using the /Gw- flag, you are disabling the ability of the compiler to optimize away unreferenced global variables.
>
> If you update the code in your example to guarantee the global variable is always accessed for all types of builds, then I suspect you will always see the global in the map.
>
> Thanks,
>
> Mike
>
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Tiger
>> Liu(BJ-RD)
>> Sent: Tuesday, August 4, 2020 11:34 PM
>> To: devel@edk2.groups.io; Gao, Liming
>> <liming.gao@intel.com>
>> Subject: Re: [edk2-devel] question about MSFT compiler/link option
>>
>> Hi, Liming:
>> Thanks for your reply!
>>
>> I checked map file, not find this global data array.
>>
>> I found if added this build option in this PEIM's inf, then it seems
>> ok.
>> [BuildOptions]
>> MSFT:*_*_IA32_CC_FLAGS = /Gw-
>>
>> Thanks
>>
>> -----邮件原件-----
>> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表
>> Liming Gao
>> 发送时间: 2020年8月4日 23:21
>> 收件人: devel@edk2.groups.io; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>
>> 主题: Re: [edk2-devel] question about MSFT compiler/link option
>>
>> If this global variable is used by code, it will be linked into the
>> final EFI image. You can check whether the generate map file includes
>> it.
>>
>>> -----Original Message-----
>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On
>> Behalf Of Tiger
>>> Liu(BJ-RD)
>>> Sent: Tuesday, August 4, 2020 5:34 PM
>>> To: devel@edk2.groups.io
>>> Subject: [edk2-devel] question about MSFT
>> compiler/link option
>>>
>>> Hi, Experts:
>>> I have a question about MSFT compiler/link option.
>>>
>>> I wrote a PEIM, which had a large global data array
>> definition in a C file.
>>> Such as:
>>> PRI_DATA_STRUCT PdataStructTable[] = {
>>> {01, 0x75, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> {02, 0x77, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> {03, 0x79, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> {04, 0x7B, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> {05, 0x7D, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> {06, 0x7F, 0xF0, 0x0, 0x0,
>> 0x0 },
>>> ......
>>> };
>>>
>>> This global data array is very large, about 20KB.
>>>
>>> But I found the PEIM's compiled size is about 5KB, it
>> seems not include this global data array in the efi binary statically.
>>> Even the release version PEIM's size is larger than
>> debug version.
>>>
>>> I found when compiling release version, the link
>> option has :
>>> /MERGE:.rdata=.data It seems release binary included
>> the global data array in the final efi image.
>>>
>>> So, my question is:
>>> Will the global data array be in linked into the final
>> efi binary image when compiling debug version?
>>>
>>> Thanks
>>>
>>>
>>> 保密声明:
>>> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内
>> 容做任何未经授权的查阅、使用、复制或转发。
>>> CONFIDENTIAL NOTE:
>>> This email contains confidential or legally privileged
>> information and
>>> is for the sole use of its intended recipient. Any
>> unauthorized review, use, copying or forwarding of this email or the
>> content of this email is strictly prohibited.
>>>
>>>
>>
>>
>>
>>
>>
>>
>> 保密声明:
>> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容
>> 做任何未经授权的查阅、使用、复制或转发。
>> CONFIDENTIAL NOTE:
>> This email contains confidential or legally privileged information and
>> is for the sole use of its intended recipient. Any unauthorized
>> review, use, copying or forwarding of this email or the content of
>> this email is strictly prohibited.
>>
>>
>
>
>
>
>
>
> 保密声明:
> 本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
> CONFIDENTIAL NOTE:
> This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
>
>
[-- Attachment #2: Type: text/html, Size: 37773 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] question about MSFT compiler/link option
@ 2020-08-10 3:25 Tiger Liu(BJ-RD)
0 siblings, 0 replies; 7+ messages in thread
From: Tiger Liu(BJ-RD) @ 2020-08-10 3:25 UTC (permalink / raw)
To: devel@edk2.groups.io, afish@apple.com; +Cc: Mike Kinney, Gao, Liming
[-- Attachment #1: Type: text/plain, Size: 6874 bytes --]
Hi, Andrew:
Got it.
Thank you very much.
Best wishes,
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Andrew Fish via groups.io
发送时间: 2020年8月6日 11:46
收件人: edk2-devel-groups-io <devel@edk2.groups.io>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>
抄送: Mike Kinney <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
主题: Re: [edk2-devel] question about MSFT compiler/link option
On Aug 5, 2020, at 8:31 PM, Tiger Liu(BJ-RD) <tigerliu@zhaoxin.com<mailto:tigerliu@zhaoxin.com>> wrote:
Hi, Michael:
I wrote this sentence in C file:
pTmp = (VOID*)& PdataStructTable;
Tiger,
Working around optimization is complicated. You likely added a statement that got optimized away as the value of pTmp could be ignored and your program could still get the same result.
You would need to do some meaningful work with pTmp or make pTmp a volatile variable to force the compiler to NOT optimize it away. The better the optimizer, the more layers of abstraction it can see and optimize away.
Thanks,
Andrew Fish
tried to reference the table being generated to prevent the optimizer from removing the data structure from the executable.
But it is still being optimized away.
I used MSTF VS2015.
Thanks
-----邮件原件-----
发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> 代表 Michael D Kinney
发送时间: 2020年8月5日 23:18
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com<mailto:TigerLiu@zhaoxin.com>>; Gao, Liming <liming.gao@intel.com<mailto:liming.gao@intel.com>>; Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>
主题: Re: [edk2-devel] question about MSFT compiler/link option
Hi,
I think you are seeing the impact of compiler optimizations.
If a global variable is never referenced after optimizing the code, then the global variable will be optimized away. This type of optimization is important for size constrained environment like firmware.
By using the /Gw- flag, you are disabling the ability of the compiler to optimize away unreferenced global variables.
If you update the code in your example to guarantee the global variable is always accessed for all types of builds, then I suspect you will always see the global in the map.
Thanks,
Mike
-----Original Message-----
From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Tiger
Liu(BJ-RD)
Sent: Tuesday, August 4, 2020 11:34 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Gao, Liming
<liming.gao@intel.com<mailto:liming.gao@intel.com>>
Subject: Re: [edk2-devel] question about MSFT compiler/link option
Hi, Liming:
Thanks for your reply!
I checked map file, not find this global data array.
I found if added this build option in this PEIM's inf, then it seems
ok.
[BuildOptions]
MSFT:*_*_IA32_CC_FLAGS = /Gw-
Thanks
-----邮件原件-----
发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> 代表
Liming Gao
发送时间: 2020年8月4日 23:21
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com<mailto:TigerLiu@zhaoxin.com>>
主题: Re: [edk2-devel] question about MSFT compiler/link option
If this global variable is used by code, it will be linked into the
final EFI image. You can check whether the generate map file includes
it.
-----Original Message-----
From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On
Behalf Of Tiger
Liu(BJ-RD)
Sent: Tuesday, August 4, 2020 5:34 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: [edk2-devel] question about MSFT
compiler/link option
Hi, Experts:
I have a question about MSFT compiler/link option.
I wrote a PEIM, which had a large global data array
definition in a C file.
Such as:
PRI_DATA_STRUCT PdataStructTable[] = {
{01, 0x75, 0xF0, 0x0, 0x0,
0x0 },
{02, 0x77, 0xF0, 0x0, 0x0,
0x0 },
{03, 0x79, 0xF0, 0x0, 0x0,
0x0 },
{04, 0x7B, 0xF0, 0x0, 0x0,
0x0 },
{05, 0x7D, 0xF0, 0x0, 0x0,
0x0 },
{06, 0x7F, 0xF0, 0x0, 0x0,
0x0 },
......
};
This global data array is very large, about 20KB.
But I found the PEIM's compiled size is about 5KB, it
seems not include this global data array in the efi binary statically.
Even the release version PEIM's size is larger than
debug version.
I found when compiling release version, the link
option has :
/MERGE:.rdata=.data It seems release binary included
the global data array in the final efi image.
So, my question is:
Will the global data array be in linked into the final
efi binary image when compiling debug version?
Thanks
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内
容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged
information and
is for the sole use of its intended recipient. Any
unauthorized review, use, copying or forwarding of this email or the
content of this email is strictly prohibited.
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容
做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and
is for the sole use of its intended recipient. Any unauthorized
review, use, copying or forwarding of this email or the content of
this email is strictly prohibited.
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
[-- Attachment #2: Type: text/html, Size: 26447 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-08-10 3:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-10 3:25 [edk2-devel] question about MSFT compiler/link option Tiger Liu(BJ-RD)
-- strict thread matches above, loose matches on Subject: below --
2020-08-06 3:31 Tiger Liu(BJ-RD)
2020-08-06 3:46 ` Andrew Fish
2020-08-05 6:33 Tiger Liu(BJ-RD)
2020-08-05 15:17 ` Michael D Kinney
2020-08-04 9:34 Tiger Liu(BJ-RD)
2020-08-04 15:20 ` Liming Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox