Skip to content

Commit fa57505

Browse files
ardbiesheuvelIngo Molnar
authored and
Ingo Molnar
committed
x86/boot: Drop PE/COFF .reloc section
Ancient buggy EFI loaders may have required a .reloc section to be present at some point in time, but this has not been true for a long time so the .reloc section can just be dropped. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20230915171623.655440-16-ardb@google.com
1 parent efa089e commit fa57505

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

arch/x86/boot/header.S

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,6 @@ section_table:
155155
IMAGE_SCN_MEM_READ | \
156156
IMAGE_SCN_MEM_EXECUTE # Characteristics
157157

158-
#
159-
# The EFI application loader requires a relocation section
160-
# because EFI applications must be relocatable. The .reloc
161-
# offset & size fields are filled in by build.c.
162-
#
163-
.ascii ".reloc"
164-
.byte 0
165-
.byte 0
166-
.long 0
167-
.long 0
168-
.long 0 # SizeOfRawData
169-
.long 0 # PointerToRawData
170-
.long 0 # PointerToRelocations
171-
.long 0 # PointerToLineNumbers
172-
.word 0 # NumberOfRelocations
173-
.word 0 # NumberOfLineNumbers
174-
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
175-
IMAGE_SCN_MEM_READ | \
176-
IMAGE_SCN_MEM_DISCARDABLE # Characteristics
177-
178158
#ifdef CONFIG_EFI_MIXED
179159
#
180160
# The offset & size fields are filled in by build.c.

arch/x86/boot/setup.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ SECTIONS
4040
setup_sig = .;
4141
LONG(0x5a5aaa55)
4242

43-
/* Reserve some extra space for the reloc and compat sections */
44-
setup_size = ALIGN(ABSOLUTE(.) + 64, 512);
43+
/* Reserve some extra space for the compat section */
44+
setup_size = ALIGN(ABSOLUTE(.) + 32, 512);
4545
setup_sects = ABSOLUTE(setup_size / 512);
4646
}
4747

arch/x86/boot/tools/build.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ typedef unsigned int u32;
4747
/* This must be large enough to hold the entire setup */
4848
u8 buf[SETUP_SECT_MAX*512];
4949

50-
#define PECOFF_RELOC_RESERVE 0x20
5150
#define PECOFF_COMPAT_RESERVE 0x20
5251

5352
static unsigned long efi32_pe_entry;
@@ -180,24 +179,13 @@ static void update_pecoff_section_header(char *section_name, u32 offset, u32 siz
180179
update_pecoff_section_header_fields(section_name, offset, size, size, offset);
181180
}
182181

183-
static void update_pecoff_setup_and_reloc(unsigned int size)
182+
static void update_pecoff_setup(unsigned int size)
184183
{
185184
u32 setup_offset = 0x200;
186-
u32 reloc_offset = size - PECOFF_RELOC_RESERVE - PECOFF_COMPAT_RESERVE;
187-
#ifdef CONFIG_EFI_MIXED
188-
u32 compat_offset = reloc_offset + PECOFF_RELOC_RESERVE;
189-
#endif
190-
u32 setup_size = reloc_offset - setup_offset;
185+
u32 compat_offset = size - PECOFF_COMPAT_RESERVE;
186+
u32 setup_size = compat_offset - setup_offset;
191187

192188
update_pecoff_section_header(".setup", setup_offset, setup_size);
193-
update_pecoff_section_header(".reloc", reloc_offset, PECOFF_RELOC_RESERVE);
194-
195-
/*
196-
* Modify .reloc section contents with a single entry. The
197-
* relocation is applied to offset 10 of the relocation section.
198-
*/
199-
put_unaligned_le32(reloc_offset + 10, &buf[reloc_offset]);
200-
put_unaligned_le32(10, &buf[reloc_offset + 4]);
201189

202190
#ifdef CONFIG_EFI_MIXED
203191
update_pecoff_section_header(".compat", compat_offset, PECOFF_COMPAT_RESERVE);
@@ -214,21 +202,10 @@ static void update_pecoff_setup_and_reloc(unsigned int size)
214202
#endif
215203
}
216204

217-
static int reserve_pecoff_reloc_section(int c)
218-
{
219-
/* Reserve 0x20 bytes for .reloc section */
220-
memset(buf+c, 0, PECOFF_RELOC_RESERVE);
221-
return PECOFF_RELOC_RESERVE;
222-
}
223-
224205
#else
225206

226-
static inline void update_pecoff_setup_and_reloc(unsigned int size) {}
207+
static inline void update_pecoff_setup(unsigned int size) {}
227208

228-
static inline int reserve_pecoff_reloc_section(int c)
229-
{
230-
return 0;
231-
}
232209
#endif /* CONFIG_EFI_STUB */
233210

234211
static int reserve_pecoff_compat_section(int c)
@@ -307,7 +284,6 @@ int main(int argc, char ** argv)
307284
fclose(file);
308285

309286
c += reserve_pecoff_compat_section(c);
310-
c += reserve_pecoff_reloc_section(c);
311287

312288
/* Pad unused space with zeros */
313289
setup_sectors = (c + 511) / 512;
@@ -316,7 +292,7 @@ int main(int argc, char ** argv)
316292
i = setup_sectors*512;
317293
memset(buf+c, 0, i-c);
318294

319-
update_pecoff_setup_and_reloc(i);
295+
update_pecoff_setup(i);
320296

321297
/* Open and stat the kernel file */
322298
fd = open(argv[2], O_RDONLY);

0 commit comments

Comments
 (0)