|
|
447b9a |
diff -ur libqb-1.0.3/configure.ac libqb-1.0.3.nosection/configure.ac
|
|
|
447b9a |
--- libqb-1.0.3/configure.ac 2017-12-21 09:02:11.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/configure.ac 2018-08-16 10:24:25.425174367 +0100
|
|
|
447b9a |
@@ -644,139 +644,6 @@
|
|
|
447b9a |
AM_CONDITIONAL(HAVE_SLOW_TESTS, [test "x${enable_slow_tests}" = xyes])
|
|
|
447b9a |
AC_SUBST(HAVE_SLOW_TESTS)
|
|
|
447b9a |
|
|
|
447b9a |
-# --- callsite sections ---
|
|
|
447b9a |
-if test "x${GCC}" = xyes; then
|
|
|
447b9a |
- AX_SAVE_FLAGS
|
|
|
447b9a |
- AC_MSG_CHECKING([whether GCC supports __attribute__((section()) + ld supports orphan sections])
|
|
|
447b9a |
- if test "x${ac_cv_link_attribute_section}" = x ; then
|
|
|
447b9a |
- LDFLAGS="${LDFLAGS_save} -shared -fPIC" # we are compiling shared lib
|
|
|
447b9a |
- AC_LINK_IFELSE(
|
|
|
447b9a |
- [AC_LANG_SOURCE(
|
|
|
447b9a |
- [[#include <assert.h>
|
|
|
447b9a |
- extern int __start___verbose[], __stop___verbose[];
|
|
|
447b9a |
- int test(void) {
|
|
|
447b9a |
- static int my_var __attribute__((section("__verbose"))) = 3;
|
|
|
447b9a |
- assert("L:non-empty data section"
|
|
|
447b9a |
- && __start___verbose != __stop___verbose);
|
|
|
447b9a |
- assert("L:no data section value loss"
|
|
|
447b9a |
- && my_var == 3 /* for 2.29.1+ */);
|
|
|
447b9a |
- return *((int *) __start___verbose); }]]
|
|
|
447b9a |
- )],
|
|
|
447b9a |
- [gcc_has_attribute_section=yes; cp "conftest${ac_exeext}" "conftest.so"],
|
|
|
447b9a |
- [gcc_has_attribute_section=no]
|
|
|
447b9a |
- )
|
|
|
447b9a |
- AX_RESTORE_FLAGS
|
|
|
447b9a |
- else
|
|
|
447b9a |
- gcc_has_attribute_section=${ac_cv_link_attribute_section}
|
|
|
447b9a |
- fi
|
|
|
447b9a |
- AC_MSG_RESULT($gcc_has_attribute_section)
|
|
|
447b9a |
-
|
|
|
447b9a |
- # in the failing case (e.g. with ld from binutils 2.29), it's likely the
|
|
|
447b9a |
- # following will fail readily in linkage (hidden symbol `__stop___verbose'
|
|
|
447b9a |
- # in conftest is referenced by DSO), but keep the sensible test
|
|
|
447b9a |
- # (in-executable symbol is expected to be propagated into the library,
|
|
|
447b9a |
- # and to draw the full circle back to the executable through standard
|
|
|
447b9a |
- # return value passing (respectively no-exec probing to spot the issue);
|
|
|
447b9a |
- # -rpath passed because LD_LIBRARY_PATH exporting is unwieldy here);
|
|
|
447b9a |
- # moreover, "my_var" == 3 assertion above (respectively checking if the
|
|
|
447b9a |
- # boundary symbol visibility differs from DEFAULT in readelf output) is
|
|
|
447b9a |
- # necessary so that binutils 2.29.1+ will not slip other parts of the
|
|
|
447b9a |
- # overall is-workaround-needed harness, as it restored some (but not
|
|
|
447b9a |
- # all) of the original behaviour, but the workaround is still provably
|
|
|
447b9a |
- # needed
|
|
|
447b9a |
- if test "x${gcc_has_attribute_section}" = xyes; then
|
|
|
447b9a |
- AC_MSG_CHECKING([whether linker emits global boundary symbols for orphan sections])
|
|
|
447b9a |
- LIBS="${LIBS} -L. -l:conftest${shrext_cmds} -Wl,-rpath=$(pwd)"
|
|
|
447b9a |
- dnl could be turned to AC_TRY_RUN (first assertion is equivalent to
|
|
|
447b9a |
- dnl the further check in action-if-true), but that would prevent
|
|
|
447b9a |
- dnl cross-building
|
|
|
447b9a |
- AC_LINK_IFELSE(
|
|
|
447b9a |
- [AC_LANG_PROGRAM(
|
|
|
447b9a |
- [[#include <assert.h>
|
|
|
447b9a |
- extern int __start___verbose[], __stop___verbose[];
|
|
|
447b9a |
- int test(void);]],
|
|
|
447b9a |
- [[static int my_var __attribute__((section("__verbose"))) = 5;
|
|
|
447b9a |
- assert("E:non-empty data section"
|
|
|
447b9a |
- && __start___verbose != __stop___verbose);
|
|
|
447b9a |
- assert("E:no data section value loss"
|
|
|
447b9a |
- && my_var == test() /*5?*/);]]
|
|
|
447b9a |
- )],
|
|
|
447b9a |
- [# alternatively something like (but requires number parsing):
|
|
|
447b9a |
- # readelf -SW "conftest${ac_exeext}" \
|
|
|
447b9a |
- # | sed -n '/__verbose/s/^\s*//p' | tr -s ' ' | cut -d" " -f6
|
|
|
447b9a |
- verbose_start_addr=$(${NM} -g --portability -- "conftest${ac_exeext}" \
|
|
|
447b9a |
- | grep __start___verbose | cut -d" " -f 3)
|
|
|
447b9a |
- verbose_stop_addr=$(${NM} -g --portability -- "conftest${ac_exeext}" \
|
|
|
447b9a |
- | grep __stop___verbose | cut -d" " -f 3)
|
|
|
447b9a |
- test "${verbose_start_addr}" = "${verbose_stop_addr}" \
|
|
|
447b9a |
- && gcc_has_attribute_section_visible=no \
|
|
|
447b9a |
- || { verbose_start_type=$(${READELF} -s backup \
|
|
|
447b9a |
- | sed -n '/__start___verbose/{s/^\s*//p;q}' \
|
|
|
447b9a |
- | tr -s ' ' \
|
|
|
447b9a |
- | cut -d" " -f6)
|
|
|
447b9a |
- test "${verbose_start_type}" = DEFAULT \
|
|
|
447b9a |
- && gcc_has_attribute_section_visible=yes \
|
|
|
447b9a |
- || gcc_has_attribute_section_visible=no; }],
|
|
|
447b9a |
- [gcc_has_attribute_section_visible=no]
|
|
|
447b9a |
- )
|
|
|
447b9a |
- AX_RESTORE_FLAGS
|
|
|
447b9a |
- AC_MSG_RESULT($gcc_has_attribute_section_visible)
|
|
|
447b9a |
- rm -f "conftest${shrext_cmds}"
|
|
|
447b9a |
-
|
|
|
447b9a |
- if test "x${gcc_has_attribute_section_visible}" = xno; then
|
|
|
447b9a |
- # check if the linker script based workaround is
|
|
|
447b9a |
- # feasible at all, otherwise fallback to using no
|
|
|
447b9a |
- # section attribute while making some noise about it
|
|
|
447b9a |
- # as combining with-without accustomed logging
|
|
|
447b9a |
- # participants is currently uncharted waters
|
|
|
447b9a |
- AC_MSG_CHECKING([whether linker workaround for orphan sections usable])
|
|
|
447b9a |
- >conftest.ld cat <<-EOF
|
|
|
447b9a |
- SECTIONS {
|
|
|
447b9a |
- __verbose : {
|
|
|
447b9a |
- __start___verbose = .;
|
|
|
447b9a |
- *(__verbose);
|
|
|
447b9a |
- __stop___verbose = .;
|
|
|
447b9a |
- }
|
|
|
447b9a |
- }
|
|
|
447b9a |
- EOF
|
|
|
447b9a |
- LDFLAGS="${LDFLAGS} -Wl,conftest.ld"
|
|
|
447b9a |
- AC_LINK_IFELSE(
|
|
|
447b9a |
- [AC_LANG_PROGRAM(
|
|
|
447b9a |
- [[#include <assert.h>
|
|
|
447b9a |
- extern int __start___verbose[], __stop___verbose[];
|
|
|
447b9a |
- int test(void);]],
|
|
|
447b9a |
- [[static int my_var __attribute__((section("__verbose"))) = 5;
|
|
|
447b9a |
- assert("E:non-empty data section"
|
|
|
447b9a |
- && __start___verbose != __stop___verbose);
|
|
|
447b9a |
- assert("E:no data section value loss"
|
|
|
447b9a |
- && my_var == 5);]]
|
|
|
447b9a |
- )],
|
|
|
447b9a |
- [],
|
|
|
447b9a |
- [gcc_has_attribute_section=no]
|
|
|
447b9a |
- )
|
|
|
447b9a |
- AX_RESTORE_FLAGS
|
|
|
447b9a |
- AC_MSG_RESULT([$gcc_has_attribute_section])
|
|
|
447b9a |
- rm -f "conftest.ld"
|
|
|
447b9a |
- fi
|
|
|
447b9a |
-
|
|
|
447b9a |
- if test "x${gcc_has_attribute_section}" = xyes; then
|
|
|
447b9a |
- AC_DEFINE([QB_HAVE_ATTRIBUTE_SECTION], 1,
|
|
|
447b9a |
- [Enabling code using __attribute__((section))])
|
|
|
447b9a |
- AC_SUBST([client_dlopen_LIBS],[$dlopen_LIBS])
|
|
|
447b9a |
- if test "x${gcc_has_attribute_section_visible}" = xyes; then
|
|
|
447b9a |
- PACKAGE_FEATURES="$PACKAGE_FEATURES attribute-section"
|
|
|
447b9a |
- else
|
|
|
447b9a |
- AC_DEFINE([QB_NEED_ATTRIBUTE_SECTION_WORKAROUND], 1,
|
|
|
447b9a |
- [Enabling code using __attribute__((section))])
|
|
|
447b9a |
- PACKAGE_FEATURES="$PACKAGE_FEATURES attribute-section-workaround"
|
|
|
447b9a |
- fi
|
|
|
447b9a |
- elif test "x${enable_nosection_fallback}" = xyes; then
|
|
|
447b9a |
- AC_MSG_NOTICE([Falling back to not using orphan section])
|
|
|
447b9a |
- else
|
|
|
447b9a |
- AC_MSG_ERROR([Would use section attribute, cannot; see --enable-nosection-fallback])
|
|
|
447b9a |
- fi
|
|
|
447b9a |
- fi
|
|
|
447b9a |
-fi
|
|
|
447b9a |
AM_CONDITIONAL(HAVE_GCC_ATTRIBUTE_SECTION, [test "x${gcc_has_attribute_section}" = xyes])
|
|
|
447b9a |
AM_CONDITIONAL(NEED_GCC_ATTRIBUTE_SECTION_WORKAROUND,
|
|
|
447b9a |
[test "x${gcc_has_attribute_section}" = xyes \
|
|
|
447b9a |
diff -ur libqb-1.0.3/include/qb/qbconfig.h.in libqb-1.0.3.nosection/include/qb/qbconfig.h.in
|
|
|
447b9a |
--- libqb-1.0.3/include/qb/qbconfig.h.in 2017-12-14 09:25:16.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/include/qb/qbconfig.h.in 2018-08-16 10:23:15.018923879 +0100
|
|
|
447b9a |
@@ -27,9 +27,6 @@
|
|
|
447b9a |
/* need atomic memory barrier */
|
|
|
447b9a |
#undef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED
|
|
|
447b9a |
|
|
|
447b9a |
-/* Enabling code using __attribute__((section)) */
|
|
|
447b9a |
-#undef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-
|
|
|
447b9a |
/* versioning info: MAJOR, MINOR, MICRO, and REST components;
|
|
|
447b9a |
note that static compile-time info is not that useful as consulting
|
|
|
447b9a |
the respectively named members of qb_version struct constant under
|
|
|
447b9a |
diff -ur libqb-1.0.3/include/qb/qblog.h libqb-1.0.3.nosection/include/qb/qblog.h
|
|
|
447b9a |
--- libqb-1.0.3/include/qb/qblog.h 2017-12-21 09:02:11.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/include/qb/qblog.h 2018-08-16 10:23:15.018923879 +0100
|
|
|
447b9a |
@@ -39,15 +39,6 @@
|
|
|
447b9a |
#include <qb/qbutil.h>
|
|
|
447b9a |
#include <qb/qbconfig.h>
|
|
|
447b9a |
|
|
|
447b9a |
-#if defined(QB_KILL_ATTRIBUTE_SECTION) || defined(S_SPLINT_S)
|
|
|
447b9a |
-#undef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-#endif /* defined(QB_KILL_ATTRIBUTE_SECTION) || defined(S_SPLINT_S) */
|
|
|
447b9a |
-
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-#include <assert.h> /* possibly needed for QB_LOG_INIT_DATA */
|
|
|
447b9a |
-#include <dlfcn.h> /* dynamic linking: dlopen, dlsym, dladdr, ... */
|
|
|
447b9a |
-#endif
|
|
|
447b9a |
-
|
|
|
447b9a |
/**
|
|
|
447b9a |
* @file qblog.h
|
|
|
447b9a |
* The logging API provides four main parts (basics, filtering, threading & blackbox).
|
|
|
447b9a |
@@ -286,119 +277,7 @@
|
|
|
447b9a |
|
|
|
447b9a |
typedef void (*qb_log_filter_fn)(struct qb_log_callsite * cs);
|
|
|
447b9a |
|
|
|
447b9a |
-/* will be assigned by linker magic (assuming linker supports that):
|
|
|
447b9a |
- * https://sourceware.org/binutils/docs/ld/Orphan-Sections.html
|
|
|
447b9a |
- */
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-
|
|
|
447b9a |
-#define QB_ATTR_SECTION __verbose /* conforms to C ident. */
|
|
|
447b9a |
-#define QB_ATTR_SECTION_STR QB_PP_STRINGIFY(QB_ATTR_SECTION)
|
|
|
447b9a |
-#define QB_ATTR_SECTION_START QB_PP_JOIN(__start_, QB_ATTR_SECTION)
|
|
|
447b9a |
-#define QB_ATTR_SECTION_STOP QB_PP_JOIN(__stop_, QB_ATTR_SECTION)
|
|
|
447b9a |
-#define QB_ATTR_SECTION_START_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_START)
|
|
|
447b9a |
-#define QB_ATTR_SECTION_STOP_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_STOP)
|
|
|
447b9a |
-
|
|
|
447b9a |
-extern struct qb_log_callsite QB_ATTR_SECTION_START[];
|
|
|
447b9a |
-extern struct qb_log_callsite QB_ATTR_SECTION_STOP[];
|
|
|
447b9a |
-
|
|
|
447b9a |
-/* Related to the next macro that is -- unlike this one -- a public API */
|
|
|
447b9a |
-#ifndef _GNU_SOURCE
|
|
|
447b9a |
-#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
|
|
|
447b9a |
- _Pragma(QB_PP_STRINGIFY(GCC warning QB_PP_STRINGIFY( \
|
|
|
447b9a |
- without "_GNU_SOURCE" defined (directly or not) \
|
|
|
447b9a |
- QB_LOG_INIT_DATA cannot check sanity of libqb proper \
|
|
|
447b9a |
- nor of the target site originating this check alone)))
|
|
|
447b9a |
-#else
|
|
|
447b9a |
-#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
|
|
|
447b9a |
- { Dl_info work_dli; \
|
|
|
447b9a |
- /* libqb sanity (locating libqb by it's relatively unique \
|
|
|
447b9a |
- non-functional symbols -- the two are mutually exclusive, the \
|
|
|
447b9a |
- ordinarily latter was introduced by accident, the former is \
|
|
|
447b9a |
- intentional -- due to possible confusion otherwise) */ \
|
|
|
447b9a |
- if ((dladdr(dlsym(RTLD_DEFAULT, "qb_ver_str"), &work_dli) \
|
|
|
447b9a |
- || dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli)) \
|
|
|
447b9a |
- && (work_handle = dlopen(work_dli.dli_fname, \
|
|
|
447b9a |
- RTLD_LOCAL|RTLD_LAZY)) != NULL) { \
|
|
|
447b9a |
- work_s1 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_START_STR); \
|
|
|
447b9a |
- work_s2 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_STOP_STR); \
|
|
|
447b9a |
- assert("libqb's callsite section is observable, otherwise \
|
|
|
447b9a |
-libqb's build is at fault, preventing reliable logging" \
|
|
|
447b9a |
- && work_s1 != NULL && work_s2 != NULL); \
|
|
|
447b9a |
- assert("libqb's callsite section is populated, otherwise \
|
|
|
447b9a |
-libqb's build is at fault, preventing reliable logging" \
|
|
|
447b9a |
- && work_s1 != work_s2); \
|
|
|
447b9a |
- dlclose(work_handle); } \
|
|
|
447b9a |
- /* sanity of the target site originating this check alone */ \
|
|
|
447b9a |
- if (dladdr(dlsym(RTLD_DEFAULT, QB_PP_STRINGIFY(name)), &work_dli) \
|
|
|
447b9a |
- && (work_handle = dlopen(work_dli.dli_fname, \
|
|
|
447b9a |
- RTLD_LOCAL|RTLD_LAZY)) != NULL) { \
|
|
|
447b9a |
- work_s1 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_START_STR); \
|
|
|
447b9a |
- work_s2 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_STOP_STR); \
|
|
|
447b9a |
- assert("target's own callsite section observable, otherwise \
|
|
|
447b9a |
-target's own linkage at fault and logging would not work reliably \
|
|
|
447b9a |
-(unless QB_LOG_INIT_DATA macro used unexpectedly in no-logging context)"\
|
|
|
447b9a |
- && work_s1 != NULL && work_s2 != NULL); \
|
|
|
447b9a |
- assert("target's own callsite section non-empty, otherwise \
|
|
|
447b9a |
-target's own linkage at fault and logging would not work reliably \
|
|
|
447b9a |
-(unless QB_LOG_INIT_DATA macro used unexpectedly in no-logging context)"\
|
|
|
447b9a |
- && work_s1 != work_s2); \
|
|
|
447b9a |
- dlclose(work_handle); } }
|
|
|
447b9a |
-#endif /* _GNU_SOURCE */
|
|
|
447b9a |
-
|
|
|
447b9a |
-/**
|
|
|
447b9a |
- * Optional on-demand self-check of 1/ toolchain sanity (prerequisite for
|
|
|
447b9a |
- * the logging subsystem to work properly) and 2/ non-void active use of
|
|
|
447b9a |
- * logging (satisfied with a justifying existence of a logging callsite as
|
|
|
447b9a |
- * defined with a @c qb_logt invocation) at the target (but see below), which
|
|
|
447b9a |
- * is supposedly assured by it's author(!) as of relying on this very macro
|
|
|
447b9a |
- * [technically, the symbols that happen to be resolved under the respective
|
|
|
447b9a |
- * identifiers do not necessarily originate in the same compilation unit as
|
|
|
447b9a |
- * when it's not the end executable (or by induction, a library positioned
|
|
|
447b9a |
- * earlier in the symbol lookup order) but a shared library, the former takes
|
|
|
447b9a |
- * a precedence unless that site comes short of exercising the logging,
|
|
|
447b9a |
- * making its callsite section empty and, in turn, without such boundary
|
|
|
447b9a |
- * symbols, hence making the resolution continue further in the lookup order
|
|
|
447b9a |
- * -- despite fuzzily targeted attestation, the check remains reasonable];
|
|
|
447b9a |
- * only effective when link-time ("run-time amortizing") callsite collection
|
|
|
447b9a |
- * is; as a side effect, it can ensure the boundary-denoting symbols for the
|
|
|
447b9a |
- * target collection area are kept alive with some otherwise unkind linkers.
|
|
|
447b9a |
- *
|
|
|
447b9a |
- * Applying this macro in the target program/library is strongly recommended
|
|
|
447b9a |
- * whenever the logging as framed by this header file is in use.
|
|
|
447b9a |
- * Moreover, it's important to state that using this check while not ensuring
|
|
|
447b9a |
- * @c _GNU_SOURCE macro definition is present at compile-time means only half
|
|
|
447b9a |
- * of the available sanity checking will be performed, possibly resulting
|
|
|
447b9a |
- * in libqb's own internally logged messages being lost without warning.
|
|
|
447b9a |
- */
|
|
|
447b9a |
-#define QB_LOG_INIT_DATA(name) \
|
|
|
447b9a |
- void name(void); \
|
|
|
447b9a |
- void name(void) { \
|
|
|
447b9a |
- void *work_handle; struct qb_log_callsite *work_s1, *work_s2; \
|
|
|
447b9a |
- /* our own (target's) sanity, or possibly that of higher priority \
|
|
|
447b9a |
- symbol resolution site (unless target equals end executable) \
|
|
|
447b9a |
- or even the lower one if no such predecessor defines these */ \
|
|
|
447b9a |
- if ((work_handle = dlopen(NULL, RTLD_LOCAL|RTLD_LAZY)) != NULL) { \
|
|
|
447b9a |
- work_s1 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_START_STR); \
|
|
|
447b9a |
- work_s2 = (struct qb_log_callsite *) \
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_STOP_STR); \
|
|
|
447b9a |
- assert("implicit callsite section is observable, otherwise \
|
|
|
447b9a |
-target's and/or libqb's build is at fault, preventing reliable logging" \
|
|
|
447b9a |
- && work_s1 != NULL && work_s2 != NULL); \
|
|
|
447b9a |
- dlclose(work_handle); /* perhaps overly eager thing to do */ } \
|
|
|
447b9a |
- QB_NONAPI_LOG_INIT_DATA_EXTRA_(name); \
|
|
|
447b9a |
- /* finally, original, straightforward check */ \
|
|
|
447b9a |
- assert("implicit callsite section is populated, otherwise \
|
|
|
447b9a |
-target's build is at fault, preventing reliable logging" \
|
|
|
447b9a |
- && QB_ATTR_SECTION_START != QB_ATTR_SECTION_STOP); } \
|
|
|
447b9a |
- void __attribute__ ((constructor)) name(void);
|
|
|
447b9a |
-#else
|
|
|
447b9a |
#define QB_LOG_INIT_DATA(name)
|
|
|
447b9a |
-#endif /* QB_HAVE_ATTRIBUTE_SECTION */
|
|
|
447b9a |
|
|
|
447b9a |
/**
|
|
|
447b9a |
* Internal function: use qb_log() or qb_logt()
|
|
|
447b9a |
@@ -476,21 +355,12 @@
|
|
|
447b9a |
* @param fmt usual printf style format specifiers
|
|
|
447b9a |
* @param args usual printf style args
|
|
|
447b9a |
*/
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-#define qb_logt(priority, tags, fmt, args...) do { \
|
|
|
447b9a |
- static struct qb_log_callsite descriptor \
|
|
|
447b9a |
- __attribute__((section(QB_ATTR_SECTION_STR), aligned(8))) = \
|
|
|
447b9a |
- { __func__, __FILE__, fmt, priority, __LINE__, 0, tags }; \
|
|
|
447b9a |
- qb_log_real_(&descriptor, ##args); \
|
|
|
447b9a |
- } while(0)
|
|
|
447b9a |
-#else
|
|
|
447b9a |
#define qb_logt(priority, tags, fmt, args...) do { \
|
|
|
447b9a |
struct qb_log_callsite* descriptor_pt = \
|
|
|
447b9a |
qb_log_callsite_get(__func__, __FILE__, fmt, \
|
|
|
447b9a |
priority, __LINE__, tags); \
|
|
|
447b9a |
qb_log_real_(descriptor_pt, ##args); \
|
|
|
447b9a |
} while(0)
|
|
|
447b9a |
-#endif /* QB_HAVE_ATTRIBUTE_SECTION */
|
|
|
447b9a |
|
|
|
447b9a |
|
|
|
447b9a |
/**
|
|
|
447b9a |
--- libqb-1.0.3/lib/libqb.pc.in 2017-12-14 09:25:16.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/lib/libqb.pc.in 2018-08-16 10:23:15.019923883 +0100
|
|
|
447b9a |
@@ -7,17 +7,6 @@
|
|
|
447b9a |
Version: @PACKAGE_VERSION@
|
|
|
447b9a |
Description: libqb
|
|
|
447b9a |
Requires:
|
|
|
447b9a |
-Libs: -L${libdir} -lqb @client_dlopen_LIBS@
|
|
|
447b9a |
-# NOTE: If -lqb not usable for linking (e.g. linker not compatible with
|
|
|
447b9a |
-# linker scripts ad-hoc modifying output sections), try recent
|
|
|
447b9a |
-# ld.bfd/binutils linker first when available, otherwise you can
|
|
|
447b9a |
-# try "-l:libqb.so.<digit>" link switch that bypasses said linker
|
|
|
447b9a |
-# script -- but beware, logging may be less efficient and may lack
|
|
|
447b9a |
-# possible future optimizations and extra features. Consequently,
|
|
|
447b9a |
-# logging issues (typically bound to QB_LOG_INIT_DATA macro) can be
|
|
|
447b9a |
-# mitigated with QB_KILL_ATTRIBUTE_SECTION macro defined for a build.
|
|
|
447b9a |
-# NOTE: when concerned about a warning coming from the build process like
|
|
|
447b9a |
-# warning: [...]libqb.so contains output sections; did you forget -T?
|
|
|
447b9a |
-# and the build finishes OK, take it merely as a harmless side-effect
|
|
|
447b9a |
+Libs: -L${libdir} -lqb
|
|
|
447b9a |
Libs.private: @LIBS@
|
|
|
447b9a |
Cflags: -I${includedir}
|
|
|
447b9a |
diff -ur libqb-1.0.3/lib/log.c libqb-1.0.3.nosection/lib/log.c
|
|
|
447b9a |
--- libqb-1.0.3/lib/log.c 2017-12-21 09:02:11.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/lib/log.c 2018-08-16 10:26:01.465514061 +0100
|
|
|
447b9a |
@@ -40,13 +40,6 @@
|
|
|
447b9a |
#include "util_int.h"
|
|
|
447b9a |
#include <regex.h>
|
|
|
447b9a |
|
|
|
447b9a |
-#if defined(QB_NEED_ATTRIBUTE_SECTION_WORKAROUND) && !defined(S_SPLINT_S)
|
|
|
447b9a |
-/* following only needed to force these symbols be global
|
|
|
447b9a |
- with ld 2.29: https://bugzilla.redhat.com/1477354 */
|
|
|
447b9a |
-struct qb_log_callsite __attribute__((weak)) QB_ATTR_SECTION_START[] = { {0} };
|
|
|
447b9a |
-struct qb_log_callsite __attribute__((weak)) QB_ATTR_SECTION_STOP[] = { {0} };
|
|
|
447b9a |
-#endif
|
|
|
447b9a |
-
|
|
|
447b9a |
static struct qb_log_target conf[QB_LOG_TARGET_MAX];
|
|
|
447b9a |
static uint32_t conf_active_max = 0;
|
|
|
447b9a |
static int32_t in_logger = QB_FALSE;
|
|
|
447b9a |
@@ -772,73 +765,6 @@
|
|
|
447b9a |
return qb_log_filter_ctl2(t, c, type, text, LOG_EMERG, priority);
|
|
|
447b9a |
}
|
|
|
447b9a |
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
-/* Some platforms (eg. FreeBSD 10+) don't support calling dlopen() from
|
|
|
447b9a |
- * within a dl_iterate_phdr() callback; so save all of the dlpi_names to
|
|
|
447b9a |
- * a list and iterate over them afterwards. */
|
|
|
447b9a |
-static int32_t
|
|
|
447b9a |
-_log_so_walk_callback(struct dl_phdr_info *info, size_t size, void *data)
|
|
|
447b9a |
-{
|
|
|
447b9a |
- struct dlname *dlname;
|
|
|
447b9a |
-
|
|
|
447b9a |
- if (strlen(info->dlpi_name) > 0) {
|
|
|
447b9a |
- dlname = calloc(1, sizeof(struct dlname));
|
|
|
447b9a |
- if (!dlname)
|
|
|
447b9a |
- return 0;
|
|
|
447b9a |
- dlname->dln_name = strdup(info->dlpi_name);
|
|
|
447b9a |
- qb_list_add_tail(&dlname->list, &dlnames);
|
|
|
447b9a |
- }
|
|
|
447b9a |
-
|
|
|
447b9a |
- return 0;
|
|
|
447b9a |
-}
|
|
|
447b9a |
-
|
|
|
447b9a |
-static void
|
|
|
447b9a |
-_log_so_walk_dlnames(void)
|
|
|
447b9a |
-{
|
|
|
447b9a |
- struct dlname *dlname;
|
|
|
447b9a |
- struct qb_list_head *iter;
|
|
|
447b9a |
- struct qb_list_head *next;
|
|
|
447b9a |
-
|
|
|
447b9a |
- void *handle;
|
|
|
447b9a |
- void *start;
|
|
|
447b9a |
- void *stop;
|
|
|
447b9a |
- const char *error;
|
|
|
447b9a |
-
|
|
|
447b9a |
- qb_list_for_each_safe(iter, next, &dlnames) {
|
|
|
447b9a |
- dlname = qb_list_entry(iter, struct dlname, list);
|
|
|
447b9a |
-
|
|
|
447b9a |
- handle = dlopen(dlname->dln_name, RTLD_LAZY);
|
|
|
447b9a |
- error = dlerror();
|
|
|
447b9a |
- if (!handle || error) {
|
|
|
447b9a |
- qb_log(LOG_ERR, "%s", error);
|
|
|
447b9a |
- goto done;
|
|
|
447b9a |
- }
|
|
|
447b9a |
-
|
|
|
447b9a |
- start = dlsym(handle, QB_ATTR_SECTION_START_STR);
|
|
|
447b9a |
- error = dlerror();
|
|
|
447b9a |
- if (error) {
|
|
|
447b9a |
- goto done;
|
|
|
447b9a |
- }
|
|
|
447b9a |
-
|
|
|
447b9a |
- stop = dlsym(handle, QB_ATTR_SECTION_STOP_STR);
|
|
|
447b9a |
- error = dlerror();
|
|
|
447b9a |
- if (error) {
|
|
|
447b9a |
- goto done;
|
|
|
447b9a |
-
|
|
|
447b9a |
- } else {
|
|
|
447b9a |
- qb_log_callsites_register(start, stop);
|
|
|
447b9a |
- }
|
|
|
447b9a |
-done:
|
|
|
447b9a |
- if (handle)
|
|
|
447b9a |
- dlclose(handle);
|
|
|
447b9a |
- qb_list_del(iter);
|
|
|
447b9a |
- if (dlname->dln_name)
|
|
|
447b9a |
- free(dlname->dln_name);
|
|
|
447b9a |
- free(dlname);
|
|
|
447b9a |
- }
|
|
|
447b9a |
-}
|
|
|
447b9a |
-#endif /* QB_HAVE_ATTRIBUTE_SECTION */
|
|
|
447b9a |
-
|
|
|
447b9a |
static void
|
|
|
447b9a |
_log_target_state_set(struct qb_log_target *t, enum qb_log_target_state s)
|
|
|
447b9a |
{
|
|
|
447b9a |
@@ -864,10 +790,6 @@
|
|
|
447b9a |
{
|
|
|
447b9a |
int32_t l;
|
|
|
447b9a |
enum qb_log_target_slot i;
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
- void *work_handle; struct qb_log_callsite *work_s1, *work_s2;
|
|
|
447b9a |
- Dl_info work_dli;
|
|
|
447b9a |
-#endif /* QB_HAVE_ATTRIBUTE_SECTION */
|
|
|
447b9a |
/* cannot reuse single qb_log invocation in various contexts
|
|
|
447b9a |
through the variables (when section attribute in use),
|
|
|
447b9a |
hence this indirection */
|
|
|
447b9a |
@@ -893,33 +815,6 @@
|
|
|
447b9a |
}
|
|
|
447b9a |
|
|
|
447b9a |
qb_log_dcs_init();
|
|
|
447b9a |
-#ifdef QB_HAVE_ATTRIBUTE_SECTION
|
|
|
447b9a |
- /* sanity check that target chain supplied QB_ATTR_SECTION_ST{ART,OP}
|
|
|
447b9a |
- symbols and hence the local references to them are not referencing
|
|
|
447b9a |
- the proper libqb's ones (locating libqb by it's relatively unique
|
|
|
447b9a |
- non-functional symbols -- the two are mutually exclusive, the
|
|
|
447b9a |
- ordinarily latter was introduced by accident, the former is
|
|
|
447b9a |
- intentional -- due to possible confusion otherwise) */
|
|
|
447b9a |
- if ((dladdr(dlsym(RTLD_DEFAULT, "qb_ver_str"), &work_dli)
|
|
|
447b9a |
- || dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli))
|
|
|
447b9a |
- && (work_handle = dlopen(work_dli.dli_fname,
|
|
|
447b9a |
- RTLD_LOCAL|RTLD_LAZY)) != NULL) {
|
|
|
447b9a |
- work_s1 = (struct qb_log_callsite *)
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_START_STR);
|
|
|
447b9a |
- work_s2 = (struct qb_log_callsite *)
|
|
|
447b9a |
- dlsym(work_handle, QB_ATTR_SECTION_STOP_STR);
|
|
|
447b9a |
- if (work_s1 == QB_ATTR_SECTION_START
|
|
|
447b9a |
- || work_s2 == QB_ATTR_SECTION_STOP) {
|
|
|
447b9a |
- preinit_err = preinit_err_target_sec;
|
|
|
447b9a |
- } else if (work_s1 == work_s2) {
|
|
|
447b9a |
- preinit_err = preinit_err_target_empty;
|
|
|
447b9a |
- }
|
|
|
447b9a |
- dlclose(work_handle); /* perhaps overly eager thing to do */
|
|
|
447b9a |
- }
|
|
|
447b9a |
- qb_log_callsites_register(QB_ATTR_SECTION_START, QB_ATTR_SECTION_STOP);
|
|
|
447b9a |
- dl_iterate_phdr(_log_so_walk_callback, NULL);
|
|
|
447b9a |
- _log_so_walk_dlnames();
|
|
|
447b9a |
-#endif /* QB_HAVE_ATTRIBUTE_SECTION */
|
|
|
447b9a |
|
|
|
447b9a |
for (i = QB_LOG_TARGET_STATIC_START; i < QB_LOG_TARGET_STATIC_MAX; i++)
|
|
|
447b9a |
conf[i].state = QB_LOG_STATE_DISABLED;
|
|
|
447b9a |
diff -ur libqb-1.0.3/lib/Makefile.am libqb-1.0.3.nosection/lib/Makefile.am
|
|
|
447b9a |
--- libqb-1.0.3/lib/Makefile.am 2017-12-14 09:25:16.000000000 +0000
|
|
|
447b9a |
+++ libqb-1.0.3.nosection/lib/Makefile.am 2018-08-16 10:25:07.001321422 +0100
|
|
|
447b9a |
@@ -79,9 +79,6 @@
|
|
|
447b9a |
libqb_la_SOURCES = $(source_to_lint) unix.c
|
|
|
447b9a |
libqb_la_CFLAGS = $(PTHREAD_CFLAGS)
|
|
|
447b9a |
libqb_la_LIBADD = $(LTLIBOBJS) $(dlopen_LIBS) $(PTHREAD_LIBS) $(socket_LIBS)
|
|
|
447b9a |
-if NEED_GCC_ATTRIBUTE_SECTION_WORKAROUND
|
|
|
447b9a |
-libqb_la_LIBADD += qblog_script.la
|
|
|
447b9a |
-endif
|
|
|
447b9a |
|
|
|
447b9a |
AM_LDFLAGS = $(LDFLAGS_COPY:-Bsymbolic-functions=)
|
|
|
447b9a |
|
|
|
447b9a |
@@ -110,33 +107,6 @@
|
|
|
447b9a |
pkgconfigexecdir = $(libdir)/pkgconfig
|
|
|
447b9a |
pkgconfigexec_DATA = libqb.pc
|
|
|
447b9a |
|
|
|
447b9a |
-# find the libqb.so symlink's target, if so, try to find out, iteratively,
|
|
|
447b9a |
-# its gradually shorter forms that likewise symlinks the same target as the
|
|
|
447b9a |
-# original libqb.so path, point to that file from the linker script using
|
|
|
447b9a |
-# qblog_script.ld as a template, storing result in place of original libqb.so
|
|
|
447b9a |
-# (e.g., libqb.so := "INPUT(libqb.so.0) " [...] "SECTIONS { " [...] "}")
|
|
|
447b9a |
-# NOTE: readlink nor realpath are POSIX; not chained links ready
|
|
|
447b9a |
-# NOTE: conservative check, i.e., not per NEED_GCC_ATTRIBUTE_SECTION_WORKAROUND
|
|
|
447b9a |
-if HAVE_GCC_ATTRIBUTE_SECTION
|
|
|
447b9a |
-install-exec-hook: qblog_script.ld
|
|
|
447b9a |
- target=$$(ls -l "$(DESTDIR)$(libdir)/libqb.so" || :); \
|
|
|
447b9a |
- target=$${target#* -> }; t1_bn=$$(basename "$${target}" || :); \
|
|
|
447b9a |
- while test -n "$${t1_bn}"; do t2_bn=$${t1_bn%.*[0-9]*}; \
|
|
|
447b9a |
- test "$${t2_bn}" != libqb.so || break; \
|
|
|
447b9a |
- test -L "$${t2_bn}" || { t1_bn=$${t2_bn}; continue; }; \
|
|
|
447b9a |
- t2_target=$$(ls -l "$${t2_bn}" || break); t2_target=$${t2_target#* -> }; \
|
|
|
447b9a |
- test "$${t2_target}" = "$${target}" || break; \
|
|
|
447b9a |
- t1_bn=$${t2_bn}; done; test -n "$${t1_bn}" || \
|
|
|
447b9a |
- { echo "only applicable to SO symlink scheme"; exit 1; }; \
|
|
|
447b9a |
- echo "$${t1_bn}" > "$(DESTDIR)$(libdir)/libqb.so-t"
|
|
|
447b9a |
- so_ver=$$(cat "$(DESTDIR)$(libdir)/libqb.so-t"); \
|
|
|
447b9a |
- echo "INPUT($${so_ver})" > "$(DESTDIR)$(libdir)/libqb.so-t"; \
|
|
|
447b9a |
- cat $< >> "$(DESTDIR)$(libdir)/libqb.so-t"; \
|
|
|
447b9a |
- sed -i -- "s/libqb.so.<digit>/$${so_ver}/" \
|
|
|
447b9a |
- "$(DESTDIR)$(libdir)/libqb.so-t" "$(DESTDIR)$(pkgconfigexecdir)/libqb.pc"
|
|
|
447b9a |
- mv -f "$(DESTDIR)$(libdir)/libqb.so-t" "$(DESTDIR)$(libdir)/libqb.so"
|
|
|
447b9a |
-endif
|
|
|
447b9a |
-
|
|
|
447b9a |
if HAVE_SPLINT
|
|
|
447b9a |
check_SCRIPTS = run_splint.sh
|
|
|
447b9a |
TESTS = $(check_SCRIPTS)
|