aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2007-02-26 09:33:52 -0500
committerSam Ravnborg <sam@ravnborg.org>2007-05-02 14:58:07 -0400
commit85bd2fddd68e757da8e1af98f857f61a3c9ce647 (patch)
tree2570f9ac0ba8ecd6373fec48e923ead773319369
parentdc87c3985e9b442c60994308a96f887579addc39 (diff)
kbuild: fix section mismatch check for vmlinux
vmlinux does not contain relocation entries which is used by the section mismatch checks. Reported by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Use the individual objects as inputs to overcome this limitation. In modpost check the .o files and skip non-ELF files. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
-rw-r--r--Makefile1
-rw-r--r--scripts/Makefile.modpost8
-rw-r--r--scripts/mod/modpost.c33
3 files changed, 26 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index d970cb16545a..5a774cbf6bfa 100644
--- a/Makefile
+++ b/Makefile
@@ -603,6 +603,7 @@ vmlinux-init := $(head-y) $(init-y)
603vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y) 603vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
604vmlinux-all := $(vmlinux-init) $(vmlinux-main) 604vmlinux-all := $(vmlinux-init) $(vmlinux-main)
605vmlinux-lds := arch/$(ARCH)/kernel/vmlinux.lds 605vmlinux-lds := arch/$(ARCH)/kernel/vmlinux.lds
606export KBUILD_VMLINUX_OBJS := $(vmlinux-all)
606 607
607# Rule to link vmlinux - also used during CONFIG_KALLSYMS 608# Rule to link vmlinux - also used during CONFIG_KALLSYMS
608# May be overridden by arch/$(ARCH)/Makefile 609# May be overridden by arch/$(ARCH)/Makefile
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 65e0a79c36cf..d5bbbcce31ef 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -63,16 +63,16 @@ quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
63 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ 63 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
64 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ 64 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
65 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ 65 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
66 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \ 66 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
67 $(wildcard vmlinux) $(filter-out FORCE,$^)
68 67
69PHONY += __modpost 68PHONY += __modpost
70__modpost: $(modules:.ko=.o) FORCE 69__modpost: $(modules:.ko=.o) FORCE
71 $(call cmd,modpost) 70 $(call cmd,modpost) $(wildcard vmlinux) $(filter-out FORCE,$^)
72 71
73quiet_cmd_kernel-mod = MODPOST $@ 72quiet_cmd_kernel-mod = MODPOST $@
74 cmd_kernel-mod = $(cmd_modpost) 73 cmd_kernel-mod = $(cmd_modpost) $(KBUILD_VMLINUX_OBJS)
75 74
75PHONY += vmlinux
76vmlinux: FORCE 76vmlinux: FORCE
77 $(call cmd,kernel-mod) 77 $(call cmd,kernel-mod)
78 78
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 65bdfdb56877..1912c752e422 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -333,10 +333,10 @@ void release_file(void *file, unsigned long size)
333 munmap(file, size); 333 munmap(file, size);
334} 334}
335 335
336static void parse_elf(struct elf_info *info, const char *filename) 336static int parse_elf(struct elf_info *info, const char *filename)
337{ 337{
338 unsigned int i; 338 unsigned int i;
339 Elf_Ehdr *hdr = info->hdr; 339 Elf_Ehdr *hdr;
340 Elf_Shdr *sechdrs; 340 Elf_Shdr *sechdrs;
341 Elf_Sym *sym; 341 Elf_Sym *sym;
342 342
@@ -346,9 +346,18 @@ static void parse_elf(struct elf_info *info, const char *filename)
346 exit(1); 346 exit(1);
347 } 347 }
348 info->hdr = hdr; 348 info->hdr = hdr;
349 if (info->size < sizeof(*hdr)) 349 if (info->size < sizeof(*hdr)) {
350 goto truncated; 350 /* file too small, assume this is an empty .o file */
351 351 return 0;
352 }
353 /* Is this a valid ELF file? */
354 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
355 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
356 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
357 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
358 /* Not an ELF file - silently ignore it */
359 return 0;
360 }
352 /* Fix endianness in ELF header */ 361 /* Fix endianness in ELF header */
353 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); 362 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
354 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); 363 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
@@ -371,8 +380,10 @@ static void parse_elf(struct elf_info *info, const char *filename)
371 = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; 380 = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
372 const char *secname; 381 const char *secname;
373 382
374 if (sechdrs[i].sh_offset > info->size) 383 if (sechdrs[i].sh_offset > info->size) {
375 goto truncated; 384 fatal("%s is truncated. sechdrs[i].sh_offset=%u > sizeof(*hrd)=%ul\n", filename, (unsigned int)sechdrs[i].sh_offset, sizeof(*hdr));
385 return 0;
386 }
376 secname = secstrings + sechdrs[i].sh_name; 387 secname = secstrings + sechdrs[i].sh_name;
377 if (strcmp(secname, ".modinfo") == 0) { 388 if (strcmp(secname, ".modinfo") == 0) {
378 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; 389 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
@@ -407,10 +418,7 @@ static void parse_elf(struct elf_info *info, const char *filename)
407 sym->st_value = TO_NATIVE(sym->st_value); 418 sym->st_value = TO_NATIVE(sym->st_value);
408 sym->st_size = TO_NATIVE(sym->st_size); 419 sym->st_size = TO_NATIVE(sym->st_size);
409 } 420 }
410 return; 421 return 1;
411
412 truncated:
413 fatal("%s is truncated.\n", filename);
414} 422}
415 423
416static void parse_elf_finish(struct elf_info *info) 424static void parse_elf_finish(struct elf_info *info)
@@ -1089,7 +1097,8 @@ static void read_symbols(char *modname)
1089 struct elf_info info = { }; 1097 struct elf_info info = { };
1090 Elf_Sym *sym; 1098 Elf_Sym *sym;
1091 1099
1092 parse_elf(&info, modname); 1100 if (!parse_elf(&info, modname))
1101 return;
1093 1102
1094 mod = new_module(modname); 1103 mod = new_module(modname);
1095 1104