bin: compile lttng-sessiond as C++
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 6 Oct 2021 16:14:41 +0000 (12:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 17 Nov 2021 23:26:59 +0000 (18:26 -0500)
commit7966af5763c4aaca39df9bbfa9277ff15715c720
tree6029d93a070670ad54cfacf4ca665a6de0940467
parent3a5f70173aa04d11ccb22694d5d31a702cad33ab
bin: compile lttng-sessiond as C++

Same as commit 48a400056134 ("bin: compile lttng as C++"), but change
lttng-sessiond to be a C++ program. In addition to the categories of
changes already mentioned in that commit's message, here are some
interesting changes:

 - Add an include in trigger.h, an exported header, to fix:

      CXX      notification-thread.lo
    In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/notification-thread.cpp:9:
    /home/simark/src/lttng-tools/include/lttng/trigger/trigger.h:142:13: error: use of enum ‘lttng_error_code’ without previous declaration
      142 | extern enum lttng_error_code lttng_register_trigger_with_name(
          |             ^~~~~~~~~~~~~~~~

 - We get this with clang:

      CXX      lttng-conf.o
    In file included from /home/simark/src/lttng-tools/src/bin/lttng/conf.cpp:18:
    In file included from /home/simark/src/lttng-tools/src/common/common.h:14:
    In file included from /home/simark/src/lttng-tools/src/common/runas.h:17:
    In file included from /home/simark/src/lttng-tools/src/common/sessiond-comm/sessiond-comm.h:38:
    In file included from /home/simark/src/lttng-tools/src/common/unix.h:17:
    /home/simark/src/lttng-tools/src/common/payload-view.h:82:27: error: 'lttng_payload_view_from_payload' has C-linkage specified, but returns user-defined type 'struct lttng_payload_view' which is incompatible with C [-Werror,-Wreturn-type-c-linkage]
    struct lttng_payload_view lttng_payload_view_from_payload(
                              ^

    Turns out that because of the "const" field in lttng_payload_view,
    clang doesn't consider that type incompatible with C. I don't
    really want to remove the "const" for C code using that API, so
    conditionally remove it if we are compiling with clang in C++.

 - clang gives:

      CXX      event.lo
    In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/event.cpp:19:
    /home/simark/src/lttng-tools/src/common/bytecode/bytecode.h:50:1: error: struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
    struct literal_string {
    ^

   It looks like that type isn't even used?  Remove it.

 - it's not possible to initialize some union members, for example with
   lttcomm_consumer_msg, in consumer.cpp. Initialize it in a separate
   statement.

 - It's not possible to use the transparent union trick when calling
   urcu function, for example in thread_application_registration, in
   register.cpp. We need to instantiate a cds_wfcq_head_ptr_t object,
   assign the appropriate field, and pass that object to the function.

 - the ALIGNED_CONST_PTR trick does not work in C++:

      CXX      consumer.lo
    In file included from /home/simark/src/lttng-tools/src/common/error.h:19,
                     from /home/simark/src/lttng-tools/src/common/common.h:12,
                     from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:19:
    /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp: In function ‘int consumer_send_relayd_socket(consumer_socket*, lttcomm_relayd_sock*, consumer_output*, lttng_stream_type, uint64_t, const char*, const char*, const char*, int, const uint64_t*, time_t, bool)’:
    /home/simark/src/lttng-tools/src/common/macros.h:116:58: error: expected primary-expression before ‘]’ token
      116 | #define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value }))
          |                                                          ^
    /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:1192:48: note: in expansion of macro ‘ALIGNED_CONST_PTR’
     1192 |         ret = consumer_send_fds(consumer_sock, ALIGNED_CONST_PTR(rsock->sock.fd), 1);
          |                                                ^~~~~~~~~~~~~~~~~

   Replace uses with copying the data in a local variable (which is
   properly aligned), and pass the address to that variable to the
   function.

 - In consumer.h, an array field in a structure is defined using
   the max macro. It can't be replaced with std::max, since std::max
   isn't constexpr in C++11. Define a max_constexpr function locally
   and use it.

 - g++ 7 doesn't support non-trivial designated initializers, leading to
   errors like:

         CXX      globals.lo
      /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/globals.cpp:44:1: sorry, unimplemented: non-trivial designated initializers not supported
      };
      ^

   Change consumer_data to have a constructor instead. Change
   initializations of some structures, such as lttcomm_lttng_msg, to
   initialize the fields separate from the variable declaration. This
   requires making these variable non-const which is not ideal. But
   once everything is C++, these types could get a fancy constructor,
   and then they can be made const again.

 - When compiling without UST support the stub versions of functions
   ust_app_rotate_session & co, in ust-app.h, are used. Some of them
   have the return type "enum lttng_error_code", but return 0, an invalid
   value, causing:

        CXX      main.o
      In file included from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/lttng-sessiond.h:22:0,
                       from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/main.cpp:45:
      /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h: In function ‘lttng_error_code ust_app_snapshot_record(ltt_ust_session*, const consumer_output*, int, uint64_t)’:
      /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h:575:9: error: invalid conversion from ‘int’ to ‘lttng_error_code’ [-fpermissive]
        return 0;
               ^

   Change these functions to return LTTNG_ERR_UNK. These functions are
   not supposed to be called if UST support is not included. But even
   if they were: all their callers check that the return value is not
   LTTNG_OK. The value 0 would be considered an error, so will be
   LTTNG_ERR_UNK.

Change-Id: I2cdd34459a54b1943087b43843ef20b35b7bf7d8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
167 files changed:
include/lttng/action/action-internal.h
include/lttng/action/list-internal.h
include/lttng/condition/buffer-usage-internal.h
include/lttng/condition/event-rule-matches-internal.h
include/lttng/condition/session-consumed-size-internal.h
include/lttng/condition/session-rotation-internal.h
include/lttng/error-query-internal.h
include/lttng/event-internal.h
include/lttng/health-internal.h
include/lttng/location-internal.h
include/lttng/log-level-rule-internal.h
include/lttng/notification/notification-internal.h
include/lttng/session-descriptor-internal.h
include/lttng/trigger/trigger.h
include/lttng/userspace-probe-internal.h
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/action-executor.c [deleted file]
src/bin/lttng-sessiond/action-executor.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/agent-thread.c [deleted file]
src/bin/lttng-sessiond/agent-thread.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/agent.c [deleted file]
src/bin/lttng-sessiond/agent.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/buffer-registry.c [deleted file]
src/bin/lttng-sessiond/buffer-registry.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/channel.c [deleted file]
src/bin/lttng-sessiond/channel.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/clear.c [deleted file]
src/bin/lttng-sessiond/clear.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/client.c [deleted file]
src/bin/lttng-sessiond/client.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/cmd.c [deleted file]
src/bin/lttng-sessiond/cmd.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/condition-internal.c [deleted file]
src/bin/lttng-sessiond/condition-internal.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/condition-internal.h
src/bin/lttng-sessiond/consumer.c [deleted file]
src/bin/lttng-sessiond/consumer.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/consumer.h
src/bin/lttng-sessiond/context.c [deleted file]
src/bin/lttng-sessiond/context.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/dispatch.c [deleted file]
src/bin/lttng-sessiond/dispatch.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/event-notifier-error-accounting.c [deleted file]
src/bin/lttng-sessiond/event-notifier-error-accounting.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/event.c [deleted file]
src/bin/lttng-sessiond/event.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/fd-limit.c [deleted file]
src/bin/lttng-sessiond/fd-limit.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/globals.c [deleted file]
src/bin/lttng-sessiond/globals.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/health.c [deleted file]
src/bin/lttng-sessiond/health.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ht-cleanup.c [deleted file]
src/bin/lttng-sessiond/ht-cleanup.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/kernel-consumer.c [deleted file]
src/bin/lttng-sessiond/kernel-consumer.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/kernel.c [deleted file]
src/bin/lttng-sessiond/kernel.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/lttng-syscall.c [deleted file]
src/bin/lttng-sessiond/lttng-syscall.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/main.c [deleted file]
src/bin/lttng-sessiond/main.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/manage-apps.c [deleted file]
src/bin/lttng-sessiond/manage-apps.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/manage-consumer.c [deleted file]
src/bin/lttng-sessiond/manage-consumer.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/manage-kernel.c [deleted file]
src/bin/lttng-sessiond/manage-kernel.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/modprobe.c [deleted file]
src/bin/lttng-sessiond/modprobe.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/notification-thread-commands.c [deleted file]
src/bin/lttng-sessiond/notification-thread-commands.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/notification-thread-events.c [deleted file]
src/bin/lttng-sessiond/notification-thread-events.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/notification-thread.c [deleted file]
src/bin/lttng-sessiond/notification-thread.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/notify-apps.c [deleted file]
src/bin/lttng-sessiond/notify-apps.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/process-utils.c [deleted file]
src/bin/lttng-sessiond/process-utils.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/register.c [deleted file]
src/bin/lttng-sessiond/register.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/rotate.c [deleted file]
src/bin/lttng-sessiond/rotate.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/rotation-thread.c [deleted file]
src/bin/lttng-sessiond/rotation-thread.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/save.c [deleted file]
src/bin/lttng-sessiond/save.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/session.c [deleted file]
src/bin/lttng-sessiond/session.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/sessiond-config.c [deleted file]
src/bin/lttng-sessiond/sessiond-config.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/snapshot.c [deleted file]
src/bin/lttng-sessiond/snapshot.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/thread-utils.c [deleted file]
src/bin/lttng-sessiond/thread-utils.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/thread.c [deleted file]
src/bin/lttng-sessiond/thread.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/timer.c [deleted file]
src/bin/lttng-sessiond/timer.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/trace-kernel.c [deleted file]
src/bin/lttng-sessiond/trace-kernel.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/trace-ust.c [deleted file]
src/bin/lttng-sessiond/trace-ust.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/tracker.c [deleted file]
src/bin/lttng-sessiond/tracker.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/trigger-error-query.c [deleted file]
src/bin/lttng-sessiond/trigger-error-query.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-app.c [deleted file]
src/bin/lttng-sessiond/ust-app.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-app.h
src/bin/lttng-sessiond/ust-consumer.c [deleted file]
src/bin/lttng-sessiond/ust-consumer.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-ctl-internal.h
src/bin/lttng-sessiond/ust-field-utils.c [deleted file]
src/bin/lttng-sessiond/ust-field-utils.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-metadata.c [deleted file]
src/bin/lttng-sessiond/ust-metadata.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-registry.c [deleted file]
src/bin/lttng-sessiond/ust-registry.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/ust-sigbus.c [deleted file]
src/bin/lttng-sessiond/ust-sigbus.cpp [new file with mode: 0644]
src/bin/lttng-sessiond/utils.c [deleted file]
src/bin/lttng-sessiond/utils.cpp [new file with mode: 0644]
src/common/buffer-view.h
src/common/bytecode/bytecode.h
src/common/compat/directory-handle.h
src/common/compat/poll.h
src/common/config/session-config.h
src/common/context.h
src/common/credentials.h
src/common/daemonize.h
src/common/defaults.h
src/common/dynamic-buffer.h
src/common/fd-handle.h
src/common/filter.h
src/common/futex.h
src/common/hashtable/hashtable.h
src/common/hashtable/utils.h
src/common/index-allocator.h
src/common/kernel-ctl/kernel-ctl.h
src/common/macros.h
src/common/optional.h
src/common/payload-view.h
src/common/payload.h
src/common/pipe.h
src/common/readwrite.h
src/common/relayd/relayd.h
src/common/runas.h
src/common/sessiond-comm/inet.c
src/common/sessiond-comm/inet.h
src/common/sessiond-comm/inet6.c
src/common/sessiond-comm/sessiond-comm.h
src/common/shm.h
src/common/testpoint/testpoint.h
src/common/trace-chunk.h
src/common/unix.h
src/common/uuid.h
src/common/waiter.h
tests/unit/Makefile.am
tests/unit/test_kernel_data.c [deleted file]
tests/unit/test_kernel_data.cpp [new file with mode: 0644]
tests/unit/test_session.c [deleted file]
tests/unit/test_session.cpp [new file with mode: 0644]
tests/unit/test_ust_data.c [deleted file]
tests/unit/test_ust_data.cpp [new file with mode: 0644]
tests/utils/tap/tap.h
This page took 0.039793 seconds and 4 git commands to generate.