Skip to contentSkip to conversation

kbuild, modpost: fix "non-allocatable section" warnings

PATCH New Sam Ravnborg 1 participant 4 messages May 4, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

It turned out there were at least three sources of the "non-allocatable section" warning.

1) SUSE specific .comment section
2) endianness issues in elf header
3) additional debug sections

I have updated kbuild-fixes.git with
patches for all of the above.

But as we have seen three independent sources of this warning within short time I expect there may be yet-to-be-discovered issues.

The patches accumulated so far all looks trivially correct and Jean and Sean has been quick to test them.
So unless something unexpected shows up I plan to push them within a day or two.

I would like to see them in -next for a day or two first in the hope that if other architectures has troubles they will report this before it hits upstream.

Patches will follow for reference / testing.

Sam

#1 lore raw

PATCH 1/3 kbuild, modpost: fix unexpected non-allocatable section when cross compiling

From 7d875a02864a35532543897195dfea2235815df8 Mon Sep 17 00:00:00 2001
From: Anders Kaseorg <[email protected]>
Date: Sun, 3 May 2009 22:02:55 +0200
Subject: [PATCH 1/3] kbuild, modpost: fix unexpected non-allocatable section when cross compiling

The missing TO_NATIVE(sechdrs[i].sh_flags) was causing many unexpected non-allocatable section warnings when cross-compiling for an architecture with a different endianness.

Fix endianness of all the fields in the ELF header and section headers, not just some of them so we are not hit by this anohter time.

---
 scripts/mod/modpost.c |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)
scripts/mod/modpost.c +23 -12
index 936b6f8..a5c17db 100644
@@ -384,11 +384,19 @@ static int parse_elf(struct elf_info *info, const char *filename)
 		return 0;
 	}
 	/* Fix endianness in ELF header */
-	hdr->e_shoff    = TO_NATIVE(hdr->e_shoff);
-	hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
-	hdr->e_shnum    = TO_NATIVE(hdr->e_shnum);
-	hdr->e_machine  = TO_NATIVE(hdr->e_machine);
-	hdr->e_type     = TO_NATIVE(hdr->e_type);
+	hdr->e_type      = TO_NATIVE(hdr->e_type);
+	hdr->e_machine   = TO_NATIVE(hdr->e_machine);
+	hdr->e_version   = TO_NATIVE(hdr->e_version);
+	hdr->e_entry     = TO_NATIVE(hdr->e_entry);
+	hdr->e_phoff     = TO_NATIVE(hdr->e_phoff);
+	hdr->e_shoff     = TO_NATIVE(hdr->e_shoff);
+	hdr->e_flags     = TO_NATIVE(hdr->e_flags);
+	hdr->e_ehsize    = TO_NATIVE(hdr->e_ehsize);
+	hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
+	hdr->e_phnum     = TO_NATIVE(hdr->e_phnum);
+	hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
+	hdr->e_shnum     = TO_NATIVE(hdr->e_shnum);
+	hdr->e_shstrndx  = TO_NATIVE(hdr->e_shstrndx);
 	sechdrs = (void *)hdr + hdr->e_shoff;
 	info->sechdrs = sechdrs;
 
@@ -402,13 +410,16 @@ static int parse_elf(struct elf_info *info, const char *filename)
 
 	/* Fix endianness in section headers */
 	for (i = 0; i < hdr->e_shnum; i++) {
-		sechdrs[i].sh_type   = TO_NATIVE(sechdrs[i].sh_type);
-		sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
-		sechdrs[i].sh_size   = TO_NATIVE(sechdrs[i].sh_size);
-		sechdrs[i].sh_link   = TO_NATIVE(sechdrs[i].sh_link);
-		sechdrs[i].sh_name   = TO_NATIVE(sechdrs[i].sh_name);
-		sechdrs[i].sh_info   = TO_NATIVE(sechdrs[i].sh_info);
-		sechdrs[i].sh_addr   = TO_NATIVE(sechdrs[i].sh_addr);
+		sechdrs[i].sh_name      = TO_NATIVE(sechdrs[i].sh_name);
+		sechdrs[i].sh_type      = TO_NATIVE(sechdrs[i].sh_type);
+		sechdrs[i].sh_flags     = TO_NATIVE(sechdrs[i].sh_flags);
+		sechdrs[i].sh_addr      = TO_NATIVE(sechdrs[i].sh_addr);
+		sechdrs[i].sh_offset    = TO_NATIVE(sechdrs[i].sh_offset);
+		sechdrs[i].sh_size      = TO_NATIVE(sechdrs[i].sh_size);
+		sechdrs[i].sh_link      = TO_NATIVE(sechdrs[i].sh_link);
+		sechdrs[i].sh_info      = TO_NATIVE(sechdrs[i].sh_info);
+		sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign);
+		sechdrs[i].sh_entsize   = TO_NATIVE(sechdrs[i].sh_entsize);
 	}
 	/* Find symbol table. */
 	for (i = 1; i < hdr->e_shnum; i++) {
Signature · 1 line
1.6.3.rc3.40.g75b44
#2 lore raw

PATCH 2/3 kbuild, modpost: fix "unexpected non-allocatable" warning with SUSE gcc

In reply to Sam Ravnborg

From 028ecebdd83cc4a7f8c7e96e28a5537d2ac98dae Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sun, 3 May 2009 22:17:37 +0200
Subject: [PATCH 2/3] kbuild, modpost: fix "unexpected non-allocatable" warning with SUSE gcc

Jean reported that he saw one warning for each module like the one below:
WARNING: arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.o (.comment.SUSE.OPTs): unexpected non-allocatable section.

The warning appeared with the improved version of the check of the flags in the sections.

That check already ignored sections named ".comment" - but SUSE store additional info in the comment section and has named it in a SUSE specific way. Therefore modpost failed to ignore the section.

The fix is to extend the pattern so we ignore all sections that start with the name ".comment.".

---
 scripts/mod/modpost.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/mod/modpost.c +1 -1
index a5c17db..268d457 100644
@@ -727,7 +727,7 @@ int match(const char *sym, const char * const pat[])
 
 /* sections that we do not want to do full section mismatch check on */
 static const char *section_white_list[] =
-	{ ".comment", ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL };
+	{ ".comment*", ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL };
 
 /*
  * This is used to find sections missing the SHF_ALLOC flag.
Signature · 1 line
1.6.3.rc3.40.g75b44
#3 lore raw

PATCH 3/3 kbuild, modpost: fix unexpected non-allocatable warning with mips

In reply to Sam Ravnborg
Quoted 1 line

From 4391ed6aa9a38cdfb48addd7a9b24a2ff099b1a7 Mon Sep 17 00:00:00 2001

From: Sam Ravnborg <[email protected]>
Date: Mon, 4 May 2009 13:05:26 +0200
Subject: [PATCH 3/3] kbuild, modpost: fix unexpected non-allocatable warning with mips

mips emit the following debug sections:
.mdebug* and .pdr

They were included in the check for non-allocatable section and caused modpost to warn.

Manuel Lauss suggested to fix this by adding the relevant sections to the list of sections we do not check.

---
 scripts/mod/modpost.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
scripts/mod/modpost.c +11 -1
index 268d457..161b784 100644
@@ -727,7 +727,17 @@ int match(const char *sym, const char * const pat[])
 
 /* sections that we do not want to do full section mismatch check on */
 static const char *section_white_list[] =
-	{ ".comment*", ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL };
+{
+	".comment*",
+	".debug*",
+	".mdebug*",        /* alpha, score, mips etc. */
+	".pdr",            /* alpha, score, mips etc. */
+	".stab*",
+	".note*",
+	".got*",
+	".toc*",
+	NULL
+};
 
 /*
  * This is used to find sections missing the SHF_ALLOC flag.
Signature · 1 line
1.6.3.rc3.40.g75b44