Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Apr 2023 00:32:12 +0800
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Hans Petter Selasky <hselasky@freebsd.org>, FreeBSD CURRENT <freebsd-current@freebsd.org>, Gleb Smirnoff <glebius@freebsd.org>
Subject:   Re: Link modules to DYN type
Message-ID:  <86DC0C8E-56E8-49B9-8441-D64C690FA5F0@FreeBSD.org>
In-Reply-To: <ZEkHKJ_BRhV22gf_@kib.kiev.ua>
References:  <97390FE1-1DF5-43A1-A3F4-2B945D681437@FreeBSD.org> <2bb66cac-c7f1-e45b-693a-8afbda05cfa6@freebsd.org> <ZEkHKJ_BRhV22gf_@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_6539C631-52D9-4A0E-99A2-AF236413CF40
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii



> On Apr 26, 2023, at 7:12 PM, Konstantin Belousov <kostikbel@gmail.com> =
wrote:
>=20
> On Wed, Apr 26, 2023 at 12:55:02PM +0200, Hans Petter Selasky wrote:
>> On 4/26/23 12:36, Zhenlei Huang wrote:
>>> Hi,
>>>=20
>>> I'm recently working on https://reviews.freebsd.org/D39638 =
(sysctl(9): Enable vnet sysctl variables be loader tunable),
>>> the changes to `sys/kern/link_elf_obj.c` are runtime tested, but not =
those to `sys/kern/link_elf.c` .
>>>=20
>>> After some hacking I realized that `link_elf.c` is for EXEC =
(Executable file) or DYN (Shared object file), and `link_elf_obj.c` is
>>> for REL (Relocatable file).
>>>=20
>>> ```
>>> /* link_elf.c */
>>> static int
>>> link_elf_load_file(linker_class_t cls, const char* filename,
>>>     linker_file_t* result)
>>> {
>>> ...
>>> 	if (hdr->e_type !=3D ET_EXEC && hdr->e_type !=3D ET_DYN) {
>>> 		error =3D ENOSYS;
>>> 		goto out;
>>> 	}
>>> ...
>>> }
>>>=20
>>>=20
>>> /* link_elf_obj.c */
>>> static int
>>> link_elf_load_file(linker_class_t cls, const char *filename,
>>>     linker_file_t *result)
>>> {
>>> ...
>>> 	if (hdr->e_type !=3D ET_REL) {
>>> 		error =3D ENOSYS;
>>> 		goto out;
>>> 	}
>>> ...
>>> }
>>> ```
>>>=20
>>> Run the following snip:
>>> ```
>>> # find /boot/kernel -type f -name "*.ko" -exec readelf -h {} \; | =
grep Type
>>> ```
>>> shows that all the kernel modules' types are `REL (Relocatable =
file)`.
>>>=20
>>> I guess if some module such as if_bridge is linked to DYN type, then =
I can do runtime for the changes to `sys/kern/link_elf.c`.
>>>=20
>>> I'm not familiar with elf and linkers, is that ( compile module and =
link it to DYN type ) possible ?
>=20
> Module file type (shared object vs. object file) depends on =
architecture.
> For amd64 modules are objects, while kernel is shared library.
> For arm64 (and all other arches, I believe) modules and kernels are =
shared
> libraries.
>=20
> I think you can link amd64 module as shared object, but this require =
enough
> hacking of the build infrastructure.  At least I am not aware of a =
simple
> knob to switch the produced type.

I did some hack on `sys/conf/kmod.mk` and finally produced DYN kernel =
modules.
The good news is I do some basic sysctl tests, but the bad news is the =
module does not function correctly.

For exampe the if_disc.c

```
static void
vnet_disc_init(const void *unused __unused)
{
	/* Reference V_disc_cloner will immediately trigger page fault =
panic */
	V_disc_cloner =3D if_clone_simple(discname, disc_clone_create,
	    disc_clone_destroy, 0);
}
VNET_SYSINIT(vnet_disc_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
    vnet_disc_init, NULL);
```

I suspect the relocation is not done correctly for  DYN elf kmod on =
amd64.

My local patch to kmod.mk:

```
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 134b150af1d9..1fc5386204a5 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -84,6 +84,7 @@ __KLD_SHARED=3Dyes
 .else
 __KLD_SHARED=3Dno
 .endif
+__KLD_SHARED=3Dyes
=20
 .if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
 CFLAGS+=3D       -fno-strict-aliasing
@@ -167,6 +168,7 @@ CFLAGS+=3D    -fno-omit-frame-pointer =
-mno-omit-leaf-frame-pointer
     ${MACHINE_CPUARCH} =3D=3D "powerpc"
 CFLAGS+=3D       -fPIC
 .endif
+CFLAGS+=3D       -fPIC
=20
 # Temporary workaround for PR 196407, which contains the fascinating =
details.
 # Don't allow clang to use fpu instructions or registers in kernel =
modules.
```


As for https://reviews.freebsd.org/D39638 =
<https://reviews.freebsd.org/D39638>, for other platform such as arm, I =
think the `link_elf_propagate_vnets()` should work if `parse_vnet()` =
works.

I'll appreciate if someone can test it on platforms those have DYN type =
kernel modules.=20

>=20
>=20
>>>=20
>>=20
>> Hi,
>>=20
>> I don't have an answer for you either, but I have seen in the past, =
loading
>> kernel modules behaves a bit like libraries, in the following regard:
>>=20
>> If two kernel modules define the same global symbol, then no warning =
is
>> given and the first loaded symbol definition (I think) is used to =
resolve
>> that symbol for all kernel modules, regardless of the prototype. =
Probably we
>> should not allow this. That's why building LINT is a good thing, to =
avoid
>> this issue.
> No, in-kernel linker does not behave this way.
> Modules need to contain explicit reference to all modules they depend =
upon,
> using the MODULE_DEPEND() macro.  Only symbols from the dependencies =
are
> resolved.
>=20
> All modules get an implicit reference to kernel.
>=20
>>=20
>> Even if we don't have C++ support in the FreeBSD kernel, defining =
symbol
>> names the way C++ does for C could be nice for the kernel too, also =
with
>> regards to debugging systems.
>>=20
>> Many times when I don't know what is going on, I do like this:
>>=20
>> #include <sys/kdb.h>
>>=20
>> ....
>>=20
>> if (not too fast or my sysctl debug) {
>>  printf("My tracer\n");
>>  kdb_backtrace();
>> }
>>=20
>> Dtrace can also do this, but not during boot. Just track who is =
calling
>> those functions, and you'll probably find the answer to your =
question!
>>=20
>> --HPS
>>=20
>>>=20
>>> Best regards,
>>> Zhenlei




--Apple-Mail=_6539C631-52D9-4A0E-99A2-AF236413CF40
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><br =
class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D"">On Apr 26, 2023, at 7:12 PM, Konstantin Belousov &lt;<a =
href=3D"mailto:kostikbel@gmail.com" class=3D"">kostikbel@gmail.com</a>&gt;=
 wrote:</div><br class=3D"Apple-interchange-newline"><div class=3D""><meta=
 charset=3D"UTF-8" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">On Wed, Apr 26, 2023 at 12:55:02PM +0200, Hans Petter Selasky =
wrote:</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><blockquote type=3D"cite" style=3D"font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D"">On =
4/26/23 12:36, Zhenlei Huang wrote:<br class=3D""><blockquote =
type=3D"cite" class=3D"">Hi,<br class=3D""><br class=3D"">I'm recently =
working on <a href=3D"https://reviews.freebsd.org/D39638" =
class=3D"">https://reviews.freebsd.org/D39638</a>; (sysctl(9): Enable =
vnet sysctl variables be loader tunable),<br class=3D"">the changes to =
`sys/kern/link_elf_obj.c` are runtime tested, but not those to =
`sys/kern/link_elf.c` .<br class=3D""><br class=3D"">After some hacking =
I realized that `link_elf.c` is for EXEC (Executable file) or DYN =
(Shared object file), and `link_elf_obj.c` is<br class=3D"">for REL =
(Relocatable file).<br class=3D""><br class=3D"">```<br class=3D"">/* =
link_elf.c */<br class=3D"">static int<br =
class=3D"">link_elf_load_file(linker_class_t cls, const char* =
filename,<br class=3D"">&nbsp;&nbsp;&nbsp;&nbsp;linker_file_t* =
result)<br class=3D"">{<br class=3D"">...<br class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>if =
(hdr-&gt;e_type !=3D ET_EXEC &amp;&amp; hdr-&gt;e_type !=3D ET_DYN) {<br =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span><span class=3D"Apple-tab-span" style=3D"white-space: pre;">	=
</span>error =3D ENOSYS;<br class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span>goto out;<br class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>}<br =
class=3D"">...<br class=3D"">}<br class=3D""><br class=3D""><br =
class=3D"">/* link_elf_obj.c */<br class=3D"">static int<br =
class=3D"">link_elf_load_file(linker_class_t cls, const char =
*filename,<br class=3D"">&nbsp;&nbsp;&nbsp;&nbsp;linker_file_t =
*result)<br class=3D"">{<br class=3D"">...<br class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>if =
(hdr-&gt;e_type !=3D ET_REL) {<br class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span><span =
class=3D"Apple-tab-span" style=3D"white-space: pre;">	</span>error =3D =
ENOSYS;<br class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:=
 pre;">	</span><span class=3D"Apple-tab-span" style=3D"white-space: =
pre;">	</span>goto out;<br class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space: pre;">	</span>}<br class=3D"">...<br =
class=3D"">}<br class=3D"">```<br class=3D""><br class=3D"">Run the =
following snip:<br class=3D"">```<br class=3D""># find /boot/kernel =
-type f -name "*.ko" -exec readelf -h {} \; | grep Type<br =
class=3D"">```<br class=3D"">shows that all the kernel modules' types =
are `REL (Relocatable file)`.<br class=3D""><br class=3D"">I guess if =
some module such as if_bridge is linked to DYN type, then I can do =
runtime for the changes to `sys/kern/link_elf.c`.<br class=3D""><br =
class=3D"">I'm not familiar with elf and linkers, is that ( compile =
module and link it to DYN type ) possible ?<br =
class=3D""></blockquote></blockquote><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">Module file type (shared object vs. object file) depends on =
architecture.</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" class=3D"">For amd64 =
modules are objects, while kernel is shared library.</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 13px; font-style: normal; font-variant-caps: normal; =
font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" class=3D"">For arm64 =
(and all other arches, I believe) modules and kernels are =
shared</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><span style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" =
class=3D"">libraries.</span></div></blockquote><blockquote type=3D"cite" =
class=3D""><div class=3D""><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">I think you can link amd64 module as shared object, but this =
require enough</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">hacking of the build infrastructure. &nbsp;At least I am not =
aware of a simple</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">knob to switch the produced type.</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 13px; font-style: normal; font-variant-caps: normal; =
font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""></div></blockquote><div><br class=3D""></div><div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">I did some =
hack on `sys/conf/kmod.mk` and finally produced DYN kernel =
modules.</div><div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0);">The good news is I do some basic sysctl tests, but the bad news is =
the module does not function correctly.</div><div style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0);"><br class=3D""></div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">For exampe the =
if_disc.c</div><div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, =
0);"><br class=3D""></div><div style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0);">```</div><div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">static =
void</span></font></div><div><font color=3D"#000000" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0);" class=3D"">vnet_disc_init(const =
void *unused __unused)</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">{</span></font></div><div><span class=3D"Apple-tab-span" =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); white-space: =
pre;">	</span>/* Reference V_disc_cloner will immediately trigger page =
fault panic */</div><div><font color=3D"#000000" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0);" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>V_disc_cloner =3D if_clone_simple(discname, =
disc_clone_create,</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span> &nbsp; =
&nbsp;disc_clone_destroy, 0);</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">}</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">VNET_SYSINIT(vnet_disc_init, SI_SUB_PSEUDO, =
SI_ORDER_ANY,</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">&nbsp; =
&nbsp; vnet_disc_init, NULL);</span></font></div></div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">```</div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br =
class=3D""></div></div><div>I suspect the relocation is not done =
correctly for &nbsp;<span style=3D"caret-color: rgb(0, 0, 0); color: =
rgb(0, 0, 0);" class=3D"">DYN elf kmod on amd64.</span></div><div><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=3D""><br =
class=3D""></span></div><div><span style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0);" class=3D"">My local patch to =
kmod.mk:</span></div><div><span style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0);" class=3D""><br class=3D""></span></div><div><span =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" =
class=3D"">```</span></div><div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">diff =
--git a/sys/conf/kmod.mk =
b/sys/conf/kmod.mk</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">index =
134b150af1d9..1fc5386204a5 100644</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">--- a/sys/conf/kmod.mk</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">+++ b/sys/conf/kmod.mk</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">@@ -84,6 +84,7 @@ =
__KLD_SHARED=3Dyes</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;.else</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;__KLD_SHARED=3Dno</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;.endif</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">+__KLD_SHARED=3Dyes</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">&nbsp;.if=
 !empty(CFLAGS:M-O[23s]) &amp;&amp; =
empty(CFLAGS:M-fno-strict-aliasing)</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;CFLAGS+=3D &nbsp; &nbsp; &nbsp; =
-fno-strict-aliasing</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">@@ =
-167,6 +168,7 @@ CFLAGS+=3D &nbsp; &nbsp;-fno-omit-frame-pointer =
-mno-omit-leaf-frame-pointer</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp; &nbsp; &nbsp;${MACHINE_CPUARCH} =3D=3D =
"powerpc"</span></font></div><div><font color=3D"#000000" class=3D""><span=
 style=3D"caret-color: rgb(0, 0, 0);" class=3D"">&nbsp;CFLAGS+=3D &nbsp; =
&nbsp; &nbsp; -fPIC</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;.endif</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">+CFLAGS+=3D=
 &nbsp; &nbsp; &nbsp; -fPIC</span></font></div><div><font =
color=3D"#000000" class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" =
class=3D"">&nbsp;</span></font></div><div><font color=3D"#000000" =
class=3D""><span style=3D"caret-color: rgb(0, 0, 0);" class=3D"">&nbsp;# =
Temporary workaround for PR 196407, which contains the fascinating =
details.</span></font></div><div><font color=3D"#000000" class=3D""><span =
style=3D"caret-color: rgb(0, 0, 0);" class=3D"">&nbsp;# Don't allow =
clang to use fpu instructions or registers in kernel =
modules.</span></font></div></div><div><span style=3D"caret-color: =
rgb(0, 0, 0); color: rgb(0, 0, 0);" class=3D"">```</span></div><div><br =
class=3D""></div><div><br class=3D""></div><div>As for&nbsp;<a =
href=3D"https://reviews.freebsd.org/D39638" =
class=3D"">https://reviews.freebsd.org/D39638</a>, for other platform =
such as arm, I think the `link_elf_propagate_vnets()` should work if =
`parse_vnet()` works.</div><div><br class=3D""></div><div>I'll =
appreciate if someone can test it on platforms those have DYN type =
kernel modules.&nbsp;</div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D""><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><blockquote type=3D"cite" =
style=3D"font-family: Menlo-Regular; font-size: 13px; font-style: =
normal; font-variant-caps: normal; font-weight: 400; letter-spacing: =
normal; orphans: auto; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: auto; word-spacing: =
0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><blockquote type=3D"cite" =
class=3D""><br class=3D""></blockquote><br class=3D"">Hi,<br =
class=3D""><br class=3D"">I don't have an answer for you either, but I =
have seen in the past, loading<br class=3D"">kernel modules behaves a =
bit like libraries, in the following regard:<br class=3D""><br =
class=3D"">If two kernel modules define the same global symbol, then no =
warning is<br class=3D"">given and the first loaded symbol definition (I =
think) is used to resolve<br class=3D"">that symbol for all kernel =
modules, regardless of the prototype. Probably we<br class=3D"">should =
not allow this. That's why building LINT is a good thing, to avoid<br =
class=3D"">this issue.<br class=3D""></blockquote><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 13px; font-style: normal; font-variant-caps: normal; =
font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; float: none; display: inline !important;" class=3D"">No, in-kernel =
linker does not behave this way.</span><br style=3D"caret-color: rgb(0, =
0, 0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">Modules need to contain explicit reference to all modules =
they depend upon,</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">using the MODULE_DEPEND() macro. &nbsp;Only symbols from the =
dependencies are</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">resolved.</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><span style=3D"caret-color: rgb(0, 0, =
0); font-family: Menlo-Regular; font-size: 13px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; float: none; display: inline !important;" =
class=3D"">All modules get an implicit reference to kernel.</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; =
font-size: 13px; font-style: normal; font-variant-caps: normal; =
font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none;" class=3D""><blockquote type=3D"cite" style=3D"font-family: =
Menlo-Regular; font-size: 13px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><br =
class=3D"">Even if we don't have C++ support in the FreeBSD kernel, =
defining symbol<br class=3D"">names the way C++ does for C could be nice =
for the kernel too, also with<br class=3D"">regards to debugging =
systems.<br class=3D""><br class=3D"">Many times when I don't know what =
is going on, I do like this:<br class=3D""><br class=3D"">#include =
&lt;sys/kdb.h&gt;<br class=3D""><br class=3D"">....<br class=3D""><br =
class=3D"">if (not too fast or my sysctl debug) {<br =
class=3D"">&nbsp;printf("My tracer\n");<br =
class=3D"">&nbsp;kdb_backtrace();<br class=3D"">}<br class=3D""><br =
class=3D"">Dtrace can also do this, but not during boot. Just track who =
is calling<br class=3D"">those functions, and you'll probably find the =
answer to your question!<br class=3D""><br class=3D"">--HPS<br =
class=3D""><br class=3D""><blockquote type=3D"cite" class=3D""><br =
class=3D"">Best regards,<br =
class=3D"">Zhenlei</blockquote></blockquote></div></blockquote></div><br =
class=3D""><div class=3D"">
<div><br class=3D""></div>

</div>
<br class=3D""></body></html>=

--Apple-Mail=_6539C631-52D9-4A0E-99A2-AF236413CF40--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86DC0C8E-56E8-49B9-8441-D64C690FA5F0>