Revert "lib: Fix undefined reference to `mq_open' build failures"
PATCH 1/2 Revert "lib: Fix undefined reference to `mq_open' build failures"
This reverts commit fcfb6970002454cfa29cf679a82ba92c94fb59e0.
I've misunderstand how __attribute__((weak)) is supposed to work. The problem here is that we link statically against the libltp library and hence dynamic linker does not even try to resolve the library internal weak mq_open symbol and we end up using the stub regardless if we linked the library with -lrt or not.
--- lib/tst_safe_posix_ipc.c | 7 ------- 1 file changed, 7 deletions(-)
lib/tst_safe_posix_ipc.c +0 -7
@@ -22,13 +22,6 @@#include "tst_test.h" #include "tst_safe_posix_ipc.h" -mqd_t __attribute__((weak))mq_open (const char *name __attribute__((unused)), -int oflag __attribute__((unused)), ...) -{ -tst_brk (TBROK ,"mq_open() stub called! Missing -lrt in LDFLAGS?" ); -return 0 ; -} -int safe_mq_open (const char *file,const int lineno,const char *pathname,int oflags, ...) {
Signature · 1 line
2.10.2
PATCH 2/2 lib: Fix undefined reference to `mq_open'
This commit moves the safe_mq_open() function into the header which fixes undeterministic linker failures.
This fix replaces the reverted commit:
commit fcfb6970002454cfa29cf679a82ba92c94fb59e0
Author: Cyril Hrubis <[email protected]> Date: Wed Mar 29 18:44:44 2017 +0200
lib: Fix undefined reference to `mq_open' build failures
--- include/tst_safe_posix_ipc.h | 36 +++++++++++++- lib/tst_safe_posix_ipc.c | 55 ---------------------- testcases/kernel/syscalls/mq_open/mq_open01.c | 2 +- .../syscalls/mq_timedreceive/mq_timedreceive01.c | 2 +- 4 files changed, 36 insertions(+), 59 deletions(-) delete mode 100644 lib/tst_safe_posix_ipc.c
include/tst_safe_posix_ipc.h +34 -2
@@ -24,10 +24,42 @@#ifndef TST_SAFE_POSIX_IPC_H__ #define TST_SAFE_POSIX_IPC_H__ +#include <mqueue.h> +#include <stdarg.h> +#define SAFE_MQ_OPEN (pathname, oflags, ...) \ safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__) -int safe_mq_open (const char *file,const int lineno,const char *pathname, -int oflags, ...); +static inline int safe_mq_open (const char *file,const int lineno, +const char *pathname,int oflags, ...) +{ +va_list ap; +int rval; +mode_t mode; +struct mq_attr *attr; + +va_start (ap, oflags); + +/* Android's NDK's mode_t is smaller than an int, which results in +* SIGILL here when passing the mode_t type. +*/ +#ifndef ANDROID + mode =va_arg (ap, mode_t); +#else + mode =va_arg (ap, int); +#endif + + attr = va_arg(ap, struct mq_attr *); + +va_end (ap); + + rval =mq_open (pathname, oflags, mode, attr); +if (rval ==-1 ) { +tst_brk (TBROK |TERRNO ,"%s:%d: mq_open(%s,%d,0%o,%p) failed" , + file, lineno, pathname, oflags, mode, attr); + } + +return rval; +}#endif /* TST_SAFE_POSIX_IPC_H__ */
lib/tst_safe_posix_ipc.c deleted +0 -55
55 lines not on this page · raw message
testcases/kernel/syscalls/mq_open/mq_open01.c +1 -1
@@ -24,9 +24,9 @@#include <mqueue.h> #include <pwd.h> +#include "tst_test.h" #include "tst_safe_file_ops.h" #include "tst_safe_posix_ipc.h" -#include "tst_test.h" #define QUEUE_NAME "/test_mqueue"#define QUEUE_INIT "/init_mqueue"
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +1 -1
@@ -24,9 +24,9 @@#include <limits.h> #include <mqueue.h> +#include "tst_test.h" #include "tst_sig_proc.h" #include "tst_safe_posix_ipc.h" -#include "tst_test.h" static struct sigaction act;static pid_t pid;
Signature · 1 line
2.10.2