Browse Source

[efi] Populate debug directory entry FileOffset field

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
619a377328
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      src/util/elf2efi.c

+ 19
- 0
src/util/elf2efi.c View File

41
 struct pe_section {
41
 struct pe_section {
42
 	struct pe_section *next;
42
 	struct pe_section *next;
43
 	EFI_IMAGE_SECTION_HEADER hdr;
43
 	EFI_IMAGE_SECTION_HEADER hdr;
44
+	void ( * fixup ) ( struct pe_section *section );
44
 	uint8_t contents[0];
45
 	uint8_t contents[0];
45
 };
46
 };
46
 
47
 
547
 	return reloc;
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
  * Create debug section
566
  * Create debug section
552
  *
567
  *
581
 	debug->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
596
 	debug->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
582
 				       EFI_IMAGE_SCN_MEM_NOT_PAGED |
597
 				       EFI_IMAGE_SCN_MEM_NOT_PAGED |
583
 				       EFI_IMAGE_SCN_MEM_READ );
598
 				       EFI_IMAGE_SCN_MEM_READ );
599
+	debug->fixup = fixup_debug_section;
584
 
600
 
585
 	/* Create section contents */
601
 	/* Create section contents */
586
 	contents->debug.TimeDateStamp = 0x10d1a884;
602
 	contents->debug.TimeDateStamp = 0x10d1a884;
589
 		( sizeof ( *contents ) - sizeof ( contents->debug ) );
605
 		( sizeof ( *contents ) - sizeof ( contents->debug ) );
590
 	contents->debug.RVA = ( debug->hdr.VirtualAddress +
606
 	contents->debug.RVA = ( debug->hdr.VirtualAddress +
591
 				offsetof ( typeof ( *contents ), rsds ) );
607
 				offsetof ( typeof ( *contents ), rsds ) );
608
+	contents->debug.FileOffset = contents->debug.RVA;
592
 	contents->rsds.Signature = CODEVIEW_SIGNATURE_RSDS;
609
 	contents->rsds.Signature = CODEVIEW_SIGNATURE_RSDS;
593
 	snprintf ( contents->name, sizeof ( contents->name ), "%s",
610
 	snprintf ( contents->name, sizeof ( contents->name ), "%s",
594
 		   filename );
611
 		   filename );
629
 			fpos += section->hdr.SizeOfRawData;
646
 			fpos += section->hdr.SizeOfRawData;
630
 			fpos = efi_file_align ( fpos );
647
 			fpos = efi_file_align ( fpos );
631
 		}
648
 		}
649
+		if ( section->fixup )
650
+			section->fixup ( section );
632
 	}
651
 	}
633
 
652
 
634
 	/* Write file header */
653
 	/* Write file header */

Loading…
Cancel
Save