oracle / dtrace-utils

DTrace-utils contains the DTrace port to Linux
Other
153 stars 20 forks source link

Needs porting to musl #87

Open thesamesam opened 3 months ago

thesamesam commented 3 months ago

My plan for the weekend was/is to investigate how much work is needed to port to musl. I was expecting most of the time to be spent on the testsuite, but we fail to build:

cmd/bpf_dump.c: In function 'readBPFFile':
cmd/bpf_dump.c:23:19: error: implicit declaration of function 'open64'; did you mean 'openat'? [-Wimplicit-function-declaration]
   23 |         if ((fd = open64(fn, O_RDONLY)) == -1) {
      |                   ^~~~~~
      |                   openat
                 from test/triggers/libproc-pldd.c:14:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         id_t
test/triggers/libproc-lookup-victim.c: In function 'main':
test/triggers/libproc-lookup-victim.c:57:34: error: implicit declaration of function 'dlmopen'; did you mean 'dlopen'? [-Wimplicit-function-declaration]
   57 |                 dlmopen_handle = dlmopen(LM_ID_NEWLM,
      |                                  ^~~~~~~
      |                                  dlopen
test/triggers/libproc-lookup-victim.c:57:42: error: 'LM_ID_NEWLM' undeclared (first use in this function)
   57 |                 dlmopen_handle = dlmopen(LM_ID_NEWLM,
      |                                          ^~~~~~~~~~~
test/triggers/libproc-lookup-victim.c:57:42: note: each undeclared identifier is reported only once for each function it appears in
test/triggers/libproc-dlmadopen.c: In function 'churn':
test/triggers/libproc-dlmadopen.c:30:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   30 |         Lmid_t lmids[6] = {0};
      |         ^~~~~~
      |         gid_t
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-lookup-victim.o] Error 1
test/triggers/libproc-dlmadopen.c:54:36: error: 'LM_ID_NEWLM' undeclared (first use in this function)
   54 |                         lmids[n] = LM_ID_NEWLM;
      |                                    ^~~~~~~~~~~
test/triggers/libproc-dlmadopen.c:54:36: note: each undeclared identifier is reported only once for each function it appears in
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libdtrace/drti.c:73:1: warning: constructor priorities from 0 to 100 are reserved for the implementation [-Wprio-ctor-dtor]
   73 | {
      | ^
test/triggers/libproc-dlmadopen.c:68:37: error: implicit declaration of function 'dlmopen'; did you mean 'dlopen'? [-Wimplicit-function-declaration]
   68 |                         loaded[n] = dlmopen(lmids[n], "test/triggers/libproc-dlmlib.so.0", RTLD_NOW);
      |                                     ^~~~~~~
      |                                     dlopen
test/triggers/libproc-dlmadopen.c:68:35: error: assignment to 'void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   68 |                         loaded[n] = dlmopen(lmids[n], "test/triggers/libproc-dlmlib.so.0", RTLD_NOW);
      |                                   ^
libdtrace/drti.c: In function 'dtrace_dof_init':
libdtrace/drti.c:81:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   81 |         Lmid_t lmid = -1;
      |         ^~~~~~
      |         id_t
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         id_t
libdtrace/drti.c:198:26: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'int' [-Wformat=]
  198 |                     "LM%lu`%s", lmid, modname);
      |                        ~~^      ~~~~
      |                          |      |
      |                          |      int
      |                          long unsigned int
      |                        %u
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     id_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     id_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     id_t
test/triggers/libproc-pldd.c: In function 'print_ldd':
test/triggers/libproc-pldd.c:50:51: warning: format '%li' expects argument of type 'long int', but argument 5 has type 'int' [-Wformat=]
   50 |         printf("%s: dyn 0x%lx, bias 0x%lx, LMID %li: %s (", buf, loadobj->rl_dyn,
      |                                                 ~~^
      |                                                   |
      |                                                   long int
      |                                                 %i
   51 |             loadobj->rl_diff_addr, loadobj->rl_lmident, loadobj->rl_default_scope ?
      |                                    ~~~~~~~~~~~~~~~~~~~
      |                                           |
      |                                           int
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-dlmadopen.o] Error 1
In file included from libproc/libproc.h:25,
                 from test/triggers/libproc-lookup-by-name.c:15:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         id_t
test/utils/showUSDT.c: In function 'readObj':
test/utils/showUSDT.c:343:15: error: implicit declaration of function 'open64'; did you mean 'openat'? [-Wimplicit-function-declaration]
  343 |     if ((fd = open64(fn, O_RDONLY)) == -1) {
      |               ^~~~~~
      |               openat
make: *** [libdtrace/Build:249: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/drti.o] Error 1
In file included from libproc/libproc.h:25,
                 from test/triggers/libproc-consistency.c:15:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         id_t
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-pldd.o] Error 1
In file included from libproc/libproc.h:25,
                 from test/triggers/libproc-execing-bkpts.c:15:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         id_t
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         id_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     id_t
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-utils--showUSDT.o] Error 1
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     id_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     id_t
test/triggers/libproc-lookup-by-name.c: In function 'main':
test/triggers/libproc-lookup-by-name.c:32:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   32 |         Lmid_t lmid;
      |         ^~~~~~
      |         id_t
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
In file included from libproc/libproc.h:25,
                 from dtprobed/dtprobed.c:71:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         id_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     id_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     id_t
test/triggers/libproc-lookup-by-name.c:65:13: error: implicit declaration of function 'Pxlookup_by_name'; did you mean 'ctf_lookup_by_name'? [-Wimplicit-function-declaration]
   65 |         if (Pxlookup_by_name(P, lmid, PR_OBJ_EVERY, symbol, &sym, &sip) != 0) {
      |             ^~~~~~~~~~~~~~~~
      |             ctf_lookup_by_name
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     id_t
test/triggers/libproc-consistency.c: In function 'print_ldd':
test/triggers/libproc-consistency.c:64:59: warning: format '%li' expects argument of type 'long int', but argument 5 has type 'int' [-Wformat=]
   64 |                 printf("%s: dyn 0x%lx, bias 0x%lx, LMID %li\n", buf, loadobj->rl_dyn,
      |                                                         ~~^
      |                                                           |
      |                                                           long int
      |                                                         %i
   65 |                     loadobj->rl_diff_addr, loadobj->rl_lmident);
      |                                            ~~~~~~~~~~~~~~~~~~~
      |                                                   |
      |                                                   int
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         id_t
libproc/libproc.h:232:27: error: 'Lmid_t' undeclared (first use in this function); did you mean 'id_t'?
  232 | #define PR_LMID_EVERY   ((Lmid_t)-1UL)          /* search every link map */
      |                           ^~~~~~
test/triggers/libproc-lookup-by-name.c:70:21: note: in expansion of macro 'PR_LMID_EVERY'
   70 |         if (lmid != PR_LMID_EVERY && sip.prs_lmid != lmid)
      |                     ^~~~~~~~~~~~~
libproc/libproc.h:232:27: note: each undeclared identifier is reported only once for each function it appears in
  232 | #define PR_LMID_EVERY   ((Lmid_t)-1UL)          /* search every link map */
      |                           ^~~~~~
test/triggers/libproc-lookup-by-name.c:70:21: note: in expansion of macro 'PR_LMID_EVERY'
   70 |         if (lmid != PR_LMID_EVERY && sip.prs_lmid != lmid)
      |                     ^~~~~~~~~~~~~
test/triggers/libproc-lookup-by-name.c:71:63: warning: format '%li' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat=]
   71 |                 fprintf(stderr, "lmid error: asked for lmid %li, got back sym "
      |                                                             ~~^
      |                                                               |
      |                                                               long int
      |                                                             %i
   72 |                     "in lmid %li\n", lmid, sip.prs_lmid);
      |                                      ~~~~                      
      |                                      |
      |                                      int
test/triggers/libproc-lookup-by-name.c:71:33: warning: format '%li' expects argument of type 'long int', but argument 4 has type 'int' [-Wformat=]
   71 |                 fprintf(stderr, "lmid error: asked for lmid %li, got back sym "
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 |                     "in lmid %li\n", lmid, sip.prs_lmid);
      |                                            ~~~~~~~~~~~~
      |                                               |
      |                                               int
test/triggers/libproc-lookup-by-name.c:72:32: note: format string is defined here
   72 |                     "in lmid %li\n", lmid, sip.prs_lmid);
      |                              ~~^
      |                                |
      |                                long int
      |                              %i
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     id_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     id_t
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-consistency.o] Error 1
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     id_t
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-lookup-by-name.o] Error 1
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
test/triggers/libproc-execing-bkpts.c: In function 'main':
test/triggers/libproc-execing-bkpts.c:104:22: error: implicit declaration of function 'Pxlookup_by_name'; did you mean 'ctf_lookup_by_name'? [-Wimplicit-function-declaration]
  104 |                 if ((Pxlookup_by_name(P, PR_LMID_EVERY, PR_OBJ_EVERY, symbol, &sym, &sip) != 0) &&
      |                      ^~~~~~~~~~~~~~~~
      |                      ctf_lookup_by_name
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_buf.c:21:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:232:27: error: 'Lmid_t' undeclared (first use in this function); did you mean 'id_t'?
  232 | #define PR_LMID_EVERY   ((Lmid_t)-1UL)          /* search every link map */
      |                           ^~~~~~
test/triggers/libproc-execing-bkpts.c:104:42: note: in expansion of macro 'PR_LMID_EVERY'
  104 |                 if ((Pxlookup_by_name(P, PR_LMID_EVERY, PR_OBJ_EVERY, symbol, &sym, &sip) != 0) &&
      |                                          ^~~~~~~~~~~~~
libproc/libproc.h:232:27: note: each undeclared identifier is reported only once for each function it appears in
  232 | #define PR_LMID_EVERY   ((Lmid_t)-1UL)          /* search every link map */
      |                           ^~~~~~
test/triggers/libproc-execing-bkpts.c:104:42: note: in expansion of macro 'PR_LMID_EVERY'
  104 |                 if ((Pxlookup_by_name(P, PR_LMID_EVERY, PR_OBJ_EVERY, symbol, &sym, &sip) != 0) &&
      |                                          ^~~~~~~~~~~~~
In file included from <stdin>:8:
include/sys/glibc_internal_link.h:64:3: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   64 |   Lmid_t l_ns;
      |   ^~~~~~
      |   gid_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
<stdin>: In function 'main':
<stdin>:27:9: warning: format '%li' expects argument of type 'long int', but argument 2 has type 'int' [-Wformat=]
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_as.c:13:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
make: *** [Makerules:31: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/test-triggers--libproc-execing-bkpts.o] Error 1
make: *** [libproc/Build:21: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/rtld_offsets.stamp] Error 1
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libdtrace/dt_proc.h:85:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
   85 |                         enum __ptrace_request request;
      |                              ^~~~~~~~~~~~~~~~
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
dtprobed/dtprobed.c: In function 'dof_parser_start':
dtprobed/dtprobed.c:383:17: error: implicit declaration of function 'mallopt'; did you mean 'malloc'? [-Wimplicit-function-declaration]
  383 |                 mallopt(M_MMAP_MAX, 0);
      |                 ^~~~~~~
      |                 malloc
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libdtrace/dt_proc.h:85:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
   85 |                         enum __ptrace_request request;
      |                              ^~~~~~~~~~~~~~~~
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_provider.h:12,
                 from libdtrace/dt_cc.c:83:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_btf.c:15:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
dtprobed/dtprobed.c:383:25: error: 'M_MMAP_MAX' undeclared (first use in this function)
  383 |                 mallopt(M_MMAP_MAX, 0);
      |                         ^~~~~~~~~~
dtprobed/dtprobed.c:383:25: note: each undeclared identifier is reported only once for each function it appears in
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_bpf.c:15:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
make: *** [Makerules:14: /var/tmp/portage/dev-debug/dtrace-2.0.1.1-r1/work/dtrace-utils-2.0.1.1/build/libdtrace--dt_buf.o] Error 1
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_cg.c:18:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libdtrace/dt_proc.h:85:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
   85 |                         enum __ptrace_request request;
      |                              ^~~~~~~~~~~~~~~~
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
dtprobed/dtprobed.c:384:25: error: 'M_TRIM_THRESHOLD' undeclared (first use in this function)
  384 |                 mallopt(M_TRIM_THRESHOLD, -1);
      |                         ^~~~~~~~~~~~~~~~
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         gid_t
In file included from libdtrace/dt_proc.h:13,
                 from libdtrace/dt_impl.h:46,
                 from libdtrace/dt_aggregate.c:11:
include/rtld_db.h:68:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
   68 |         Lmid_t          rl_lmident;     /* ident of link map */
      |         ^~~~~~
      |         id_t
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     gid_t
dtprobed/dtprobed.c: In function 'mapping_dev_inums':
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
dtprobed/dtprobed.c:465:21: error: implicit declaration of function 'Plmid_to_map'; did you mean 'Pname_to_map'? [-Wimplicit-function-declaration]
  465 |         exec_mapp = Plmid_to_map(P, LM_ID_BASE, PR_OBJ_EXEC);
      |                     ^~~~~~~~~~~~
      |                     Pname_to_map
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     gid_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
In file included from libdtrace/dt_proc.h:14:
libproc/libproc.h:130:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
  130 | typedef long ptrace_fun(enum __ptrace_request request, void *arg, pid_t pid,
      |                              ^~~~~~~~~~~~~~~~
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     gid_t
libproc/libproc.h:130:30: warning: 'enum __ptrace_request' declared inside parameter list will not be visible outside of this definition or declaration
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libproc/libproc.h:245:9: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  245 |         Lmid_t          prs_lmid;               /* link map id */
      |         ^~~~~~
      |         id_t
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              gid_t
libproc/libproc.h:251:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  251 |     Lmid_t, const char *, const char *, GElf_Sym *, prsyminfo_t *);
      |     ^~~~~~
      |     id_t
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       gid_t
dtprobed/dtprobed.c:465:37: error: 'LM_ID_BASE' undeclared (first use in this function)
  465 |         exec_mapp = Plmid_to_map(P, LM_ID_BASE, PR_OBJ_EXEC);
      |                                     ^~~~~~~~~~
libproc/libproc.h:260:5: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  260 |     Lmid_t, const char *);
      |     ^~~~~~
      |     id_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'gid_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       gid_t
libproc/libproc.h:266:53: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  266 | extern int Plmid(struct ps_prochandle *, uintptr_t, Lmid_t *);
      |                                                     ^~~~~~
      |                                                     id_t
libdtrace/dt_proc.h:85:30: warning: ISO C forbids forward references to 'enum' types [-Wpedantic]
   85 |                         enum __ptrace_request request;
      |                              ^~~~~~~~~~~~~~~~
libdtrace/dt_proc.h:85:47: error: field 'request' has incomplete type
   85 |                         enum __ptrace_request request;
      |                                               ^~~~~~~
libdtrace/dt_proc.h:157:62: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  157 | extern const prmap_t *dt_Plmid_to_map(dtrace_hdl_t *, pid_t, Lmid_t,
      |                                                              ^~~~~~
      |                                                              id_t
libdtrace/dt_proc.h:161:55: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  161 | extern int dt_Plmid(dtrace_hdl_t *, pid_t, uintptr_t, Lmid_t *);
      |                                                       ^~~~~~
      |                                                       id_t
libdtrace/dt_proc.h:163:55: error: unknown type name 'Lmid_t'; did you mean 'id_t'?
  163 | extern int dt_Pxlookup_by_name(dtrace_hdl_t *, pid_t, Lmid_t, const char *,
      |                                                       ^~~~~~
      |                                                       id_t

I'll analyse the failures more, I don't need help at this point (may do later).

thesamesam commented 3 months ago

While this might be a bit of work, I want to say that I do think this is valuable, for two reasons:

  1. The kind of people who tinker with systems often either run musl or have musl ports of their distros;
  2. musl often ends up having odd issues (not necc. its fault) where you have a failure and you need to understand why - DTrace shines there.
kvanhees commented 3 months ago

On Sat, Aug 24, 2024 at 06:59:33PM -0700, Sam James wrote:

My plan for the weekend was/is to investigate how much work is needed to port to musl. I was expecting most of the time to be spent on the testsuite, but we fail to build:

cmd/bpf_dump.c: In function 'readBPFFile': cmd/bpf_dump.c:23:19: error: implicit declaration of function 'open64'; did you mean 'openat'? [-Wimplicit-function-declaration] 23 | if ((fd = open64(fn, O_RDONLY)) == -1) { | ^~ | openat from test/triggers/libproc-pldd.c:14:

Oh my, I forgot about the bpf_dump tool that I once wrote to assist in my develoment work on porting DTrace to use BPF. That is quite outdated and not at all userful anymore as far as I can see. We can just get rid of it.

nickalcock commented 2 months ago

I was going to laugh this off, but while DTrace does incestuous things with the internals of glibc to do symbol lookups in nonstandard lmids and ask victim ld.so's for their symbol lookup ordering info, it does those to glibcs in other processes (and tries to test them, which obviously would have to disable itself if compiling with musl). We extract some critical glibc internal structure offsets at compile time, which does assume we can compile various generator programs against glibc, but we could always provide some fallback pregenerated output I suppose (assuming that output isn't implicitly GPL, it's only a bunch of offsetof()s).

I can immediately think of no fundamental reason why we can't compile against musl, though under testing mode we turn on things like recursive mutexes which IIRC musl will never implement %but that's an edge case).

The biggest evil thing we do that requires glibc internals in the dtrace process itself is in the replacement for waitfd() in libdtrace/dt_proc.c, where we need thread-directed signals from timer_create() to cover a nasty race:

    sev.sigev_notify = SIGEV_SIGNAL | SIGEV_THREAD_ID;
    sev.sigev_signo = dtp->dt_proc_signal;
    sev._sigev_un._tid = gettid();
    if (timer_create(CLOCK_MONOTONIC, &sev, &dpr->dpr_proxy_timer) < 0) {

There is no standard way to do this, this uses glibc internals, but obviously Linux can do it (and we don't care at all about portability to non-Linux): does musl have some way to do it? If it doesn't, I don't know any way to implement dtrace -c without said nasty race. See commits c883bd437cfbb8269ebbe6c78171a0d2e08c029c and 234b39beb0e0083381df6bb498491f2904d5d087.