diff options
Diffstat (limited to 'src/util/elf2efi.c')
-rw-r--r-- | src/util/elf2efi.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c index 61ac0e277..5b3e785f5 100644 --- a/src/util/elf2efi.c +++ b/src/util/elf2efi.c @@ -181,6 +181,7 @@ struct pe_section { struct pe_section *next; EFI_IMAGE_SECTION_HEADER hdr; void ( * fixup ) ( struct pe_section *section ); + int hidden; uint8_t contents[0]; }; @@ -641,10 +642,12 @@ static struct pe_section * process_section ( struct elf_file *elf, /* Update RVA limits */ start = new->hdr.VirtualAddress; end = ( start + new->hdr.Misc.VirtualSize ); - if ( ( ! *applicable_start ) || ( *applicable_start >= start ) ) - *applicable_start = start; - if ( *applicable_end < end ) - *applicable_end = end; + if ( ! new->hidden ) { + if ( ( ! *applicable_start ) || ( *applicable_start >= start ) ) + *applicable_start = start; + if ( *applicable_end < end ) + *applicable_end = end; + } if ( data_start < code_end ) data_start = code_end; if ( data_mid < data_start ) @@ -664,8 +667,11 @@ static struct pe_section * process_section ( struct elf_file *elf, ( data_end - data_mid ); /* Update remaining file header fields */ - pe_header->nt.FileHeader.NumberOfSections++; - pe_header->nt.OptionalHeader.SizeOfHeaders += sizeof ( new->hdr ); + if ( ! new->hidden ) { + pe_header->nt.FileHeader.NumberOfSections++; + pe_header->nt.OptionalHeader.SizeOfHeaders += + sizeof ( new->hdr ); + } pe_header->nt.OptionalHeader.SizeOfImage = efi_image_align ( data_end ); @@ -935,6 +941,7 @@ static void write_pe_file ( struct pe_header *pe_header, FILE *pe ) { struct pe_section *section; unsigned long fpos = 0; + unsigned int count = 0; /* Align length of headers */ fpos = pe_header->nt.OptionalHeader.SizeOfHeaders = @@ -962,12 +969,16 @@ static void write_pe_file ( struct pe_header *pe_header, /* Write section headers */ for ( section = pe_sections ; section ; section = section->next ) { + if ( section->hidden ) + continue; if ( fwrite ( §ion->hdr, sizeof ( section->hdr ), 1, pe ) != 1 ) { perror ( "Could not write section header" ); exit ( 1 ); } + count++; } + assert ( count == pe_header->nt.FileHeader.NumberOfSections ); /* Write sections */ for ( section = pe_sections ; section ; section = section->next ) { |