]>
Commit | Line | Data |
---|---|---|
c683aa9c OM |
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 | |
5 | ||
6 | Before this change the alignment of the first code section was not taken into account. | |
7 | ||
8 | Change-Id: I6e6b07edb2f7e7179c9467b43857c44a8309cb68 | |
9 | Contributed-under: TianoCore Contribution Agreement 1.0 | |
10 | Signed-off-by: Olivier Martin <olivier.martin@arm.com> | |
11 | --- | |
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 | |
17 | ||
18 | diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c | |
19 | old mode 100644 | |
20 | new mode 100755 | |
21 | index ddb45ac..58ac333 | |
22 | --- a/BaseTools/Source/C/GenFw/Elf32Convert.c | |
23 | +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c | |
24 | @@ -1,6 +1,7 @@ | |
25 | /** @file | |
26 | ||
27 | Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR> | |
28 | +Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR> | |
29 | ||
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. | |
33 | #include <windows.h> | |
34 | #include <io.h> | |
35 | #endif | |
36 | +#include <assert.h> | |
37 | #include <stdio.h> | |
38 | #include <stdlib.h> | |
39 | #include <string.h> | |
40 | @@ -264,9 +266,12 @@ ScanSections32 ( | |
41 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; | |
42 | UINT32 CoffEntry; | |
43 | UINT32 SectionCount; | |
44 | + BOOLEAN FoundText; | |
45 | ||
46 | CoffEntry = 0; | |
47 | mCoffOffset = 0; | |
48 | + mTextOffset = 0; | |
49 | + FoundText = FALSE; | |
50 | ||
51 | // | |
52 | // Coff file start with a DOS header. | |
53 | @@ -291,7 +296,6 @@ ScanSections32 ( | |
54 | // First text sections. | |
55 | // | |
56 | mCoffOffset = CoffAlign(mCoffOffset); | |
57 | - mTextOffset = mCoffOffset; | |
58 | SectionCount = 0; | |
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; | |
64 | } | |
65 | + | |
66 | + // | |
67 | + // Set mTextOffset with the offset of the first '.text' section | |
68 | + // | |
69 | + if (!FoundText) { | |
70 | + mTextOffset = mCoffOffset; | |
71 | + FoundText = TRUE; | |
72 | + } | |
73 | + | |
74 | mCoffSectionsOffset[i] = mCoffOffset; | |
75 | mCoffOffset += shdr->sh_size; | |
76 | SectionCount ++; | |
77 | } | |
78 | } | |
79 | ||
80 | + if (!FoundText) { | |
81 | + Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section."); | |
82 | + assert (FALSE); | |
83 | + } | |
84 | + | |
85 | if (mEhdr->e_machine != EM_ARM) { | |
86 | mCoffOffset = CoffAlign(mCoffOffset); | |
87 | } | |
88 | diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c | |
89 | old mode 100644 | |
90 | new mode 100755 | |
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. | |
95 | #include <windows.h> | |
96 | #include <io.h> | |
97 | #endif | |
98 | +#include <assert.h> | |
99 | #include <stdio.h> | |
100 | #include <stdlib.h> | |
101 | #include <string.h> | |
102 | @@ -258,9 +259,12 @@ ScanSections64 ( | |
103 | EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; | |
104 | UINT32 CoffEntry; | |
105 | UINT32 SectionCount; | |
106 | + BOOLEAN FoundText; | |
107 | ||
108 | CoffEntry = 0; | |
109 | mCoffOffset = 0; | |
110 | + mTextOffset = 0; | |
111 | + FoundText = FALSE; | |
112 | ||
113 | // | |
114 | // Coff file start with a DOS header. | |
115 | @@ -286,7 +290,6 @@ ScanSections64 ( | |
116 | // First text sections. | |
117 | // | |
118 | mCoffOffset = CoffAlign(mCoffOffset); | |
119 | - mTextOffset = mCoffOffset; | |
120 | SectionCount = 0; | |
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); | |
126 | } | |
127 | + | |
128 | + // | |
129 | + // Set mTextOffset with the offset of the first '.text' section | |
130 | + // | |
131 | + if (!FoundText) { | |
132 | + mTextOffset = mCoffOffset; | |
133 | + FoundText = TRUE; | |
134 | + } | |
135 | + | |
136 | mCoffSectionsOffset[i] = mCoffOffset; | |
137 | mCoffOffset += (UINT32) shdr->sh_size; | |
138 | SectionCount ++; | |
139 | } | |
140 | } | |
141 | ||
142 | + if (!FoundText) { | |
143 | + Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section."); | |
144 | + assert (FALSE); | |
145 | + } | |
146 | + | |
147 | if (mEhdr->e_machine != EM_ARM) { | |
148 | mCoffOffset = CoffAlign(mCoffOffset); | |
149 | } | |
150 | -- | |
151 | 1.7.0.4 | |
152 |