From 2a1c6258fae187d4bd16837ce16da7ca6e759535 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Thu, 26 Sep 2019 13:57:59 +0900 Subject: [PATCH] scripts: gen_syscalls: Add compiler check to pragma. This commit addresses the following portability issues: 1. gen_syscalls incorrectly assumes that the compiler is always GCC. 2. pragma GCC diagnostic push and pop are not supported in GCC < 4.6. Signed-off-by: Stephanos Ioannidis --- scripts/gen_syscalls.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/gen_syscalls.py b/scripts/gen_syscalls.py index beffaf73396..3fc9f09a804 100755 --- a/scripts/gen_syscalls.py +++ b/scripts/gen_syscalls.py @@ -80,8 +80,13 @@ syscall_template = """ #include #include +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic push +#endif + +#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif #ifdef __cplusplus extern "C" { @@ -93,7 +98,9 @@ extern "C" { } #endif +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic pop +#endif #endif #endif /* include guard */ @@ -411,12 +418,18 @@ def main(): with open(mrsh_fn, "w") as fp: fp.write("/* auto-generated by gen_syscalls.py, don't edit */\n") + fp.write("#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)\n") fp.write("#pragma GCC diagnostic push\n") + fp.write("#endif\n") + fp.write("#ifdef __GNUC__\n") fp.write("#pragma GCC diagnostic ignored \"-Wstrict-aliasing\"\n") + fp.write("#endif\n") fp.write(mrsh_includes[fn] + "\n") fp.write("\n") fp.write(mrsh_defs[fn] + "\n") + fp.write("#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)\n") fp.write("#pragma GCC diagnostic pop\n") + fp.write("#endif\n") if __name__ == "__main__": main()