Date: Fri, 30 Mar 2012 23:36:05 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Richard Yao <ryao@cs.stonybrook.edu> Cc: freebsd-stable@freebsd.org Subject: Re: Text relocations in kernel modules Message-ID: <20120330203605.GI2358@deviant.kiev.zoral.com.ua> In-Reply-To: <4F761371.7020606@cs.stonybrook.edu> References: <4F75E404.8000104@cs.stonybrook.edu> <4F75EF86.6090909@cs.stonybrook.edu> <20120330190713.GG2358@deviant.kiev.zoral.com.ua> <4F760C9E.6060405@cs.stonybrook.edu> <20120330194649.GH2358@deviant.kiev.zoral.com.ua> <4F761371.7020606@cs.stonybrook.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
--i0xbckOs9ckBzXei Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 30, 2012 at 04:11:29PM -0400, Richard Yao wrote: > On 03/30/12 15:46, Konstantin Belousov wrote: > > On Fri, Mar 30, 2012 at 03:42:22PM -0400, Richard Yao wrote: > >> On 03/30/12 15:07, Konstantin Belousov wrote: > >>>> Is this a bug? > >>> No. This is by design. > >>> > >>> Why do you consider this a bug ? > >> > >> It occurs on i386, but not amd64. It could be that something is wrong > >> with how things are being compiled i386, or it could be that i386 > >> requires things to be compiled this way. I do not know which. > >> > > Again, let me repeat my question. Why do you consider the presence > > of relocations against text section a problem ? >=20 > The linker emits warnings: > i686-gentoo-freebsd9.0-ld: warning: creating a DT_TEXTREL in object. >=20 > Furthermore, this triggers a QA check in Gentoo/FreeBSD's package manager. >=20 > * QA Notice: The following files contain runtime text relocations > * Text relocations force the dynamic linker to perform extra > * work at startup, waste system resources, and may pose a security > * risk. On some architectures, the code may not even function > * properly, if at all. > * For more information, see http://hardened.gentoo.org/pic-fix-guide.xml > * Please include the following list of files in your report: > * TEXTREL boot/modules/if_vtnet.ko > * TEXTREL boot/modules/virtio_blk.ko > * TEXTREL boot/modules/virtio.ko > * TEXTREL boot/modules/virtio_balloon.ko > * TEXTREL boot/modules/virtio_pci.ko >=20 > I wrote that ebuild as part of something entirely unrelated. If it is a > feature, I can disable the QA check, but I should at least know why the > text relocations are needed. >=20 > Gentoo maintainers are expected to patch text relocations and send > patches upstream. The only exception is in the case of binary packages, > which they cannot patch. >=20 > Investigating the text relocations in my port of emulators/virtio-kmod > revealed that all kernel modules on i386 Gentoo/FreeBSD have text > relocations, yet none have them on amd64 FreeBSD, so I do not know > whether this is a bug or a feature. >=20 First, there _are_ relocations against text in the amd64 modules, but I suspect that your scripts do not detect this. Most likely, scripts look for DT_TEXTREL dynamic tag, and tags are only present in the executables or shared objects, not in the object files. The amd64 modules are object files, so you just mis-interpret the situation. Second, from what you wrote, I see the issue in either wrong policy being established in your project, or (another) mis-interpretation of the policy. Indeed, having text relocations in the shared objects is bad, because said relocations hinder text pages sharing. Relocated page is modified, so COW mechanism causes it to become private to process. On the other hand, there is only one instance of the loaded kernel module, its text segment (or section, for amd64) is not shared, so modifications to the text pages do not cause increased memory use. More, not compiling modules with -fPIC (absence of -fPIC is what makes the text relocations to appear in the final link result) makes the code faster, esp. on i386. So, there is nothing to report, and fix is outside the FreeBSD domain: either fix your policy by not stating that text relocation in kernel module is banned, or just find that policy only applicable to usermode objects. --i0xbckOs9ckBzXei Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk92GTQACgkQC3+MBN1Mb4g7cQCgnitw46a68Tb8cyxG+6Ze2KOZ MkAAoNetmv8hRzJLz7mBs0pRq8Fqdx+4 =e9HE -----END PGP SIGNATURE----- --i0xbckOs9ckBzXei--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120330203605.GI2358>