aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-11-22 23:14:38 +0000
committerMichael Brown <mcb30@ipxe.org>2023-11-23 13:20:21 +0000
commit678a60f61d76b6fce2d9e3b323db1892f69800d3 (patch)
tree5d0aeb509fc82aad98f2fd1aceeae43242d5491a
parent8c8ead25305bbe9521b488144257c131abbbcd23 (diff)
downloadipxe-678a60f61d76b6fce2d9e3b323db1892f69800d3.zip
ipxe-678a60f61d76b6fce2d9e3b323db1892f69800d3.tar.gz
ipxe-678a60f61d76b6fce2d9e3b323db1892f69800d3.tar.bz2
[efi] Treat writable sections as data sections
Hybrid bzImage and UEFI binaries (such as wimboot) may include 16-bit executable code that is opaque data from the perspective of a UEFI PE binary, as described in wimboot commit fe456ca ("[efi] Use separate .text and .data PE sections"). The ELF section will be marked as containing both executable code and writable data. Choose to treat such a section as a data section rather than a code section, since that matches the expected semantics for ELF files that we expect to process. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/util/elf2efi.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 5b3e785..4ed016c 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -591,17 +591,7 @@ static struct pe_section * process_section ( struct elf_file *elf,
/* Fill in section characteristics and update RVA limits */
if ( ( shdr->sh_type == SHT_PROGBITS ) &&
- ( shdr->sh_flags & SHF_EXECINSTR ) ) {
- /* .text-type section */
- new->hdr.Characteristics =
- ( EFI_IMAGE_SCN_CNT_CODE |
- EFI_IMAGE_SCN_MEM_NOT_PAGED |
- EFI_IMAGE_SCN_MEM_EXECUTE |
- EFI_IMAGE_SCN_MEM_READ );
- applicable_start = &code_start;
- applicable_end = &code_end;
- } else if ( ( shdr->sh_type == SHT_PROGBITS ) &&
- ( shdr->sh_flags & SHF_WRITE ) ) {
+ ( shdr->sh_flags & SHF_WRITE ) ) {
/* .data-type section */
new->hdr.Characteristics =
( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
@@ -610,6 +600,16 @@ static struct pe_section * process_section ( struct elf_file *elf,
EFI_IMAGE_SCN_MEM_WRITE );
applicable_start = &data_start;
applicable_end = &data_mid;
+ } else if ( ( shdr->sh_type == SHT_PROGBITS ) &&
+ ( shdr->sh_flags & SHF_EXECINSTR ) ) {
+ /* .text-type section */
+ new->hdr.Characteristics =
+ ( EFI_IMAGE_SCN_CNT_CODE |
+ EFI_IMAGE_SCN_MEM_NOT_PAGED |
+ EFI_IMAGE_SCN_MEM_EXECUTE |
+ EFI_IMAGE_SCN_MEM_READ );
+ applicable_start = &code_start;
+ applicable_end = &code_end;
} else if ( shdr->sh_type == SHT_PROGBITS ) {
/* .rodata-type section */
new->hdr.Characteristics =