Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for suggestion of building a liblkl.so without libc #264

Closed
liuyuan10 opened this issue Nov 16, 2016 · 2 comments
Closed

Ask for suggestion of building a liblkl.so without libc #264

liuyuan10 opened this issue Nov 16, 2016 · 2 comments

Comments

@liuyuan10
Copy link
Member

dlmopen of liblkl.so brings so many troubles and one that I can't get around is limitation of static TLS. Now liblkl.so depends on libc which may use static TLS. At runtime, the amount of static TLS is fixed so dlmopen may fail.

To overcome this, I'd like to introduce another layer like struct lkl_libc. It's similar to lkl_host_ops but only accessible in tools/lkl/lib. So struct lkl_libc looks like:

struct lkl_libc {
memcpy
memset
strcpy...
}

And there will be a lkl_libc.c which is shared by both posix-host and nt-host.

A new host called nonlibc-host is added that provides empty lkl_host_ops and lkl_libc so the final liblkl.so doesn't depends on libc at all. In application, at run time, after dlmopen it, lkl_host_ops and lkl_libc is properly set so all liblkl.so instances share the same libc/libpthread.

I guess it may also simplify the work in #255 where a new libc implementation can be easily integrated.

Please let me know your opinions. Thanks

@thehajime
Copy link
Member

just curious - are you going to re-implement pthread used in posix-host.c ?

I guess it may also simplify the work in #255 where a new libc implementation can be easily integrated.

actually #255 has two libc implementation when it's integrated with frankenlibc - 1) frankenlibc, an implementation of libc functions for underlying host (linux, netbsd, freebsd, qemu-arm, etc) used by host_ops (or rump hypercalls), and 2) musl-extended libc for upper applications.

so, though i'm not quite sure what the @liuyuan10's original guess is, there is already lkl_libc.c-ish implementation out there (note: native thread/posix thread is not supported yet).

another question would be: isn't reimplementation of libdl.so enough to overcome the static TLS issue ?

@liuyuan10
Copy link
Member Author

Embarrassing. Turns out I don't have to use dlmopen but rename liblkl.so multiple times and I'm able to load LKL tens of times this way. It helps to avoid all the troubles from dlmopen and I'm happy to get rid of it.

Closing it... Sorry for the noise.

rodionov pushed a commit to rodionov/lkl that referenced this issue Jan 2, 2025
Add a new test case which performs double query of the bpf_mprog through
libbpf API, but also via raw bpf(2) syscall. This is testing to gather
first the count and then in a subsequent probe the full information with
the program array without clearing passed structs in between.

  # ./vmtest.sh -- ./test_progs -t tc_opts
  [...]
  ./test_progs -t tc_opts
  [    1.398818] tsc: Refined TSC clocksource calibration: 3407.999 MHz
  [    1.400263] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fd336761, max_idle_ns: 440795243819 ns
  [    1.402734] clocksource: Switched to clocksource tsc
  [    1.426639] bpf_testmod: loading out-of-tree module taints kernel.
  [    1.428112] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
  lkl#252     tc_opts_after:OK
  lkl#253     tc_opts_append:OK
  lkl#254     tc_opts_basic:OK
  lkl#255     tc_opts_before:OK
  lkl#256     tc_opts_chain_classic:OK
  lkl#257     tc_opts_chain_mixed:OK
  lkl#258     tc_opts_delete_empty:OK
  lkl#259     tc_opts_demixed:OK
  lkl#260     tc_opts_detach:OK
  lkl#261     tc_opts_detach_after:OK
  lkl#262     tc_opts_detach_before:OK
  lkl#263     tc_opts_dev_cleanup:OK
  lkl#264     tc_opts_invalid:OK
  lkl#265     tc_opts_max:OK
  lkl#266     tc_opts_mixed:OK
  lkl#267     tc_opts_prepend:OK
  lkl#268     tc_opts_query:OK            <--- (new test)
  lkl#269     tc_opts_replace:OK
  lkl#270     tc_opts_revision:OK
  Summary: 19/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20231006220655.1653-4-daniel@iogearbox.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
rodionov pushed a commit to rodionov/lkl that referenced this issue Jan 2, 2025
Add a new test case to query on an empty bpf_mprog and pass the revision
directly into expected_revision for attachment to assert that this does
succeed.

  ./test_progs -t tc_opts
  [    1.406778] tsc: Refined TSC clocksource calibration: 3407.990 MHz
  [    1.408863] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fcaf6eb0, max_idle_ns: 440795321766 ns
  [    1.412419] clocksource: Switched to clocksource tsc
  [    1.428671] bpf_testmod: loading out-of-tree module taints kernel.
  [    1.430260] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
  lkl#252     tc_opts_after:OK
  lkl#253     tc_opts_append:OK
  lkl#254     tc_opts_basic:OK
  lkl#255     tc_opts_before:OK
  lkl#256     tc_opts_chain_classic:OK
  lkl#257     tc_opts_chain_mixed:OK
  lkl#258     tc_opts_delete_empty:OK
  lkl#259     tc_opts_demixed:OK
  lkl#260     tc_opts_detach:OK
  lkl#261     tc_opts_detach_after:OK
  lkl#262     tc_opts_detach_before:OK
  lkl#263     tc_opts_dev_cleanup:OK
  lkl#264     tc_opts_invalid:OK
  lkl#265     tc_opts_max:OK
  lkl#266     tc_opts_mixed:OK
  lkl#267     tc_opts_prepend:OK
  lkl#268     tc_opts_query:OK
  lkl#269     tc_opts_query_attach:OK     <--- (new test)
  lkl#270     tc_opts_replace:OK
  lkl#271     tc_opts_revision:OK
  Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20231006220655.1653-6-daniel@iogearbox.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants