【问题标题】:error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing] while compiling `gcc`错误:在编译“gcc”时将“-1”从“int”缩小到“long unsigned int”[-Wnarrowing]
【发布时间】:2020-08-16 13:00:42
【问题描述】:

当我遇到以下错误消息时,我正在使用 glibc-2.31 编译最终的 gcc-9.2.0 构建,同时使用 this articlemake && make install 来编译:

In file included from ../../../../libsanitizer/sanitizer_common/sanitizer
_platform_limits_posix.cc:193:
../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:339:7
2: error: narrowing conversion of '-1' from 'int' to 'long unsigned int'
[-Wnarrowing]
  339 | IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
      |                                                       ^

../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:333:3
0: note: in expansion of macro 'IMPL_COMPILER_ASSERT'
  333 | #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
      |                              ^~~~~~~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.h:1511:3: note: in expansion of macro 'COMPILER_CHECK'
 1511 |   COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) =
= \
      |   ^~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.cc:1161:1: note: in expansion of macro 'CHECK_SIZE_AND_OFFSET'
 1161 | CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
      | ^~~~~~~~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:339:7
0: warning: size of array 'assertion_failed__1161' is not an integral con
stant-expression [-Wpedantic]
  339 | r IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
      |                                          ~~~~~~~~~~~~~^~

../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:333:3
0: note: in expansion of macro 'IMPL_COMPILER_ASSERT'
  333 | #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
      |                              ^~~~~~~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.h:1511:3: note: in expansion of macro 'COMPILER_CHECK'
 1511 |   COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) =
= \
      |   ^~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.cc:1161:1: note: in expansion of macro 'CHECK_SIZE_AND_OFFSET'
 1161 | CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
      | ^~~~~~~~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:339:7
0: error: size '-1' of array 'assertion_failed__1161' is negative
  339 | r IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
      |                                          ~~~~~~~~~~~~~^~

../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:333:3
0: note: in expansion of macro 'IMPL_COMPILER_ASSERT'
  333 | #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
      |                              ^~~~~~~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.h:1511:3: note: in expansion of macro 'COMPILER_CHECK'
 1511 |   COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *) NULL)->MEMBER) =
= \
      |   ^~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix
.cc:1161:1: note: in expansion of macro 'CHECK_SIZE_AND_OFFSET'
 1161 | CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
      | ^~~~~~~~~~~~~~~~~~~~~
make[4]: *** [Makefile:663: sanitizer_platform_limits_posix.lo] Error 1
make[4]: Leaving directory '/home/sayakbrm/sbos/sources/gcc-9.2.0/gcc-bui
ld/x86_64-unknown-linux-gnu/libsanitizer/sanitizer_common'
make[3]: *** [Makefile:527: all-recursive] Error 1
make[3]: Leaving directory '/home/sayakbrm/sbos/sources/gcc-9.2.0/gcc-bui
ld/x86_64-unknown-linux-gnu/libsanitizer'
make[2]: *** [Makefile:414: all] Error 2
make[2]: Leaving directory '/home/sayakbrm/sbos/sources/gcc-9.2.0/gcc-bui
ld/x86_64-unknown-linux-gnu/libsanitizer'
make[1]: *** [Makefile:12361: all-target-libsanitizer] Error 2
make[1]: Leaving directory '/home/sayakbrm/sbos/sources/gcc-9.2.0/gcc-bui
ld'
make: *** [Makefile:962: all] Error 2

我已经成功编译了stage 1 gccglibc,而且这个错误只有在构建gcc的最终pass时才会出现。

【问题讨论】:

  • 这不是linux-from-scratch 的问题。 echo $LJOS_HOST && echo $LJOS_ENDIAN 输出什么?
  • 它发生了......好吧,再来一个:echo $LJOS?
  • 好的,很好。其他人可能知道如何解决您看到的错误,但可能的问题是您使用旧指令来构建更新的包。 (你为 GCC 跳了两个专业,这很重要......)所以我认为你应该回到开始,使用指定的包版本,并仔细按照说明进行操作(我没有理由认为你'不是。)一旦你成功地逐字构建它,那么你就可以开始定制它并克服这些挑战。你应该结帐Linux From Scratchlinuxfromscratch.org/lfs/view/stable
  • @rfmodulator 感谢您的建议!我确实想过建立一个 LFS 系统,并计划将此系统用作垫脚石。
  • @rfmodulator 感谢您提到 LFS,这个确切问题的解决方案恰好在手册中并且是由使用 glibc-2.31 引起的:stackoverflow.com/a/63439284/5961780

标签: c gcc glibc gcc-warning


【解决方案1】:

上述错误是由于使用 Glibc-2.31 引入的问题所致。

问题可以通过以下命令解决:

sed -e '1161 s|^|//|' \
    -i libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc

Source

【讨论】:

  • 很遗憾,“来源”链接似乎已损坏(2021 年 5 月 16 日检查)。您还记得您的链接在发帖时指向的 LinuxFromScratch 版本吗?
  • @Patrick LFS9.1...查看此链接以获取参考web.archive.org/web/20200723122730/http://…
【解决方案2】:

GCC 的 libsanitizer 需要移植到这个 glibc 更改中:

这发生在GCC PR 92154: new glibc breaks arm bootstrap due to libsanitizer 中,它包含在 GCC 9.3 中,但不包含在 GCC 9.2 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 2016-07-29
    • 2016-12-20
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多