|
From: <oli...@us...> - 2013-09-24 09:31:41
|
Revision: 2602
http://sourceforge.net/p/edk2-buildtools/code/2602
Author: oliviermartin
Date: 2013-09-24 09:31:38 +0000 (Tue, 24 Sep 2013)
Log Message:
-----------
BaseTools/GenFw: Set the PE/COFF attribute BaseOfCode with the address of the first '.text' section
Before this change the alignment of the first code section was not taken into account.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <oli...@ar...>
Reviewed-by: Jordan Justen <jor...@in...>
Reviewed-by: Liu, Yingke D <yin...@in...>
Modified Paths:
--------------
trunk/BaseTools/Source/C/GenFw/Elf32Convert.c
trunk/BaseTools/Source/C/GenFw/Elf64Convert.c
Modified: trunk/BaseTools/Source/C/GenFw/Elf32Convert.c
===================================================================
--- trunk/BaseTools/Source/C/GenFw/Elf32Convert.c 2013-09-18 07:10:28 UTC (rev 2601)
+++ trunk/BaseTools/Source/C/GenFw/Elf32Convert.c 2013-09-24 09:31:38 UTC (rev 2602)
@@ -1,6 +1,7 @@
/** @file
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
@@ -18,6 +19,7 @@
#include <windows.h>
#include <io.h>
#endif
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -264,9 +266,12 @@
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
UINT32 CoffEntry;
UINT32 SectionCount;
+ BOOLEAN FoundText;
CoffEntry = 0;
mCoffOffset = 0;
+ mTextOffset = 0;
+ FoundText = FALSE;
//
// Coff file start with a DOS header.
@@ -291,7 +296,6 @@
// First text sections.
//
mCoffOffset = CoffAlign(mCoffOffset);
- mTextOffset = mCoffOffset;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -315,12 +319,26 @@
(mEhdr->e_entry < shdr->sh_addr + shdr->sh_size)) {
CoffEntry = mCoffOffset + mEhdr->e_entry - shdr->sh_addr;
}
+
+ //
+ // Set mTextOffset with the offset of the first '.text' section
+ //
+ if (!FoundText) {
+ mTextOffset = mCoffOffset;
+ FoundText = TRUE;
+ }
+
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size;
SectionCount ++;
}
}
+ if (!FoundText) {
+ Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
+ assert (FALSE);
+ }
+
if (mEhdr->e_machine != EM_ARM) {
mCoffOffset = CoffAlign(mCoffOffset);
}
Modified: trunk/BaseTools/Source/C/GenFw/Elf64Convert.c
===================================================================
--- trunk/BaseTools/Source/C/GenFw/Elf64Convert.c 2013-09-18 07:10:28 UTC (rev 2601)
+++ trunk/BaseTools/Source/C/GenFw/Elf64Convert.c 2013-09-24 09:31:38 UTC (rev 2602)
@@ -19,6 +19,7 @@
#include <windows.h>
#include <io.h>
#endif
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -258,9 +259,12 @@
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
UINT32 CoffEntry;
UINT32 SectionCount;
+ BOOLEAN FoundText;
CoffEntry = 0;
mCoffOffset = 0;
+ mTextOffset = 0;
+ FoundText = FALSE;
//
// Coff file start with a DOS header.
@@ -286,7 +290,6 @@
// First text sections.
//
mCoffOffset = CoffAlign(mCoffOffset);
- mTextOffset = mCoffOffset;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -310,12 +313,26 @@
(mEhdr->e_entry < shdr->sh_addr + shdr->sh_size)) {
CoffEntry = (UINT32) (mCoffOffset + mEhdr->e_entry - shdr->sh_addr);
}
+
+ //
+ // Set mTextOffset with the offset of the first '.text' section
+ //
+ if (!FoundText) {
+ mTextOffset = mCoffOffset;
+ FoundText = TRUE;
+ }
+
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += (UINT32) shdr->sh_size;
SectionCount ++;
}
}
+ if (!FoundText) {
+ Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
+ assert (FALSE);
+ }
+
if (mEhdr->e_machine != EM_ARM) {
mCoffOffset = CoffAlign(mCoffOffset);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|