Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error when turn on CONFIG_DEBUG #206

Open
cebarobot opened this issue Nov 3, 2023 · 0 comments
Open

Compile error when turn on CONFIG_DEBUG #206

cebarobot opened this issue Nov 3, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@cebarobot
Copy link
Member

Description 描述

When turning on Testing and Debugging -> Enable debug features: instruction tracing and watchpoint (macro CONFIG_DEBUG ), compiling NEMU will get a format-truncation error:
开启 Testing and Debugging -> Enable debug features: instruction tracing and watchpoint (宏 CONFIG_DEBUG )之后,编译 NEMU 会出现 format-truncation 报错:

include/common.h:34:39: error: ‘%s’ directive output may be truncated writing up to 79 bytes into a region of size 58 [-Werror=format-truncation=]
Full Error logs
ln -sf resource/softfloat/repo/build/Linux-x86_64-GCC/softfloat.a resource/softfloat/build/softfloat.a
In file included from include/common.h:26,
                 from include/cpu/cpu.h:19,
                 from src/cpu/cpu-exec.c:18:
src/cpu/cpu-exec.c: In function ‘fetch_decode’:
include/common.h:34:39: error: ‘%s’ directive output may be truncated writing up to 79 bytes into a region of size 58 [-Werror=format-truncation=]
   34 | #define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016lx", "0x%08x")
      |                                       ^~~~~~~~~~
include/macro.h:69:21: note: in definition of macro ‘__KEEP’
   69 | #define __KEEP(...) __VA_ARGS__
      |                     ^~~~~~~~~~~
src/cpu/cpu-exec.c:577:3: note: in expansion of macro ‘IFDEF’
  577 |   IFDEF(CONFIG_DEBUG,
      |   ^~~~~
include/macro.h:41:45: note: in expansion of macro ‘CHOOSE2nd’
   41 | #define MUX_WITH_COMMA(contain_comma, a, b) CHOOSE2nd(contain_comma a, b)
      |                                             ^~~~~~~~~
include/macro.h:42:44: note: in expansion of macro ‘MUX_WITH_COMMA’
   42 | #define MUX_MACRO_PROPERTY(p, macro, a, b) MUX_WITH_COMMA(concat(p, macro), a, b)
      |                                            ^~~~~~~~~~~~~~
include/macro.h:49:30: note: in expansion of macro ‘MUX_MACRO_PROPERTY’
   49 | #define MUXDEF(macro, X, Y)  MUX_MACRO_PROPERTY(__P_DEF_, macro, X, Y)
      |                              ^~~~~~~~~~~~~~~~~~
include/common.h:34:18: note: in expansion of macro ‘MUXDEF’
   34 | #define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016lx", "0x%08x")
      |                  ^~~~~~
src/cpu/cpu-exec.c:578:48: note: in expansion of macro ‘FMT_WORD’
  578 |         snprintf(s->logbuf, sizeof(s->logbuf), FMT_WORD ":   %s%*.s%s", s->pc,
      |                                                ^~~~~~~~
src/cpu/cpu-exec.c:578:62: note: format string is defined here
  578 |         snprintf(s->logbuf, sizeof(s->logbuf), FMT_WORD ":   %s%*.s%s", s->pc,
      |                                                              ^~
In file included from include/common.h:26,
                 from include/cpu/cpu.h:19,
                 from src/cpu/cpu-exec.c:18:
include/common.h:34:39: note: assuming directive output of 1 byte
   34 | #define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016lx", "0x%08x")
      |                                       ^~~~~~~~~~
include/macro.h:69:21: note: in definition of macro ‘__KEEP’
   69 | #define __KEEP(...) __VA_ARGS__
      |                     ^~~~~~~~~~~
src/cpu/cpu-exec.c:577:3: note: in expansion of macro ‘IFDEF’
  577 |   IFDEF(CONFIG_DEBUG,
      |   ^~~~~
include/macro.h:41:45: note: in expansion of macro ‘CHOOSE2nd’
   41 | #define MUX_WITH_COMMA(contain_comma, a, b) CHOOSE2nd(contain_comma a, b)
      |                                             ^~~~~~~~~
include/macro.h:42:44: note: in expansion of macro ‘MUX_WITH_COMMA’
   42 | #define MUX_MACRO_PROPERTY(p, macro, a, b) MUX_WITH_COMMA(concat(p, macro), a, b)
      |                                            ^~~~~~~~~~~~~~
include/macro.h:49:30: note: in expansion of macro ‘MUX_MACRO_PROPERTY’
   49 | #define MUXDEF(macro, X, Y)  MUX_MACRO_PROPERTY(__P_DEF_, macro, X, Y)
      |                              ^~~~~~~~~~~~~~~~~~
include/common.h:34:18: note: in expansion of macro ‘MUXDEF’
   34 | #define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016lx", "0x%08x")
      |                  ^~~~~~
src/cpu/cpu-exec.c:578:48: note: in expansion of macro ‘FMT_WORD’
  578 |         snprintf(s->logbuf, sizeof(s->logbuf), FMT_WORD ":   %s%*.s%s", s->pc,
      |                                                ^~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from include/debug.h:20,
                 from include/common.h:55,
                 from include/cpu/cpu.h:19,
                 from src/cpu/cpu-exec.c:18:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 23 and 2147483828 bytes into a destination of size 80
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Environment 环境

  • gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
  • commit 5e081a5

Possible solutions 可能的解决方案

I think this warning is a misreport. This debug output may be truncated in theroy, not not in practice. I think add -Wno-format-truncation to CFLAGS and CXXFLAGS in Makefile will solve this. I can't think of any unexpected results.
我认为这个警告是误报。这个调试输出理论上可能被截断,但实际并不会(实际上就算节段了也完全不影响)。在Makefile中的 CFLAGSCXXFLAGS 中添加 -Wno-format-truncation 可以解决此问题。我想不出有什么出乎意料的结果。

@cebarobot cebarobot added the bug Something isn't working label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant