From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 13 09:01:17 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C8BB116A41A for ; Tue, 13 Jun 2006 09:01:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from fw.zoral.com.ua (ll-227.216.82.212.sovam.net.ua [212.82.216.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 11F6A43D46 for ; Tue, 13 Jun 2006 09:01:16 +0000 (GMT) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by fw.zoral.com.ua (8.13.4/8.13.4) with ESMTP id k5D914Ks012307 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Jun 2006 12:01:04 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6) with ESMTP id k5D91F4c083366; Tue, 13 Jun 2006 12:01:15 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.13.6/8.13.6/Submit) id k5D91Bcx083365; Tue, 13 Jun 2006 12:01:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 13 Jun 2006 12:01:11 +0300 From: Konstantin Belousov To: Divacky Roman Message-ID: <20060613090111.GS54415@deviant.kiev.zoral.com.ua> References: <20060606144455.GA502@stud.fit.vutbr.cz> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="mln0rGgUGuXEqmuI" Content-Disposition: inline In-Reply-To: <20060606144455.GA502@stud.fit.vutbr.cz> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: ClamAV version 0.88.2, clamav-milter version 0.88.2 on fw.zoral.com.ua X-Virus-Status: Clean Cc: hackers@freebsd.org Subject: Re: SoC: strange magic with objcopy and module builds X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jun 2006 09:01:18 -0000 --mln0rGgUGuXEqmuI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 06, 2006 at 04:44:55PM +0200, Divacky Roman wrote: > Hi, >=20 > I am working on SoC linuxolator and I found strange thing I dont know how= to > cope with: >=20 > I made a patch which enables module build of linuxolator on amd64 but it > refuses to kldload because of missing symbol. I tracked the problem down = to > the fact that i386 module build works in a way that it builds .kld and th= en > turns this into .ko: >=20 > ld -Bshareable -d -warn-common -o linux.ko linux.kld >=20 > this line makes transition from U symbol to A symbol. >=20 > Amd64 version uses only .ko, so this step doesnt exist there so those sym= bols > remain U. >=20 > can someone explain me whats going on? >=20 > thnx roman In private communication, Roman said that the problem symbols are __start* and __stop*. That symbols are generated by the static linker for the section start/end. Since AMD64 uses relocatable objects as kld instead of shared ones, that symbols are leaved undefined. Patch below will simulate behaviour of the static linker for the in-kernel elf_obj linker. The patch makes the linker_set.h machinery fully operatable on AMD64. Please test. Index: kern/link_elf_obj.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/local/arch/ncvs/src/sys/kern/link_elf_obj.c,v retrieving revision 1.87.2.3 diff -u -r1.87.2.3 link_elf_obj.c --- kern/link_elf_obj.c 30 Dec 2005 22:13:58 -0000 1.87.2.3 +++ kern/link_elf_obj.c 13 Jun 2006 08:56:08 -0000 @@ -1112,6 +1112,51 @@ } =20 static void +link_elf_fix_link_set(elf_file_t ef) +{ + static const char startn[] =3D "__start_"; + static const char stopn[] =3D "__stop_"; + Elf_Sym *sym; + const char *sym_name, *linkset_name; + Elf_Addr startp, stopp; + Elf_Size symidx; + int start, i; + + startp =3D stopp =3D 0; + for (symidx =3D 1 /* zero entry is special */; + symidx < ef->ddbsymcnt; symidx++) { + sym =3D ef->ddbsymtab + symidx; + if (sym->st_shndx !=3D SHN_UNDEF) + continue; + + sym_name =3D ef->ddbstrtab + sym->st_name; + if (strncmp(sym_name, startn, sizeof(startn) - 1) =3D=3D 0) { + start =3D 1; + linkset_name =3D sym_name + sizeof(startn) - 1; + } + else if (strncmp(sym_name, stopn, sizeof(stopn) - 1) =3D=3D 0) { + start =3D 0; + linkset_name =3D sym_name + sizeof(stopn) - 1; + } + else + continue; + + for (i =3D 0; i < ef->nprogtab; i++) { + if (strcmp(ef->progtab[i].name, linkset_name) =3D=3D 0) { + startp =3D (Elf_Addr)ef->progtab[i].addr; + stopp =3D (Elf_Addr)(startp + ef->progtab[i].size); + break; + } + } + if (i =3D=3D ef->nprogtab) + continue; + + sym->st_value =3D start ? startp : stopp; + sym->st_shndx =3D i; + } +} + +static void link_elf_reloc_local(linker_file_t lf) { elf_file_t ef =3D (elf_file_t)lf; @@ -1124,6 +1169,8 @@ int i; Elf_Size symidx; =20 + link_elf_fix_link_set(ef); + /* Perform relocations without addend if there are any: */ for (i =3D 0; i < ef->nrel; i++) { rel =3D ef->reltab[i].rel; --mln0rGgUGuXEqmuI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (FreeBSD) iD8DBQFEjn7XC3+MBN1Mb4gRAjT8AKDL3nWsdigFsTFbBFoEfnB1zpm5sQCffb7W 2USILVow6G8PYF9CxuUxxNI= =JV6x -----END PGP SIGNATURE----- --mln0rGgUGuXEqmuI--