SYS_FUNC macro fix for musl

Szabolcs Nagy nsz at port70.net
Mon Dec 14 20:05:50 UTC 2015


currently the syscall_name argument of the SYS_FUNC and
SEN macros is subject to macro expansion (because it is
passed to other function-like macros as parameter before
it is prefixed).

if lfs64 support is requested (_GNU_SOURCE is defined),
musl defines lfs64 names as macros like

	#define fstat64 fstat

(there is no easy way around this because both stat64
function and stat64 struct tag should be redirected to
plain stat, doing it with proper wrappers would add
significant boilerplate to the libc).

so strace fails to build. (sys_fstat64 becomes sys_fstat)

i'd like to propose a workaround that always prefixes
the syscall_name before anything is done with it.
(it seems to me that the code assumes sys_ prefix anyway.)


diff --git a/defs.h b/defs.h
index 0538bcf..782f443 100644
--- a/defs.h
+++ b/defs.h
@@ -800,8 +800,8 @@ extern unsigned num_quals;
 #define MPERS_FUNC_NAME_(prefix, name) MPERS_FUNC_NAME__(prefix, name)
 #define MPERS_FUNC_NAME(name) MPERS_FUNC_NAME_(MPERS_PREFIX, name)
 
-#define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(sys_ ## syscall_name)
+#define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(syscall_name)
 
-#define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(syscall_name)(struct tcb *tcp)
+#define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(sys_ ## syscall_name)(struct tcb *tcp)
 
 #define MPERS_PRINTER_DECL(type, name) type MPERS_FUNC_NAME(name)
diff --git a/linux/ia64/syscallent.h b/linux/ia64/syscallent.h
index 3bfa347..7867b7a 100644
--- a/linux/ia64/syscallent.h
+++ b/linux/ia64/syscallent.h
@@ -31,10 +31,10 @@
  * with 64-bit layout get redirected to printargs.
  */
 #undef SYS_FUNC_NAME
-#define SYS_FUNC_NAME(syscall_name) printargs
+#define SYS_FUNC_NAME(syscall_name) sys_printargs
 #include "../i386/syscallent.h"
 #undef SYS_FUNC_NAME
-#define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(sys_ ## syscall_name)
+#define SYS_FUNC_NAME(syscall_name) MPERS_FUNC_NAME(syscall_name)
 
 /* You must be careful to check ../i386/syscallent.h so that this table
    starts where that one leaves off.
diff --git a/syscall.c b/syscall.c
index 66154f7..8d81274 100644
--- a/syscall.c
+++ b/syscall.c
@@ -82,8 +82,7 @@
 #define SI STACKTRACE_INVALIDATE_CACHE
 #define SE STACKTRACE_CAPTURE_ON_ENTER
 
-#define SEN_NAME(syscall_name) SEN_ ## syscall_name
-#define SEN(syscall_name) SEN_NAME(syscall_name), SYS_FUNC_NAME(syscall_name)
+#define SEN(syscall_name) SEN_ ## syscall_name, SYS_FUNC_NAME(sys_ ## syscall_name)
 
 const struct_sysent sysent0[] = {
 #include "syscallent.h"
@@ -105,7 +104,6 @@ static const struct_sysent sysent2[] = {
 
 /* Now undef them since short defines cause wicked namespace pollution. */
 #undef SEN
-#undef SEN_NAME
 #undef TD
 #undef TF
 #undef TI




More information about the Strace-devel mailing list