Subject: Re: kern/21844: netwinder kernal cannot be linked because link_set_* sections overlap with .data
To: None <>
From: Christos Zoulas <>
List: tech-toolchain
Date: 06/19/2003 19:33:09
In article <>,
Ian Lance Taylor <> wrote:
>I assume that you intentionally want the section to be loaded into
>memory at runtime.  If you don't need the section to be loaded into
>memory, then remove the "a" from the initial .section pseudo-op.  That
>should fix the problem.

Well, removing the "a" cause the section to be completely ignored and not
part of the kernel output file.

>Otherwise, the basic problem is that the linker counts the number of
>segments when it sees SIZEOF_HEADERS in the linker script, before it
>knows how many segments it really needs.
>So, hmmm.  You have a loadable .note section, so the linker will want
>to create a PT_NOTE segment.  You are linking statically, so the
>linker is only allocating two other segments when it sees
>SIZEOF_HEADERS, plus the PT_NOTE segment.  It turns out that you need
>another segment.  You should only need three segments if the .note
>section gets merged into the text segment.  Evidently this isn't
>happening--the linker is putting the .note section somewhere else.
>Since the kernel build process uses its own linker script, certainly
>the easy way to handle this is to change the linker script to
>explicitly put the .note section somewhere near the .text section.
>The linker will normally put a loadable .note section immediately
>after the .interp section.  However, in a static link there is no
>.interp section.  So another fix would be more intelligent handling of
>.note sections in that case.  This would be a change to
>gld${EMULATION_NAME}_place_orphan() in ld/emultempl/elf32.em.  Perhaps
>I'll look into that.

Well, I made some changes into that, but it still does not work. I don't
really want to go and change the kernel linker script. It should not
be necessary.

Index: elf32.em
RCS file: /cvsroot/src/gnu/dist/toolchain/ld/emultempl/elf32.em,v
retrieving revision 1.7
diff -u -u -r1.7 elf32.em
--- elf32.em	2003/03/05 21:02:56	1.7
+++ elf32.em	2003/06/19 19:32:45
@@ -1161,9 +1161,14 @@
   if ((s->flags & SEC_ALLOC) == 0)
   else if ((s->flags & SEC_LOAD) != 0
-	   && strncmp (secname, ".note", 5) == 0
-	   && HAVE_SECTION (hold_interp, ".interp"))
-    place = &hold_interp;
+	   && strncmp (secname, ".note", 5) == 0) {
+    if (isdyn && HAVE_SECTION (hold_interp, ".interp"))
+      place = &hold_interp;
+    else if (hold_text.os != NULL)
+      place = &hold_text;
+  } 
+  if (place != NULL)
+    ;
   else if ((s->flags & SEC_HAS_CONTENTS) == 0
 	   && HAVE_SECTION (hold_bss, ".bss"))
     place = &hold_bss;