messages: resolve module name at link-time

Within all the introduced static libraries, the module cannot be known
at compilation time. This moves the module name from a compilation
constant to a link time constant string symbol. That way, the same
compiled object within a static library can use a different and correct
module name depending on which plugin it is linked into.

The symbol is hidden so it does not leak between shared objects. For
non-plugins shared libraries (vlccore, vlc, vlc_pulse and
vlc_xcb_events) the module name must be defined manually, unless the
library does not use msg_* macros at all (vlc_vdpau).
This commit is contained in:
Rémi Denis-Courmont 2017-11-18 21:18:24 +02:00
parent d2cf1ff065
commit e46fd2bfa6
10 changed files with 21 additions and 12 deletions

View File

@ -71,11 +71,11 @@ VLC_API void vlc_vaLog(vlc_object_t *obj, int prio, const char *module,
const char *file, unsigned line, const char *func,
const char *format, va_list ap);
#define msg_GenericVa(o, p, fmt, ap) \
vlc_vaLog(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, __func__, \
fmt, ap)
vlc_vaLog(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
__func__, fmt, ap)
#define msg_Generic(o, p, ...) \
vlc_Log(VLC_OBJECT(o), p, MODULE_STRING, __FILE__, __LINE__, \
vlc_Log(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
__func__, __VA_ARGS__)
#define msg_Info(p_this, ...) \
msg_Generic(p_this, VLC_MSG_INFO, __VA_ARGS__)
@ -86,9 +86,7 @@ VLC_API void vlc_vaLog(vlc_object_t *obj, int prio, const char *module,
#define msg_Dbg(p_this, ...) \
msg_Generic(p_this, VLC_MSG_DBG, __VA_ARGS__)
#ifndef MODULE_STRING
# define MODULE_STRING __FILE__
#endif
extern const char vlc_module_name[];
VLC_API const char *vlc_strerror(int);
VLC_API const char *vlc_strerror_c(int);

View File

@ -210,9 +210,12 @@ enum vlc_module_properties
/* If the module is built-in, then we need to define foo_InitModule instead
* of InitModule. Same for Activate- and DeactivateModule. */
#ifdef __PLUGIN__
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_SYMBOL )
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_SYMBOL )
# define VLC_MODULE_NAME_HIDDEN_SYMBOL \
const char vlc_module_name[] = MODULE_STRING;
#else
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_NAME )
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_NAME )
# define VLC_MODULE_NAME_HIDDEN_SYMBOL
#endif
#define CDECL_SYMBOL
@ -267,6 +270,7 @@ int CDECL_SYMBOL __VLC_SYMBOL(vlc_entry) (vlc_set_cb vlc_set, void *opaque) \
error: \
return -1; \
} \
VLC_MODULE_NAME_HIDDEN_SYMBOL \
VLC_METADATA_EXPORTS
#define add_submodule( ) \

View File

@ -1,6 +1,5 @@
AUTOMAKE_OPTIONS = subdir-objects
pkgconfigdir = $(libdir)/pkgconfig
AM_CPPFLAGS = -DMODULE_STRING=\"libvlc\"
AM_CFLAGS = $(CFLAGS_libvlc)
SUFFIXES = .pc.in .pc

View File

@ -256,3 +256,5 @@ int64_t libvlc_clock(void)
{
return mdate();
}
const char vlc_module_name[] = "libvlc";

View File

@ -38,7 +38,6 @@ aout_LTLIBRARIES += libalsa_plugin.la
endif
libvlc_pulse_la_SOURCES = audio_output/vlcpulse.c audio_output/vlcpulse.h
libvlc_pulse_la_CPPFLAGS = -DMODULE_STRING=\"pulse\"
libvlc_pulse_la_CFLAGS = $(AM_CFLAGS) $(PULSE_CFLAGS)
libvlc_pulse_la_LIBADD = $(PULSE_LIBS) $(LTLIBVLCCORE)
libvlc_pulse_la_LDFLAGS = \

View File

@ -34,6 +34,8 @@
#include <unistd.h>
#include <pwd.h>
const char vlc_module_name[] = "vlcpulse";
#undef vlc_pa_error
void vlc_pa_error (vlc_object_t *obj, const char *msg, pa_context *ctx)
{

View File

@ -120,7 +120,6 @@ endif # HAVE_GL
### XCB ###
libvlc_xcb_events_la_SOURCES = \
video_output/xcb/events.c video_output/xcb/events.h
libvlc_xcb_events_la_CPPFLAGS = -DMODULE_STRING=\"xcb\"
libvlc_xcb_events_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS)
libvlc_xcb_events_la_LDFLAGS = \
-no-undefined \

View File

@ -34,6 +34,8 @@
#include "events.h"
const char vlc_module_name[] = "vlcpulse";
#pragma GCC visibility push(default)
int vlc_xcb_error_Check(vout_display_t *vd, xcb_connection_t *conn,

View File

@ -2809,3 +2809,7 @@ vlc_module_end ()
/*****************************************************************************
* End configuration.
*****************************************************************************/
#ifdef HAVE_DYNAMIC_PLUGINS
const char vlc_module_name[] = "main";
#endif

View File

@ -145,7 +145,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
* \param obj VLC object emitting the message or NULL
* \param type VLC_MSG_* message type (info, error, warning or debug)
* \param module name of module from which the message come
* (normally MODULE_STRING)
* (normally vlc_module_name)
* \param file source module file name (normally __FILE__) or NULL
* \param line function call source line number (normally __LINE__) or 0
* \param func calling function name (normally __func__) or NULL