NetBSD Problem Report #25467

Received: (qmail 23363 invoked by uid 605); 5 May 2004 08:46:10 -0000
Message-Id: <200405050846.i458k5qh008400@shark1.cambridge.arm.com>
Date: Wed, 5 May 2004 09:46:05 +0100 (BST)
From: Richard.Earnshaw@arm.com
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: Richard.Earnshaw@arm.com
To: gnats-bugs@gnats.NetBSD.org
Subject: objcopy fails to hand link_set sections correctly
X-Send-Pr-Version: 3.95

>Number:         25467
>Category:       toolchain
>Synopsis:       objcopy fails to hand link_set sections correctly
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 05 08:47:00 +0000 2004
>Closed-Date:    Fri Sep 30 07:49:13 +0000 2016
>Last-Modified:  Fri Sep 30 07:49:13 +0000 2016
>Originator:     Richard Earnshaw
>Release:        NetBSD 2.0E
>Organization:
ARM
-- 
>Environment:


System: NetBSD shark1.cambridge.arm.com 2.0E NetBSD 2.0E (SHARK1) #2: Tue Apr 27 17:51:37 BST 2004 rearnsha@pc960.cambridge.arm.com:/work/rearnsha/netbsd/build/src/shark/sys/arch/shark/compile/SHARK1 shark
Architecture: arm
Machine: shark, cats
>Description:

	Objcopy is used to generate a.out bootable images from the ELF kernel
	and tries to handle the link_set sections (special initialization 
	tables in the kernel) by appending them to the .text section.

	Unfortunatley, it doesn't take the size of these sections into account
	when writing out the kernel header, so if the text section grows beyond
	a page boundary then the resuling image headers will be incorrect and
	part of the image won't be loaded correctly.  This causes the kernel
	to be dead at boot time.

	THE FAILURE MODE IS SILENT, SO YOU ONLY KNOW THINGS HAVE FAILED WHEN
	YOU TRY TO BOOT THE KERNEL.


>How-To-Repeat:
	Build and boot various shark and cats kernels, there's about a 1 in 10
	chance that a kernel will be dead (2.0E GENERIC kernels for shark seem
	to suffer from this problem, I believe the distributed 1.6.2 INSTALL
	for shark is similarly broken).

	The key criteria for the failure is that in the ELF image:

	(sizeof .text + sizeof (link_set*)) mod 4096 > (sizeof .text) mod 4096


>Fix:

	Personally, I'm not convinced that the hack introduced into objcopy
	to do this sort of thing is the right approach.  My proposed fix
	would be to ammend the kernel link script to manually incorporate
	each required link section into the script, something like the 
	following (for shark):


Index: kern.ldscript
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/conf/kern.ldscript,v
retrieving revision 1.1
diff -u -r1.1 kern.ldscript
--- kern.ldscript       21 Nov 2002 01:38:41 -0000      1.1
+++ kern.ldscript       5 May 2004 08:41:19 -0000
@@ -15,6 +15,25 @@
     *(.stub)
     *(.glue_7t) *(.glue_7)
     *(.rodata) *(.rodata.*)
+    /* Special link sections for kernel data tables.  We put these in the
+       .text section because objcopy can't translate them into a.out object
+       files and get the section boundaries correct.  */
+    . = ALIGN(4);
+    PROVIDE (__start_link_set_pools = .);
+    *(link_set_pools)
+    PROVIDE (__stop_link_set_pools = .);
+    . = ALIGN(4);
+    PROVIDE (__start_link_set_sysctl_funcs = .);
+    *(link_set_sysctl_funcs)
+    PROVIDE (__stop_link_set_sysctl_funcs = .);
+    . = ALIGN(4);
+    PROVIDE (__start_link_set_malloc_types = .);
+    *(link_set_malloc_types)
+    PROVIDE (__stop_link_set_malloc_types = .);
+    . = ALIGN(4);
+    PROVIDE (__start_link_set_evcnts = .);
+    *(link_set_evcnts)
+    PROVIDE (__stop_link_set_evcnts = .);
   } =0
   PROVIDE (__etext = .);
   PROVIDE (_etext = .);

	Using this method and removing the hack from objcopy would mean that
	we'd get link failures if a new link_set sections were added, but
	at least we'd then have a direct failure mode with an obvious fix.

	Jason, however, seems to think differently: see the discussion on
	port-arm circa 2004/04/27.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 31 Dec 2011 21:33:08 +0000
State-Changed-Why:
Is this still an issue?


From: Richard Earnshaw <Richard.Earnshaw@arm.com>
To: <gnats-bugs@gnats.netbsd.org>
Cc: 
Subject: Re: toolchain/25467
Date: Wed, 20 Jan 2016 11:50:17 +0000

 I've not been using netbsd actively on ARM boards for a while now, so
 I'm afraid I don't know whether this is still a problem or not.
 IMPORTANT NOTICE: The contents of this email and any attachments are confid=
 ential and may also be privileged. If you are not the intended recipient, p=
 lease notify the sender immediately and do not disclose the contents to any=
  other person, use it for any purpose, or store or copy the information in =
 any medium. Thank you.

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/25467: objcopy fails to hand link_set sections correctly
Date: Wed, 20 Jan 2016 13:27:53 +0100

 Whether or not objcopy handles this correctly nowadays is likely moot,
 as src/sys/conf/mkldscript.sh is used to explicitly merge all link_set
 sections into the .text section for a.out conversion.

 Basically this implements what Richard suggested here.

 Martin

State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Fri, 30 Sep 2016 07:49:13 +0000
State-Changed-Why:
feedback came in january and I apparently missed it.
The problem's been fixed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.