1 From 7686eed1a9ed96791cfa65ec5b2f5fdaca538e53 Mon Sep 17 00:00:00 2001
2 From: Olivier Martin <olivier.martin@arm.com>
3 Date: Tue, 11 Jun 2013 10:56:12 +0100
4 Subject: [PATCH 3/8] BaseTools/GenFw: Set the PE/COFF attribute BaseOfCode with the address of the first '.text' section
6 Before this change the alignment of the first code section was not taken into account.
8 Change-Id: I6e6b07edb2f7e7179c9467b43857c44a8309cb68
9 Contributed-under: TianoCore Contribution Agreement 1.0
10 Signed-off-by: Olivier Martin <olivier.martin@arm.com>
12 BaseTools/Source/C/GenFw/Elf32Convert.c | 20 +++++++++++++++++++-
13 BaseTools/Source/C/GenFw/Elf64Convert.c | 19 ++++++++++++++++++-
14 2 files changed, 37 insertions(+), 2 deletions(-)
15 mode change 100644 => 100755 BaseTools/Source/C/GenFw/Elf32Convert.c
16 mode change 100644 => 100755 BaseTools/Source/C/GenFw/Elf64Convert.c
18 diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
21 index ddb45ac..58ac333
22 --- a/BaseTools/Source/C/GenFw/Elf32Convert.c
23 +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
27 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
28 +Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
30 This program and the accompanying materials are licensed and made available
31 under the terms and conditions of the BSD License which accompanies this
32 @@ -18,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
40 @@ -264,9 +266,12 @@ ScanSections32 (
41 EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
52 // Coff file start with a DOS header.
53 @@ -291,7 +296,6 @@ ScanSections32 (
54 // First text sections.
56 mCoffOffset = CoffAlign(mCoffOffset);
57 - mTextOffset = mCoffOffset;
59 for (i = 0; i < mEhdr->e_shnum; i++) {
60 Elf_Shdr *shdr = GetShdrByIndex(i);
61 @@ -315,12 +319,26 @@ ScanSections32 (
62 (mEhdr->e_entry < shdr->sh_addr + shdr->sh_size)) {
63 CoffEntry = mCoffOffset + mEhdr->e_entry - shdr->sh_addr;
67 + // Set mTextOffset with the offset of the first '.text' section
70 + mTextOffset = mCoffOffset;
74 mCoffSectionsOffset[i] = mCoffOffset;
75 mCoffOffset += shdr->sh_size;
81 + Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
85 if (mEhdr->e_machine != EM_ARM) {
86 mCoffOffset = CoffAlign(mCoffOffset);
88 diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
91 index 72d6cd1..713f8f7
92 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
93 +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
94 @@ -19,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
102 @@ -258,9 +259,12 @@ ScanSections64 (
103 EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
114 // Coff file start with a DOS header.
115 @@ -286,7 +290,6 @@ ScanSections64 (
116 // First text sections.
118 mCoffOffset = CoffAlign(mCoffOffset);
119 - mTextOffset = mCoffOffset;
121 for (i = 0; i < mEhdr->e_shnum; i++) {
122 Elf_Shdr *shdr = GetShdrByIndex(i);
123 @@ -310,12 +313,26 @@ ScanSections64 (
124 (mEhdr->e_entry < shdr->sh_addr + shdr->sh_size)) {
125 CoffEntry = (UINT32) (mCoffOffset + mEhdr->e_entry - shdr->sh_addr);
129 + // Set mTextOffset with the offset of the first '.text' section
132 + mTextOffset = mCoffOffset;
136 mCoffSectionsOffset[i] = mCoffOffset;
137 mCoffOffset += (UINT32) shdr->sh_size;
143 + Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
147 if (mEhdr->e_machine != EM_ARM) {
148 mCoffOffset = CoffAlign(mCoffOffset);