Re: [edk2-devel] : Query regarding IsTextShdr inside Basetools

Ard Biesheuvel <ard.biesheuvel@...>

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?

Darn, I used Liming's old email address. Correcting it now. Sorry!

On 11/10/20 14:07, Mukesh Ojha wrote:
Hi All,

I have a doubt about the check we have put inside IsTextShdr() .

IsTextShdr (
  Elf_Shdr *Shdr
  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | 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
“” size. Because compiled dll has “”
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)) ==
+  return (BOOLEAN) ((Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE |

Was this ELF executable built using the linker script? If so, we should fix it to disregard .note sections.

If you are not using, 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.

Join to automatically receive all group messages.