Sat Mar 21 04:48:38 2020 UTC ()
Teach rump how to process __link_set_sysctl_funcs so it can handle
modules the same as a real kernel.

Partly addresses PR kern/55088 - __link_set_evcnts not yet handled
(that will happen later)


(pgoyette)
diff -r1.31 -r1.32 src/lib/librumpuser/rumpuser_dl.c
diff -r1.3 -r1.4 src/sys/rump/ldscript.rump

cvs diff -r1.31 -r1.32 src/lib/librumpuser/rumpuser_dl.c (expand / switch to unified diff)

--- src/lib/librumpuser/rumpuser_dl.c 2019/12/26 04:53:11 1.31
+++ src/lib/librumpuser/rumpuser_dl.c 2020/03/21 04:48:37 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser_dl.c,v 1.31 2019/12/26 04:53:11 msaitoh Exp $ */ 1/* $NetBSD: rumpuser_dl.c,v 1.32 2020/03/21 04:48:37 pgoyette Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -30,31 +30,36 @@ @@ -30,31 +30,36 @@
30 * Called during rump bootstrap. 30 * Called during rump bootstrap.
31 */ 31 */
32 32
33/* 33/*
34 * Solaris libelf.h doesn't support _FILE_OFFSET_BITS=64. Luckily, 34 * Solaris libelf.h doesn't support _FILE_OFFSET_BITS=64. Luckily,
35 * for this module it doesn't matter. 35 * for this module it doesn't matter.
36 */ 36 */
37#if defined(__sun__) 37#if defined(__sun__)
38#define RUMPUSER_NO_FILE_OFFSET_BITS 38#define RUMPUSER_NO_FILE_OFFSET_BITS
39#endif 39#endif
40#include "rumpuser_port.h" 40#include "rumpuser_port.h"
41 41
42#if !defined(lint) 42#if !defined(lint)
43__RCSID("$NetBSD: rumpuser_dl.c,v 1.31 2019/12/26 04:53:11 msaitoh Exp $"); 43__RCSID("$NetBSD: rumpuser_dl.c,v 1.32 2020/03/21 04:48:37 pgoyette Exp $");
44#endif /* !lint */ 44#endif /* !lint */
45 45
46#include <sys/types.h> 46#include <sys/types.h>
47#include <sys/time.h> 47#include <sys/time.h>
 48
 49#ifdef NOTYET
 50#include <sys/evcnt.h>
 51#endif
 52
48#include <assert.h> 53#include <assert.h>
49 54
50#include <dlfcn.h> 55#include <dlfcn.h>
51#include <errno.h> 56#include <errno.h>
52#include <fcntl.h> 57#include <fcntl.h>
53#include <stdint.h> 58#include <stdint.h>
54#include <stdio.h> 59#include <stdio.h>
55#include <stdlib.h> 60#include <stdlib.h>
56#include <string.h> 61#include <string.h>
57#include <unistd.h> 62#include <unistd.h>
58 63
59#include <rump/rumpuser.h> 64#include <rump/rumpuser.h>
60 65
@@ -343,38 +348,66 @@ getsymbols(struct link_map *map, int ism @@ -343,38 +348,66 @@ getsymbols(struct link_map *map, int ism
343 strtaboff += strlen(cursymname)+1; 348 strtaboff += strlen(cursymname)+1;
344 } 349 }
345 350
346 return 0; 351 return 0;
347} 352}
348 353
349static void 354static void
350process_object(void *handle, 355process_object(void *handle,
351 rump_modinit_fn domodinit, rump_compload_fn docompload) 356 rump_modinit_fn domodinit, rump_compload_fn docompload)
352{ 357{
353 const struct modinfo *const *mi_start, *const *mi_end; 358 const struct modinfo *const *mi_start, *const *mi_end;
354 struct rump_component *const *rc, *const *rc_end; 359 struct rump_component *const *rc, *const *rc_end;
355 360
 361 struct sysctllog;
 362 typedef void sysctl_setup_func(struct sysctllog **);
 363 sysctl_setup_func *const *sfp, *const *sfp_end;
 364
 365#ifdef NOTYET /* We don't yet handle link_set_evcnts */
 366 struct evcnt *const *evp, *const *evp_end;
 367#endif
 368
356 mi_start = dlsym(handle, "__start_link_set_modules"); 369 mi_start = dlsym(handle, "__start_link_set_modules");
357 mi_end = dlsym(handle, "__stop_link_set_modules"); 370 mi_end = dlsym(handle, "__stop_link_set_modules");
358 if (mi_start && mi_end) 371 if (mi_start && mi_end)
359 domodinit(mi_start, (size_t)(mi_end-mi_start)); 372 domodinit(mi_start, (size_t)(mi_end-mi_start));
360 373
361 rc = dlsym(handle, "__start_link_set_rump_components"); 374 rc = dlsym(handle, "__start_link_set_rump_components");
362 rc_end = dlsym(handle, "__stop_link_set_rump_components"); 375 rc_end = dlsym(handle, "__stop_link_set_rump_components");
363 if (rc && rc_end) { 376 if (rc && rc_end) {
364 for (; rc < rc_end; rc++) 377 for (; rc < rc_end; rc++)
365 docompload(*rc); 378 docompload(*rc);
366 assert(rc == rc_end); 379 assert(rc == rc_end);
367 } 380 }
 381
 382 /* handle link_set_sysctl_funcs */
 383 sfp = dlsym(handle, "__start_link_set_sysctl_funcs");
 384 sfp_end = dlsym(handle, "__stop_link_set_sysctl_funcs");
 385 if (sfp && sfp_end) {
 386 for (; sfp < sfp_end; sfp++)
 387 (**sfp)(NULL);
 388 assert(sfp == sfp_end);
 389 }
 390
 391#ifdef NOTYET
 392 /* handle link_set_evcnts */
 393 evp = dlsym(handle, "__start_link_set_evcnts");
 394 evp_end = dlsym(handle, "__stop_link_set_evcnts");
 395 if (evp && evp_end) {
 396 for (; evp < evp_end; evp++)
 397 evcnt_attach_static(*evp);
 398 assert(evp == evp_end);
 399 }
 400#endif
368} 401}
369 402
370/* 403/*
371 * Get the linkmap from the dynlinker. Try to load kernel modules 404 * Get the linkmap from the dynlinker. Try to load kernel modules
372 * from all objects in the linkmap. 405 * from all objects in the linkmap.
373 */ 406 */
374void 407void
375rumpuser_dl_bootstrap(rump_modinit_fn domodinit, 408rumpuser_dl_bootstrap(rump_modinit_fn domodinit,
376 rump_symload_fn symload, rump_compload_fn compload) 409 rump_symload_fn symload, rump_compload_fn compload)
377{ 410{
378 struct link_map *map, *origmap, *mainmap; 411 struct link_map *map, *origmap, *mainmap;
379 void *mainhandle; 412 void *mainhandle;
380 int error; 413 int error;

cvs diff -r1.3 -r1.4 src/sys/rump/ldscript.rump (expand / switch to unified diff)

--- src/sys/rump/ldscript.rump 2014/04/23 17:05:18 1.3
+++ src/sys/rump/ldscript.rump 2020/03/21 04:48:38 1.4
@@ -1,28 +1,42 @@ @@ -1,28 +1,42 @@
1/* $NetBSD: ldscript.rump,v 1.3 2014/04/23 17:05:18 pooka Exp $ */ 1/* $NetBSD: ldscript.rump,v 1.4 2020/03/21 04:48:38 pgoyette Exp $ */
2 2
3/* 3/*
4 * From binutils 2.19 onwards (in NetBSD) binutils ld PROVIDEs 4 * From binutils 2.19 onwards (in NetBSD) binutils ld PROVIDEs
5 * __start/__stop for orphaned sections. This means that 5 * __start/__stop for orphaned sections. This means that
6 * __start_link_set_modules/__stop_link_set_modules will no 6 * __start_link_set_modules/__stop_link_set_modules will no
7 * longer automatically be present in shared libraries. This 7 * longer automatically be present in shared libraries. This
8 * ldscript forces those symbols to be present for all rump 8 * ldscript forces those symbols to be present for all rump
9 * shared lib components. 9 * shared lib components.
10 */ 10 */
11 11
12SECTIONS 12SECTIONS
13{ 13{
14 link_set_modules : 14 link_set_modules :
15 { 15 {
16 __start_link_set_modules = .; 16 __start_link_set_modules = .;
17 *(link_set_modules); 17 *(link_set_modules);
18 __stop_link_set_modules = .; 18 __stop_link_set_modules = .;
19 } 19 }
20 20
21 link_set_rump_components : 21 link_set_rump_components :
22 { 22 {
23 __start_link_set_rump_components = .; 23 __start_link_set_rump_components = .;
24 *(link_set_rump_components); 24 *(link_set_rump_components);
25 __stop_link_set_rump_components = .; 25 __stop_link_set_rump_components = .;
26 } 26 }
 27
 28 link_set_sysctl_funcs :
 29 {
 30 __start_link_set_sysctl_funcs = .;
 31 *(link_set_sysctl_funcs);
 32 __stop_link_set_sysctl_funcs = .;
 33 }
 34
 35 link_set_rump_components :
 36 {
 37 __start_link_set_evcnts = .;
 38 *(link_set_evcnts);
 39 __stop_link_set_evcnts = .;
 40 }
27} 41}
28INSERT AFTER .data; 42INSERT AFTER .data;