Date: Tue, 13 Jun 2006 12:01:11 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Divacky Roman <xdivac02@stud.fit.vutbr.cz> Cc: hackers@freebsd.org Subject: Re: SoC: strange magic with objcopy and module builds Message-ID: <20060613090111.GS54415@deviant.kiev.zoral.com.ua> In-Reply-To: <20060606144455.GA502@stud.fit.vutbr.cz> References: <20060606144455.GA502@stud.fit.vutbr.cz>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060613090111.GS54415>
