From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.1431.1605169428481802856 for ; Thu, 12 Nov 2020 00:23:48 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1630C101E; Thu, 12 Nov 2020 00:23:48 -0800 (PST) Received: from [192.168.1.81] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6AF13F73C; Thu, 12 Nov 2020 00:23:46 -0800 (PST) Subject: Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools To: Laszlo Ersek , "Liming Gao (Byosoft address)" Cc: devel@edk2.groups.io, mojha@codeaurora.org, discuss@edk2.groups.io References: <9cd5c07e-d74d-5fa7-b3a7-2ef5fec01fc5@redhat.com> <7b920231-f763-06d6-c69c-a97123c7a4be@redhat.com> From: "Ard Biesheuvel" Message-ID: <086e1e01-7ab5-d877-480f-62f588b84300@arm.com> Date: Thu, 12 Nov 2020 09:23:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <7b920231-f763-06d6-c69c-a97123c7a4be@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 >=20 > Darn, I used Liming's old email address. Correcting it now. Sorry! >=20 > Laszlo >=20 >> >> 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 ( >>> =C2=A0 Elf_Shdr *Shdr >>> =C2=A0 ) >>> { >>> =C2=A0 return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) = =3D=3D >>> SHF_ALLOC); >>> } >>> >>> >>> We are observing one issue where while generate EFI using GenFW in ED= K2 >>> 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 int= o >>> GenFW. and found that =E2=80=9CmCoffSectionsOffset=E2=80=9D for data = section seems not >>> to have expected value due to >>> =E2=80=9C.note.gnu.property=E2=80=9D size. Because compiled dll has =E2= =80=9C.note.gnu.property=E2=80=9D >>> section with alloc flag and GenFW thinks that it=E2=80=99s a text sec= tion 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 ( >>> =C2=A0=C2=A0 Elf_Shdr *Shdr >>> =C2=A0=C2=A0 ) >>> { >>> -=C2=A0 return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) = =3D=3D >>> SHF_ALLOC); >>> +=C2=A0 return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRIT= E | >>> SHF_ALLOC)) =3D=3D (SHF_ALLOC | SHF_EXECINSTR));^ >>> Was this ELF executable built using the GccBase.lds linker script? If=20 so, we should fix it to disregard .note sections. If you are not using GccBase.lds, I'm afraid you are simply in=20 unsupported territory - there are too many assumptions in GenFw that are=20 not guaranteed to hold for arbitrary ELF executables. I don't think changing IsTextShdr() is the right approach here.