Clean-up: run format-cpp on the tree The original re-format commit missed a number of files that were caught by format-cpp. Hopefully this is the last large reformat commit for a while. Change-Id: I493ee6d9fe6187e0bd087c68ed346af69c929c1e Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Build fix: rpath of test libraries results in non-reproducible build Yocto has trouble making LTTng-tools builds reproducibile since abs_builddir is used as the rpath of the test libraries under tests/regression/ust/ust-dl/. From their commit message: Specifing abs_builddir as an RPATH is plain wrong when cross compiling. Sadly, removing the rpath makes libtool/automake do weird things and breaks the build as shared libs are no longer generated. We already try and delete the RPATH at do_install with chrpath however that does leave the path in the string table so it doesn't help us with reproducibility. Their fix consists in hardcoding /usr/lib as the rpath of those libraries. As mentionned, the rpath doesn't matter; it's used to workaround libtool's behaviour. This fix uses `$libdir`, which takes the user's specified prefix into account to generate an rpath that is consistent with the one inserted in the other artifacts. Note that the change in the notification tests is a bit more involved since we have to bypass libtool to instrument a test application with uprobes. Fixes #1361 Change-Id: I7739956f8bc8571ef90802c3b37a4e1f21352385 Reported-by: Alexander Kanavin <alex.kanavin@gmail.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Prepare for '-Wunused-parameter' In preparation for '-Wextra' Change-Id: I30e6abb9502fc97daa565fde450d1e4235cf1ec7 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib: compile liblttng-ctl as C++ Same as the previous commits, but compile the liblttng-ctl library as C++ code (while still offering a C interface). Some exported global variables (for example in deprecated-symbols.cpp) have to be made non-const, otherwise we get: CXX deprecated-symbols.lo /home/simark/src/lttng-tools/src/lib/lttng-ctl/deprecated-symbols.cpp:21:33: error: ‘visibility’ attribute ignored [-Werror=attributes] 21 | LTTNG_EXPORT const char * const config_element_pid_tracker; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ I think this is related to the fact that const global variables automatically have internal linkage in C++. Despite using -export-symbols in src/lib/lttng-ctl/Makefile.am, some new ELF symbols become exposed. It could be related to this, in the ld man page: --retain-symbols-file does not discard undefined symbols, or symbols needed for relocations. One new symbol I see, for example, is `_Z16connect_sessiondv`. Looking at liblttng-ctl.so, I indeed see a relocation for this symbol: 000000000010b778 0000053e00000007 R_X86_64_JUMP_SLOT 00000000000314a2 _Z16connect_sessiondv + 0 And that would explain why the linker keeps that symbol visible. This is related to the entry for this function in the procedure linkage table. I'm not entirely sure why these functions didn't generate a PLT entry in C, but do in C++. To avoid these new symbols, build everything with -fvisibility=hidden and -fvisibility-inlines-hidden, and tag functions we really want to export with LTTNG_EXPORT, a new macro defined to __attribute__((visibility("default"))). This macro is publicly visible, because it has to be used in distributed header files (although it's of no use for users of liblttng-ctl). Change-Id: Ie51bf0a2edfb87e5f46f9c39eed5309d9f8c41d6 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: tests: add `void` parameter to functions that take no parameters In C, empty parenthesis declare a function without a prorotype (without specifying its parameters). This is not the same as having a `void` parameter, which declares a function which has no parameters. It's safer to use the later, otherwise it makes it possible to erroneously call the function with some arguments. Change this `test_function` to add `void`. It fixes diagnostics like: CC userspace-probe-elf-binary.o /home/simark/src/lttng-tools/tests/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary.c:12:33: error: no previous prototype for ‘test_function’ [-Werror=missing-prototypes] 12 | void __attribute__ ((noinline)) test_function() | Change-Id: Iceb7636e44d45f51889667ec76f2c04c032b5df8 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: append to AM_CFLAGS instead of overriding it The Makefiles modified by this patch currently override the AM_CFLAGS value, which means that anything put in AM_CFLAGS by configure (for example, the warning flags) is lost. I believe the intention is to add some flags to CFLAGS, so modify them such that they append instead of override. notification/Makefile.am overrides AM_LDFLAGS with nothing. It feels like it was not the intention to actually clear that variable, but rather that it is just the by-product of a copy paste. If it was really the intention to clear the value of AM_LDFLAGS, there would have been a comment to explain it, right? Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Change-Id: I4ef926d9135b16200e5f17d09461506a5e955068 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: Move to kernel style SPDX license identifiers The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. See https://spdx.org/ids-how for details. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: I89cd4b4b7440f71f52426a5508252932bb46e796 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: include foo.h in foo.c Fixes: CC foo.lo /home/smarchi/src/lttng-tools/tests/utils/testapp/userspace-probe-elf-binary/foo.c:19:5: error: no previous declaration for ‘dynamic_symbol’ [-Werror=missing-declarations] int dynamic_symbol(int a) ^~~~~~~~~~~~~~ Change-Id: I58888da2908bcf4c38d59ba9bacf3e96adc575b6 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: add declaration for test_function in userspace-probe-elf-binary.c Fixes: CC userspace-probe-elf-binary.o /home/smarchi/src/lttng-tools/tests/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary.c:21:34: error: no previous declaration for ‘test_function’ [-Werror=missing-declarations] void __attribute__ ((noinline)) test_function() ^~~~~~~~~~~~~ I did not make test_function static, because from what I understand, it is important that test_function remains an exported symbol, for example for test regression/kernel/test_userspace_probe. Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Change-Id: I52019f69de023b24b46cc701e2e0df919e654a76 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
elf: support dynamic symbol table lookup Background ========== There may be two symbol tables in a shared object or executable. The normal symbol table (.symtab) and the dynamic symbol table (.dynsym). The normal symbol table contains lots of information, such as static linking data, but none of it is used at runtime. This is why some shared libraries are 'stripped', reducing the final size of the file. Stripping an object file removes the entire .symtab section of the elf file, amongst other things. The dynamic symbol table contains symbols that are needed for dynamic linking of the shared object. The symbols in that section form a subset of the symbols contained in the normal symbol section (before stripping). The .dynsym section is left untouched when stripping a file as it is needed at runtime. Current limitation ================== The current elf parsing implementation looks for the normal symbol section (.symtab) to find the target symbol. If the .symtab is not found, the parsing stops and returns that the symbol was not found. As explained in the section above, a shared library might be stripped from its normal symbol table, but still have a dynamic symbol table (.dynsym) containing the information of the target symbol. For example, on distributions where libc is stripped, the malloc symbol can only be found in the .dynsym section Solution ======== Look for the normal symbol section first and, if it's found, use it to find the symbol, as was previously done. If the .symtab is absent, try to use the dynamic symbol section instead. This commit also adds a testcase for this feature. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Implement userspace-probe regression tests This adds regression testcases for the following userspace probe features and should-fail scenarios. Features: * ELF function location tracing works, * ELF C++ mangled function and method location tracing works, * SDT tracepoint location tracing works, * Implicit location type defaults to ELF location, * Binary found $PATH, * Binary found using full path, * Binary with colon in file name, * Disabling of all location types, * Listing of all location types, * Saving and loading of all location types, * SDT probe with one or more callsites, * SDT probe with arguments, * SDT probe in shared object, * SDT probe in dlopen()ed and ldpreload()ed shared object. Should-fail: * Target binary does not exist, * Target binary not ELF file, * ELF symbol not found in target binary, * ELF symbol not a function, * SDT provider name not found, * SDT probe name not found, * SDT probe guarded by a semaphore. We also make sure to disable testcases when the necessary files/tools for them are not found: * Disables C++ testcases if no C++ compiler is found. * Disables SDT testcases if the Systemtap header files are not found. This is tested by trying to compile a simple C program with a SDT probe. If it fails, it will only disable the testcases and not the feature since the SDT userspace probe feature does not use this header for parsing. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Erica Bugden <ebugden@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>