Skip to content

Commit

Permalink
[WIP: missing commit message] TBD
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Pokorný <[email protected]>
  • Loading branch information
jnpkrn committed Jan 17, 2018
1 parent c44a7f7 commit 03497c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
50 changes: 36 additions & 14 deletions include/qb/qblog.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,36 @@ typedef void (*qb_log_filter_fn)(struct qb_log_callsite * cs);
#define QB_ATTR_SECTION_START_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_START)
#define QB_ATTR_SECTION_STOP_STR QB_PP_STRINGIFY(QB_ATTR_SECTION_STOP)

extern struct qb_log_callsite QB_ATTR_SECTION_START[];
extern struct qb_log_callsite QB_ATTR_SECTION_STOP[];
extern struct qb_log_callsite QB_ATTR_SECTION_START[]
#if !defined(QB_NOAPI_LOG_INT) && !defined(_GNU_SOURCE) && !defined(QB_LD_2_29)
__attribute__((visibility ("protected")))
#endif
;
extern struct qb_log_callsite QB_ATTR_SECTION_STOP[]
#if !defined(QB_NOAPI_LOG_INT) && !defined(_GNU_SOURCE) && !defined(QB_LD_2_29)
__attribute__((visibility ("protected")))
#endif
;

/* Related to the next macro that is -- unlike this one -- a public API */
#ifndef _GNU_SOURCE
#if !defined(_GNU_SOURCE) && !defined(QB_LD_2_29)
#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
{ _Pragma(QB_PP_STRINGIFY(GCC warning QB_PP_STRINGIFY( \
without "_GNU_SOURCE" defined (directly or not) \
QB_LOG_INIT_DATA cannot check sanity of libqb proper \
and only superficially of the target site originating \
this check alone. \
NOT COMPATIBLE WITH BINUTILS 2.29 (2.29.1 OK)))); \
/* original, straightforward check */ \
assert("target's own callsite section is populated, otherwise \
target's build is at fault, preventing reliable logging" \
&& QB_ATTR_SECTION_START != QB_ATTR_SECTION_STOP); }
#elif !defined(_GNU_SOURCE)
#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
_Pragma(QB_PP_STRINGIFY(GCC warning QB_PP_STRINGIFY( \
without "_GNU_SOURCE" defined (directly or not) \
QB_LOG_INIT_DATA cannot check sanity of libqb proper \
nor of the target site originating this check alone)))
_Pragma(QB_PP_STRINGIFY(GCC warning QB_PP_STRINGIFY( \
without "_GNU_SOURCE" defined (directly or not) \
QB_LOG_INIT_DATA cannot check sanity of libqb proper \
nor of the target site originating this check alone)))
#else
#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
{ Dl_info work_dli; \
Expand Down Expand Up @@ -338,11 +358,11 @@ libqb's build is at fault, preventing reliable logging" \
dlsym(work_handle, QB_ATTR_SECTION_START_STR); \
work_s2 = (struct qb_log_callsite *) \
dlsym(work_handle, QB_ATTR_SECTION_STOP_STR); \
assert("target's own callsite section observable, otherwise \
assert("target's own callsite section is observable, otherwise \
target's own linkage at fault and logging would not work reliably \
(unless QB_LOG_INIT_DATA macro used unexpectedly in no-logging context)"\
&& work_s1 != NULL && work_s2 != NULL); \
assert("target's own callsite section non-empty, otherwise \
assert("target's own callsite section is populated, otherwise \
target's own linkage at fault and logging would not work reliably \
(unless QB_LOG_INIT_DATA macro used unexpectedly in no-logging context)"\
&& work_s1 != work_s2); \
Expand Down Expand Up @@ -373,6 +393,12 @@ target's own linkage at fault and logging would not work reliably \
* @c _GNU_SOURCE macro definition is present at compile-time means only half
* of the available sanity checking will be performed, possibly resulting
* in libqb's own internally logged messages being lost without warning.
*
* @note When this macro is leveraged in the end executable that is moreover
* linked with ld.bfd from binutils 2.29 (2.29.1 is not of concern,
* though), make sure the respective code is compiled with at least one
* of @c _GNU_SOURCE and @c QB_LD_2_29 macros defined so as to avoid
* run-time misbehaviour of the pertaining checks.
*/
#define QB_LOG_INIT_DATA(name) \
void name(void); \
Expand All @@ -390,11 +416,7 @@ target's own linkage at fault and logging would not work reliably \
target's and/or libqb's build is at fault, preventing reliable logging" \
&& work_s1 != NULL && work_s2 != NULL); \
dlclose(work_handle); /* perhaps overly eager thing to do */ } \
QB_NONAPI_LOG_INIT_DATA_EXTRA_(name); \
/* finally, original, straightforward check */ \
assert("implicit callsite section is populated, otherwise \
target's build is at fault, preventing reliable logging" \
&& QB_ATTR_SECTION_START != QB_ATTR_SECTION_STOP); } \
QB_NONAPI_LOG_INIT_DATA_EXTRA_(name); } \
void __attribute__ ((constructor)) name(void);
#else
#define QB_LOG_INIT_DATA(name)
Expand Down
10 changes: 8 additions & 2 deletions lib/libqb.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ Libs: -L${libdir} -lqb @client_dlopen_LIBS@
# possible future optimizations and extra features. Consequently,
# logging issues (typically bound to QB_LOG_INIT_DATA macro) can be
# mitigated with QB_KILL_ATTRIBUTE_SECTION macro defined for a build.
# NOTE: when concerned about a warning coming from the build process like
# NOTE: Conversely, when QB_LOG_INIT_DATA macro is leveraged in the end
# executable relying on this library that is moreover linked with
# ld.bfd from binutils 2.29 (2.29.1 is not of concern, though), make
# sure the respective code is compiled with at least one of _GNU_SOURCE
# and QB_LD_2_29 macros defined so as to avoid run-time misbehaviour
# of the pertaining checks.
# NOTE: When concerned about a warning coming from the build process like
# warning: [...]libqb.so contains output sections; did you forget -T?
# and the build finishes OK, take it merely as a harmless side-effect
# and the build finishes OK, take it merely as a harmless side-effect.
Libs.private: @LIBS@
Cflags: -I${includedir}
2 changes: 2 additions & 0 deletions lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#define QB_NOAPI_LOG_INT 1

#include "os_base.h"
#include <ctype.h>
#ifdef HAVE_LINK_H
Expand Down

0 comments on commit 03497c7

Please sign in to comment.