Skip to content

Commit e549317

Browse files
author
Daniel Kiper
committed
windows: Fix symbol table generation during module conversion from PE to ELF
According to the System V Application Binary Interface specification [1] the sections holding a symbol table, SHT_SYMTAB and SHT_DYNSYM, have to have sh_info set to "One greater than the symbol table index of the last local symbol (binding STB_LOCAL)". Current code converting PE images to ELF files does not do that and readelf complains in following way: ... Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000034 0014d4 00 AX 0 0 4 [ 2] .data PROGBITS 00000000 001508 000040 00 WA 0 0 32 [ 3] .rdata PROGBITS 00000000 001548 0006b8 00 A 0 0 4 [ 4] .module_license PROGBITS 00000000 001c00 000010 00 0 0 4 [ 5] .bss NOBITS 00000000 000000 000008 00 WA 0 0 4 [ 6] .moddeps PROGBITS 00000000 001c10 000010 00 0 0 4 [ 7] .modname PROGBITS 00000000 001c20 000008 00 0 0 4 [ 8] .rel.text REL 00000000 001c28 0008c8 08 11 1 4 [ 9] .rel.data REL 00000000 0024f0 000040 08 11 2 4 [10] .rel.rdata REL 00000000 002530 000070 08 11 3 4 [11] .symtab SYMTAB 00000000 0025a0 0001d0 10 12 0 4 [12] .strtab STRTAB 00000000 002770 000237 00 0 0 1 ... Symbol table '.symtab' contains 29 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND readelf: Warning: local symbol 0 found at index >= .symtab's sh_info value of 0 1: 0000144a 0 FUNC LOCAL DEFAULT 1 grub_mod_init readelf: Warning: local symbol 1 found at index >= .symtab's sh_info value of 0 2: 000014aa 0 FUNC LOCAL DEFAULT 1 grub_mod_fini readelf: Warning: local symbol 2 found at index >= .symtab's sh_info value of 0 3: 00000000 0 SECTION LOCAL DEFAULT 1 .text readelf: Warning: local symbol 3 found at index >= .symtab's sh_info value of 0 4: 00000000 0 SECTION LOCAL DEFAULT 2 .data readelf: Warning: local symbol 4 found at index >= .symtab's sh_info value of 0 5: 00000000 0 SECTION LOCAL DEFAULT 5 .bss readelf: Warning: local symbol 5 found at index >= .symtab's sh_info value of 0 6: 00000000 0 SECTION LOCAL DEFAULT 3 .rdata readelf: Warning: local symbol 6 found at index >= .symtab's sh_info value of 0 7: 00000000 0 NOTYPE GLOBAL DEFAULT UND grub_dma_get_phys 8: 00000000 0 NOTYPE GLOBAL DEFAULT UND grub_cs5536_write_msr 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND grub_dma_free ... Let's fix it... [1] https://www.sco.com/developers/gabi/2012-12-31/contents.html Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> Reviewed-by: Ross Philipson <ross.philipson@oracle.com> Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
1 parent a340750 commit e549317

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

util/grub-pe2elf.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ write_symbol_table (FILE* fp, const char *name, char *image,
360360
struct grub_pe32_symbol *pe_symtab;
361361
char *pe_strtab;
362362
Elf_Sym *symtab;
363-
int *symtab_map, num_syms;
363+
int *symtab_map, num_syms, last_stb_local = 0;
364364
int i;
365365

366366
pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset);
@@ -391,7 +391,10 @@ write_symbol_table (FILE* fp, const char *name, char *image,
391391
if (pe_symtab->storage_class == GRUB_PE32_SYM_CLASS_EXTERNAL)
392392
bind = STB_GLOBAL;
393393
else
394-
bind = STB_LOCAL;
394+
{
395+
bind = STB_LOCAL;
396+
last_stb_local = num_syms;
397+
}
395398

396399
if ((pe_symtab->type != GRUB_PE32_DT_FUNCTION) && (pe_symtab->num_aux))
397400
{
@@ -441,6 +444,7 @@ write_symbol_table (FILE* fp, const char *name, char *image,
441444
shdr[symtab_section].sh_size = num_syms * sizeof (Elf_Sym);
442445
shdr[symtab_section].sh_entsize = sizeof (Elf_Sym);
443446
shdr[symtab_section].sh_link = strtab_section;
447+
shdr[symtab_section].sh_info = ++last_stb_local;
444448
shdr[symtab_section].sh_addralign = 4;
445449

446450
grub_util_write_image_at (symtab, shdr[symtab_section].sh_size,

0 commit comments

Comments
 (0)