* [edk2-devel] : Query regarding IsTextShdr inside Basetools
@ 2020-11-10 13:07 mojha
2020-11-11 22:40 ` Laszlo Ersek
0 siblings, 1 reply; 5+ messages in thread
From: mojha @ 2020-11-10 13:07 UTC (permalink / raw)
To: devel, discuss
Hi All,
I have a doubt about the check we have put inside IsTextShdr() .
STATIC
BOOLEAN
IsTextShdr (
Elf_Shdr *Shdr
)
{
return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
SHF_ALLOC);
}
We are observing one issue where while generate EFI using GenFW in EDK2
because test/data section offset is different than calculated
mCoffSectionsOffset when scanning sections.
I run GenFW with a failure dll in my local after adding some logs into
GenFW. and found that “mCoffSectionsOffset” for data section seems not
to have expected value due to
“.note.gnu.property” size. Because compiled dll has “.note.gnu.property”
section with alloc flag and GenFW thinks that it’s a text section if
alloc flag is set.
So its size is added to the mCoffSectionsOffset.
Could you please give us an advice whether we can fix IsTextShdr()
function like below ?
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -229,7 +229,7 @@ IsTextShdr (
Elf_Shdr *Shdr
)
{
- return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
SHF_ALLOC);
+ return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |
SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR));^
Thanks,
Mukesh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools
2020-11-10 13:07 [edk2-devel] : Query regarding IsTextShdr inside Basetools mojha
@ 2020-11-11 22:40 ` Laszlo Ersek
2020-11-11 22:41 ` Laszlo Ersek
0 siblings, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2020-11-11 22:40 UTC (permalink / raw)
To: Ard Biesheuvel (ARM address), Liming Gao (Intel address)
Cc: devel, mojha, discuss
Ard, Liming,
can you please take a look?
Thanks!
Laszlo
On 11/10/20 14:07, Mukesh Ojha wrote:
> Hi All,
>
> I have a doubt about the check we have put inside IsTextShdr() .
>
> STATIC
> BOOLEAN
> IsTextShdr (
> Elf_Shdr *Shdr
> )
> {
> return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> SHF_ALLOC);
> }
>
>
> We are observing one issue where while generate EFI using GenFW in EDK2
> because test/data section offset is different than calculated
> mCoffSectionsOffset when scanning sections.
> I run GenFW with a failure dll in my local after adding some logs into
> GenFW. and found that “mCoffSectionsOffset” for data section seems not
> to have expected value due to
> “.note.gnu.property” size. Because compiled dll has “.note.gnu.property”
> section with alloc flag and GenFW thinks that it’s a text section if
> alloc flag is set.
> So its size is added to the mCoffSectionsOffset.
>
> Could you please give us an advice whether we can fix IsTextShdr()
> function like below ?
>
>
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -229,7 +229,7 @@ IsTextShdr (
> Elf_Shdr *Shdr
> )
> {
> - return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> SHF_ALLOC);
> + return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |
> SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR));^
>
>
> Thanks,
> Mukesh
>
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools
2020-11-11 22:40 ` Laszlo Ersek
@ 2020-11-11 22:41 ` Laszlo Ersek
2020-11-12 8:23 ` Ard Biesheuvel
0 siblings, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2020-11-11 22:41 UTC (permalink / raw)
To: Ard Biesheuvel (ARM address), Liming Gao (Byosoft address)
Cc: devel, mojha, discuss
On 11/11/20 23:40, Laszlo Ersek wrote:
> Ard, Liming,
>
> can you please take a look?
>
> Thanks!
> Laszlo
Darn, I used Liming's old email address. Correcting it now. Sorry!
Laszlo
>
> On 11/10/20 14:07, Mukesh Ojha wrote:
>> Hi All,
>>
>> I have a doubt about the check we have put inside IsTextShdr() .
>>
>> STATIC
>> BOOLEAN
>> IsTextShdr (
>> Elf_Shdr *Shdr
>> )
>> {
>> return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
>> SHF_ALLOC);
>> }
>>
>>
>> We are observing one issue where while generate EFI using GenFW in EDK2
>> because test/data section offset is different than calculated
>> mCoffSectionsOffset when scanning sections.
>> I run GenFW with a failure dll in my local after adding some logs into
>> GenFW. and found that “mCoffSectionsOffset” for data section seems not
>> to have expected value due to
>> “.note.gnu.property” size. Because compiled dll has “.note.gnu.property”
>> section with alloc flag and GenFW thinks that it’s a text section if
>> alloc flag is set.
>> So its size is added to the mCoffSectionsOffset.
>>
>> Could you please give us an advice whether we can fix IsTextShdr()
>> function like below ?
>>
>>
>> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
>> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
>> @@ -229,7 +229,7 @@ IsTextShdr (
>> Elf_Shdr *Shdr
>> )
>> {
>> - return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
>> SHF_ALLOC);
>> + return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |
>> SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR));^
>>
>>
>> Thanks,
>> Mukesh
>>
>>
>>
>>
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools
2020-11-11 22:41 ` Laszlo Ersek
@ 2020-11-12 8:23 ` Ard Biesheuvel
0 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2020-11-12 8:23 UTC (permalink / raw)
To: Laszlo Ersek, Liming Gao (Byosoft address); +Cc: devel, mojha, discuss
On 11/11/20 11:41 PM, Laszlo Ersek wrote:
> On 11/11/20 23:40, Laszlo Ersek wrote:
>> Ard, Liming,
>>
>> can you please take a look?
>>
>> Thanks!
>> Laszlo
>
> Darn, I used Liming's old email address. Correcting it now. Sorry!
>
> Laszlo
>
>>
>> On 11/10/20 14:07, Mukesh Ojha wrote:
>>> Hi All,
>>>
>>> I have a doubt about the check we have put inside IsTextShdr() .
>>>
>>> STATIC
>>> BOOLEAN
>>> IsTextShdr (
>>> Elf_Shdr *Shdr
>>> )
>>> {
>>> return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
>>> SHF_ALLOC);
>>> }
>>>
>>>
>>> We are observing one issue where while generate EFI using GenFW in EDK2
>>> because test/data section offset is different than calculated
>>> mCoffSectionsOffset when scanning sections.
>>> I run GenFW with a failure dll in my local after adding some logs into
>>> GenFW. and found that “mCoffSectionsOffset” for data section seems not
>>> to have expected value due to
>>> “.note.gnu.property” size. Because compiled dll has “.note.gnu.property”
>>> section with alloc flag and GenFW thinks that it’s a text section if
>>> alloc flag is set.
>>> So its size is added to the mCoffSectionsOffset.
>>>
>>> Could you please give us an advice whether we can fix IsTextShdr()
>>> function like below ?
>>>
>>>
>>> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
>>> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
>>> @@ -229,7 +229,7 @@ IsTextShdr (
>>> Elf_Shdr *Shdr
>>> )
>>> {
>>> - return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
>>> SHF_ALLOC);
>>> + return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |
>>> SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR));^
>>>
Was this ELF executable built using the GccBase.lds linker script? If
so, we should fix it to disregard .note sections.
If you are not using GccBase.lds, I'm afraid you are simply in
unsupported territory - there are too many assumptions in GenFw that are
not guaranteed to hold for arbitrary ELF executables.
I don't think changing IsTextShdr() is the right approach here.
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <164632B1BC861BDB.31324@groups.io>]
* Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools
[not found] <164632B1BC861BDB.31324@groups.io>
@ 2020-11-11 7:07 ` Mukesh Ojha
0 siblings, 0 replies; 5+ messages in thread
From: Mukesh Ojha @ 2020-11-11 7:07 UTC (permalink / raw)
To: devel, discuss; +Cc: mojha
Apology for rushing into this.
Looking for a quick input on this.
-Mukesh
On 11/10/2020 6:37 PM, Mukesh Ojha wrote:
> Hi All,
>
> I have a doubt about the check we have put inside IsTextShdr() .
>
> STATIC
> BOOLEAN
> IsTextShdr (
> Elf_Shdr *Shdr
> )
> {
> return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> SHF_ALLOC);
> }
>
>
> We are observing one issue where while generate EFI using GenFW in
> EDK2 because test/data section offset is different than calculated
> mCoffSectionsOffset when scanning sections.
> I run GenFW with a failure dll in my local after adding some logs into
> GenFW. and found that “mCoffSectionsOffset” for data ection seems not
> to have expected value due to
> “.note.gnu.property” size. Because compiled dll has
> “.note.gnu.property” section with alloc flag and GenFW thinks that
> it’s a text section if alloc flag is set.
> So its size is added to the mCoffSectionsOffset.
>
> Could you please give us an advice whether we can fix IsTextShdr()
> function like below ?
>
>
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -229,7 +229,7 @@ IsTextShdr (
> Elf_Shdr *Shdr
> )
> {
> - return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> SHF_ALLOC);
> + return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |
> SHF_ALLOC)) == (SHF_ALLOC | SHF_EXECINSTR));^
>
>
> Thanks,
> Mukesh
>
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-12 8:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-10 13:07 [edk2-devel] : Query regarding IsTextShdr inside Basetools mojha
2020-11-11 22:40 ` Laszlo Ersek
2020-11-11 22:41 ` Laszlo Ersek
2020-11-12 8:23 ` Ard Biesheuvel
[not found] <164632B1BC861BDB.31324@groups.io>
2020-11-11 7:07 ` Mukesh Ojha
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox