Bladeren bron

[efi] Populate debug directory entry FileOffset field

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 jaren geleden
bovenliggende
commit
619a377328
1 gewijzigde bestanden met toevoegingen van 19 en 0 verwijderingen
  1. 19
    0
      src/util/elf2efi.c

+ 19
- 0
src/util/elf2efi.c Bestand weergeven

@@ -41,6 +41,7 @@
41 41
 struct pe_section {
42 42
 	struct pe_section *next;
43 43
 	EFI_IMAGE_SECTION_HEADER hdr;
44
+	void ( * fixup ) ( struct pe_section *section );
44 45
 	uint8_t contents[0];
45 46
 };
46 47
 
@@ -547,6 +548,20 @@ create_reloc_section ( struct pe_header *pe_header,
547 548
 	return reloc;
548 549
 }
549 550
 
551
+/**
552
+ * Fix up debug section
553
+ *
554
+ * @v debug		Debug section
555
+ */
556
+static void fixup_debug_section ( struct pe_section *debug ) {
557
+	EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *contents;
558
+
559
+	/* Fix up FileOffset */
560
+	contents = ( ( void * ) debug->contents );
561
+	contents->FileOffset += ( debug->hdr.PointerToRawData -
562
+				  debug->hdr.VirtualAddress );
563
+}
564
+
550 565
 /**
551 566
  * Create debug section
552 567
  *
@@ -581,6 +596,7 @@ create_debug_section ( struct pe_header *pe_header, const char *filename ) {
581 596
 	debug->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
582 597
 				       EFI_IMAGE_SCN_MEM_NOT_PAGED |
583 598
 				       EFI_IMAGE_SCN_MEM_READ );
599
+	debug->fixup = fixup_debug_section;
584 600
 
585 601
 	/* Create section contents */
586 602
 	contents->debug.TimeDateStamp = 0x10d1a884;
@@ -589,6 +605,7 @@ create_debug_section ( struct pe_header *pe_header, const char *filename ) {
589 605
 		( sizeof ( *contents ) - sizeof ( contents->debug ) );
590 606
 	contents->debug.RVA = ( debug->hdr.VirtualAddress +
591 607
 				offsetof ( typeof ( *contents ), rsds ) );
608
+	contents->debug.FileOffset = contents->debug.RVA;
592 609
 	contents->rsds.Signature = CODEVIEW_SIGNATURE_RSDS;
593 610
 	snprintf ( contents->name, sizeof ( contents->name ), "%s",
594 611
 		   filename );
@@ -629,6 +646,8 @@ static void write_pe_file ( struct pe_header *pe_header,
629 646
 			fpos += section->hdr.SizeOfRawData;
630 647
 			fpos = efi_file_align ( fpos );
631 648
 		}
649
+		if ( section->fixup )
650
+			section->fixup ( section );
632 651
 	}
633 652
 
634 653
 	/* Write file header */

Laden…
Annuleren
Opslaan