From owner-freebsd-current@FreeBSD.ORG  Tue Jun 22 21:07:31 2010
Return-Path: <owner-freebsd-current@FreeBSD.ORG>
Delivered-To: freebsd-current@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 327551065677
	for <freebsd-current@freebsd.org>; Tue, 22 Jun 2010 21:07:31 +0000 (UTC)
	(envelope-from faber@zod.isi.edu)
Received: from zod.isi.edu (zod.isi.edu [128.9.168.221])
	by mx1.freebsd.org (Postfix) with ESMTP id 1182C8FC24
	for <freebsd-current@freebsd.org>; Tue, 22 Jun 2010 21:07:30 +0000 (UTC)
Received: from zod.isi.edu (localhost [127.0.0.1])
	by zod.isi.edu (8.14.4/8.14.4) with ESMTP id o5ML7N8r021850;
	Tue, 22 Jun 2010 14:07:23 -0700 (PDT)
	(envelope-from faber@zod.isi.edu)
Received: (from faber@localhost)
	by zod.isi.edu (8.14.4/8.14.4/Submit) id o5ML7LGU021849;
	Tue, 22 Jun 2010 14:07:21 -0700 (PDT) (envelope-from faber)
Date: Tue, 22 Jun 2010 14:07:21 -0700
From: Ted Faber <faber@isi.edu>
To: Ryan Stone <rysto32@gmail.com>
Message-ID: <20100622210721.GC18012@zod.isi.edu>
References: <permail-20100305171533f7e55a9d0000225a-a_best01@message-id.uni-muenster.de>
	<201003301510.58203.jhb@freebsd.org> <87bpe4ps9m.fsf@kobe.laptop>
	<201006222208.23271.hselasky@c2i.net>
	<AANLkTimD3Hcjqpy2w9Q0tvVDJ01gCH1ClSQCj2c4MFBz@mail.gmail.com>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="c3bfwLpm8qysLVxt"
Content-Disposition: inline
In-Reply-To: <AANLkTimD3Hcjqpy2w9Q0tvVDJ01gCH1ClSQCj2c4MFBz@mail.gmail.com>
User-Agent: Mutt/1.4.2.3i
X-url: http://www.isi.edu/~faber
Cc: Bruce Cran <bruce@cran.org.uk>,
	"Sergey V. Dyatko" <sergey.dyatko@gmail.com>, freebsd-hackers@freebsd.org,
	Hans Petter Selasky <hselasky@c2i.net>,
	Alexander Best <alexbestms@wwu.de>, freebsd-current@freebsd.org,
	Giorgos Keramidas <keramida@ceid.upatras.gr>
Subject: Re: building world with debugging symbols [broken?]
X-BeenThere: freebsd-current@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Discussions about the use of FreeBSD-current
	<freebsd-current.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>, 
	<mailto:freebsd-current-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-current>
List-Post: <mailto:freebsd-current@freebsd.org>
List-Help: <mailto:freebsd-current-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>,
	<mailto:freebsd-current-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 22 Jun 2010 21:07:31 -0000


--c3bfwLpm8qysLVxt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jun 22, 2010 at 04:39:17PM -0400, Ryan Stone wrote:
> I saw similar behaviour a couple of years ago when I switched from
> using gcc 4.0.2 to gcc 4.3.0 to compile some out-of-tree KLD modules.
> The problem ended up being a change in the linker script used by GNU
> ld for linking kernel modules.  It used to always put some magic
> symbols used by the linker to implement things like sysinits into the
> module.  It was changed to only provide those symbols, which
> apparently means that the linker would discard those symbols if
> nothing referenced them(and nothing did reference them).  I had to
> work around it by adding the following to my link line:
>=20
> -u __start_set_sysinit_set -u __start_set_sysuninit_set \
> -u __start_set_sysctl_set -u __start_set_modmetadata_set \
> -u __stop_set_sysinit_set -u __stop_set_sysuninit_set \
> -u __stop_set_sysctl_set -u __stop_set_modmetadata_set

HPS:

I added those lines to the LDFLAGS in Makefile.kmod in the cuse4bsd port
made the module and the result loads and creates the /dev/cuse file.

Here's a diff relative to
/usr/ports/multimedia/cuse4bsd-kmod/work/cuse4bsd-kmod-0.1.11 just so
it's clear what I did.


--- Makefile.kmod.orig  2010-02-11 03:28:02.000000000 -0800
+++ Makefile.kmod       2010-06-22 14:02:52.000000000 -0700
@@ -30,4 +30,10 @@
 KMOD=3D  cuse4bsd
 SRCS=3D  cuse4bsd_kmod.c device_if.h bus_if.h vnode_if.h
=20
+LDFLAGS +=3D -u __start_set_sysinit_set -u __start_set_sysuninit_set \
+ -u __start_set_sysctl_set -u __start_set_modmetadata_set \
+ -u __stop_set_sysinit_set -u __stop_set_sysuninit_set \
+ -u __stop_set_sysctl_set -u __stop_set_modmetadata_set
+
+
 .include <bsd.kmod.mk>

Running nm -o on the two modules, the difference seems to be that the -u
results in some additional absolute symbols being defined:

Bad module:
$ nm -o /boot/modules/cuse4bsd.ko| grep sys
/boot/modules/cuse4bsd.ko:0000275c r
__set_sysinit_set_sym_cuse_kern_init_sys_init
/boot/modules/cuse4bsd.ko:00002758 r __set_sysuninit_set_sym_cuse_kern_unin=
it_sys_uninit
/boot/modules/cuse4bsd.ko:00003194 d cuse_kern_init_sys_init
/boot/modules/cuse4bsd.ko:00003184 d cuse_kern_uninit_sys_uninit

Good module:

$ nm -o ./cuse4bsd.ko  | grep sys
=2E/cuse4bsd.ko:000028cc r __set_sysinit_set_sym_cuse_kern_init_sys_init
=2E/cuse4bsd.ko:000028c8 r __set_sysuninit_set_sym_cuse_kern_uninit_sys_uni=
nit
=2E/cuse4bsd.ko:         U __start_set_sysctl_set
=2E/cuse4bsd.ko:000028cc A __start_set_sysinit_set
=2E/cuse4bsd.ko:000028c8 A __start_set_sysuninit_set
=2E/cuse4bsd.ko:         U __stop_set_sysctl_set
=2E/cuse4bsd.ko:000028d0 A __stop_set_sysinit_set
=2E/cuse4bsd.ko:000028cc A __stop_set_sysuninit_set
=2E/cuse4bsd.ko:00003194 d cuse_kern_init_sys_init
=2E/cuse4bsd.ko:00003184 d cuse_kern_uninit_sys_uninit


--=20
Ted Faber
http://www.isi.edu/~faber           PGP: http://www.isi.edu/~faber/pubkeys.=
asc
Unexpected attachment on this mail? See http://www.isi.edu/~faber/FAQ.html#=
SIG

--c3bfwLpm8qysLVxt
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAkwhJgkACgkQaUz3f+Zf+XsIHQCg01pjgmyQMtRhCxX5Vcecfmh6
oAEAoMjEQJnq4qzA5nrwpptyHFNnnJ+T
=tM4z
-----END PGP SIGNATURE-----

--c3bfwLpm8qysLVxt--