]> granicus.if.org Git - strace/commitdiff
mpers: skip xlat struct definitions in mpers mode
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 20 Nov 2015 01:43:12 +0000 (01:43 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 20 Nov 2015 05:44:49 +0000 (05:44 +0000)
Avoid duplicate definitions of xlat structures in files
compiled in mpers mode.

Each xlat file defines the corresponding xlat struct with
either global or local visibility using the following rules:

- if xlat struct declaration is available in defs.h,
  a global definition is provided in regular mode,
  and nothing is provided in mpers mode;
- otherwise, if xlat file is included by a mpers source file,
  a global definition is provided in regular mode
  (unless no mpers mode is supported on this architecture,
  in that case, a local definition is provided instead),
  and a declaration is provided in mpers mode;
- otherwise, a local definition is provided in regular mode,
  and an error message is printed in mpers mode.

Fallback definitions of constants provided by xlat files
remain available in all modes.

* bootstrap: Invoke generate_mpers_am.sh before xlat/gen.sh.
* defs.h (adjtimex_modes, adjtimex_status, sigev_value): Remove.
* generate_mpers_am.sh: Generate mpers_xlat.h.
* Makefile.am (EXTRA_DIST): Add mpers_xlat.h.
* print_sigevent.c: Include "xlat/sigev_value.h" unconditionally.
* print_timex.c: Include "xlat/adjtimex_modes.h" and
"xlat/adjtimex_status.h" unconditionally.
* xlat/gen.sh (cond_xlat): Move printing of fallback definitions ...
(cond_def): ... here.
(gen_header): Check also mpers_xlat.h for global declarations
of xlat structures.
Process input file twice, first time print directives
only, second time print everything.
Wrap struct xlat into #ifdef IN_MPERS ... #else ... #endif.
* xlat/getrandom_flags.in: Cleanup.

Makefile.am
bootstrap
defs.h
generate_mpers_am.sh
print_sigevent.c
print_timex.c
xlat/gen.sh
xlat/getrandom_flags.in

index a79d50c25372054cb4171cd3f980923bb69116d4..b74bf455dc50f1adb74a7fe81adc65513d0fc68e 100644 (file)
@@ -595,6 +595,7 @@ EXTRA_DIST =                                \
        mpers.awk                       \
        mpers.sh                        \
        mpers_test.sh                   \
+       mpers_xlat.h                    \
        signalent.sh                    \
        strace-graph                    \
        strace-log-merge                \
index 59d2480d1b832dd25ffe7840005b4f849b0d4a91..9b432d415853da58e59e3164f88d222d11fe51a0 100755 (executable)
--- a/bootstrap
+++ b/bootstrap
@@ -14,7 +14,7 @@ for m in -m32 -mx32; do
        done
 done
 
-./xlat/gen.sh
 ./generate_mpers_am.sh
+./xlat/gen.sh
 
 exec autoreconf -f -i "$@"
diff --git a/defs.h b/defs.h
index 5e40f4db0f0fad7d06f365ad41404fb601a0f64a..4aab7bbfdae9bf0964ad6bccdb74eec040777fd9 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -410,14 +410,11 @@ struct xlat {
 #define XLAT_END { 0, NULL }
 
 extern const struct xlat addrfams[];
-extern const struct xlat adjtimex_modes[];
-extern const struct xlat adjtimex_status[];
 extern const struct xlat at_flags[];
 extern const struct xlat dirent_types[];
 extern const struct xlat open_access_modes[];
 extern const struct xlat open_mode_flags[];
 extern const struct xlat resource_flags[];
-extern const struct xlat sigev_value[];
 extern const struct xlat whence_codes[];
 
 /* Format of syscall return values */
index 5469c946679d87f8ff8210d975dae505e7bdd957..1ee4791be51bf5bf63044fc64219510470bc63b3 100755 (executable)
@@ -1,11 +1,13 @@
 #!/bin/sh -e
 
-exec > mpers.am
+list="$(sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.am |
+       xargs -r grep -lx '#[[:space:]]*include[[:space:]]\+MPERS_DEFS' |
+       tr '\n' ' ')"
 
-echo "# Generated by $0; do not edit."
-printf 'mpers_source_files = '
+cat > mpers.am <<EOF
+# Generated by $0; do not edit.
+mpers_source_files = $list
+EOF
 
-sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.am |
-       xargs -r grep -lx '#[[:space:]]*include[[:space:]]\+MPERS_DEFS' |
-       tr '\n' ' '
-echo
+sed -n 's/^#[[:space:]]*include[[:space:]]*"xlat\/\([^."]\+\)\.h".*/extern const struct xlat \1[];/p' \
+       $list > mpers_xlat.h
index 5454486b6cf2592f615fe3982c16da8cd75d7733..9ef655ae22fb02daecb150d582b06a448c8e06ef 100644 (file)
@@ -35,9 +35,7 @@ typedef struct sigevent struct_sigevent;
 
 #include MPERS_DEFS
 
-#ifndef IN_MPERS
-# include "xlat/sigev_value.h"
-#endif
+#include "xlat/sigev_value.h"
 
 MPERS_PRINTER_DECL(void, print_sigevent)(struct tcb *tcp, const long addr)
 {
index f961ecf2444ff57088c64fedd222057df1895610..4eac54df8976166cc41486e78a5533b6a6449707 100644 (file)
@@ -37,10 +37,8 @@ typedef struct timex struct_timex;
 
 #include MPERS_DEFS
 
-#ifndef IN_MPERS
-# include "xlat/adjtimex_modes.h"
-# include "xlat/adjtimex_status.h"
-#endif
+#include "xlat/adjtimex_modes.h"
+#include "xlat/adjtimex_status.h"
 
 MPERS_PRINTER_DECL(int, print_timex)(struct tcb *tcp, const long addr)
 {
index 8754a032534af7bf435a783694e61a4082f2cfac..0f1adadc2db09c2a1e090b98e7fd007c3b07444d 100755 (executable)
@@ -11,6 +11,28 @@ EOF
        exit 1
 }
 
+cond_def()
+{
+       local line
+       line="$1"; shift
+
+       local val
+       val="$(printf %s "$line" |
+               sed -n 's/^\([^[:space:]]\+\).*$/\1/p')"
+
+       local def
+       def="$(printf %s "${line}" |
+               sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
+
+       if [ -n "$def" ]; then
+               cat <<-EOF
+               #if !(defined($val) || (defined(HAVE_DECL_$val) && HAVE_DECL_$val))
+               # define $val $def
+               #endif
+               EOF
+       fi
+}
+
 cond_xlat()
 {
        local line val m def xlat
@@ -22,7 +44,7 @@ cond_xlat()
               sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
 
        if [ "${m}" = "${m#1<<}" ]; then
-               xlat="XLAT(${val}),"
+               xlat=" XLAT(${val}),"
        else
                m="${m#1<<}"
                xlat=" { ${val}, \"${m}\" },"
@@ -35,12 +57,7 @@ cond_xlat()
                #endif
                EOF
        else
-               cat <<-EOF
-               #if !(defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m}))
-               # define ${m} ${def}
-               #endif
-                ${xlat}
-               EOF
+               echo "$xlat"
        fi
 }
 
@@ -50,28 +67,81 @@ gen_header()
        echo "generating ${output}"
        (
        local defs="${0%/*}/../defs.h"
-       local prefix
-       if grep -x "extern const struct xlat ${name}\\[\\];" "${defs}" > /dev/null; then
-               prefix=
-       else
-               prefix='static '
+       local mpers="${0%/*}/../mpers_xlat.h"
+       local decl="extern const struct xlat ${name}[];"
+       local in_defs= in_mpers=
+
+       if grep -F -x "$decl" "$defs" > /dev/null; then
+               in_defs=1
+       elif grep -F -x "$decl" "$mpers" > /dev/null; then
+               in_mpers=1
        fi
 
-       cat <<-EOF
-               /* Generated by $0 from $1; do not edit. */
+       echo "/* Generated by $0 from $1; do not edit. */"
 
-               ${prefix}const struct xlat ${name}[] = {
-       EOF
        local unconditional= unterminated= line
+       # 1st pass: output directives.
        while read line; do
                LC_COLLATE=C
-               case ${line} in
+               case $line in
                '#unconditional')
                        unconditional=1
                        ;;
                '#unterminated')
                        unterminated=1
                        ;;
+               '#'*)
+                       echo "${line}"
+                       ;;
+               [A-Z_]*)
+                       [ -n "$unconditional" ] ||
+                               cond_def "$line"
+                       ;;
+               esac
+       done < "$input"
+
+       echo
+       if [ -n "$in_defs" ]; then
+               cat <<-EOF
+                       #ifndef IN_MPERS
+
+               EOF
+       elif [ -n "$in_mpers" ]; then
+               cat <<-EOF
+                       #ifdef IN_MPERS
+
+                       ${decl}
+
+                       #else
+
+                       # if !(defined HAVE_M32_MPERS || defined HAVE_MX32_MPERS)
+                       static
+                       # endif
+               EOF
+       else
+               cat <<-EOF
+                       #ifdef IN_MPERS
+
+                       # error static const struct xlat ${name} in mpers mode
+
+                       #else
+
+                       static
+               EOF
+       fi
+       echo "const struct xlat ${name}[] = {"
+
+       unconditional=
+       # 2nd pass: output everything.
+       while read line; do
+               LC_COLLATE=C
+               case ${line} in
+               '#unconditional')
+                       unconditional=1
+                       ;;
+               '#unterminated')
+                       # processed during 1st pass
+                       ;;
                [A-Z_]*)        # symbolic constants
                        if [ -n "${unconditional}" ]; then
                                echo " XLAT(${line}),"
@@ -80,7 +150,6 @@ gen_header()
                        fi
                        ;;
                '1<<'[A-Z_]*)   # symbolic constants with shift
-                       m="${line%% *}"
                        if [ -n "${unconditional}" ]; then
                                echo " { ${line}, \"${line#1<<}\" },"
                        else
@@ -100,7 +169,12 @@ gen_header()
        else
                echo " XLAT_END"
        fi
-       echo "};"
+
+       cat <<-EOF
+               };
+
+               #endif /* !IN_MPERS */
+       EOF
        ) >"${output}"
 }
 
index 7b77c5ab5311e6b73c64965742bc03e775d03f32..ad1a7580606a7eeb3d138cb76a6a2405a402a8f5 100644 (file)
@@ -1,12 +1,2 @@
-#unconditional
-
-#ifndef GRND_NONBLOCK
-# define GRND_NONBLOCK 1
-#endif
-
-#ifndef GRND_RANDOM
-# define GRND_RANDOM 2
-#endif
-
-GRND_NONBLOCK
-GRND_RANDOM
+GRND_NONBLOCK  1
+GRND_RANDOM    2