【问题标题】:How to avoid auto-generate a ".cold" symbol which causes redefined error如何避免自动生成导致重新定义错误的“.cold”符号
【发布时间】:2022-01-25 09:19:06
【问题描述】:

我试图修改项目“CRIU”的部分代码,其代码在https://github.com/checkpoint-restore/criu。我更改了criu/pie/restorer.c 中的一些代码,具体来说,我在函数__export_restore_task 中添加了一些新变量。但是,在编译项目时,使用 gcc-9 会产生如下错误。

In file included from criu/cr-restore.c:47:
criu/pie/restorer-blob.h:3:9: error: ISO C99 requires whitespace after the macro name [-Werror]
    3 | #define restorer_sym__export_restore_task.cold 0x47a1
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu/pie/restorer-blob.h:6: error: "restorer_sym__export_restore_task" redefined [-Werror]
    6 | #define restorer_sym__export_restore_task 0x2270
      | 
criu/pie/restorer-blob.h:3: note: this is the location of the previous definition
    3 | #define restorer_sym__export_restore_task.cold 0x47a1
      | 

似乎有一个新的和不必要的符号#define restorer_sym__export_restore_task.cold 0x47a1。删除此行后,我可以成功编译项目。

但是,使用gcc 5.4.0编译项目不会产生这个问题,所以我认为可能是gcc版本的问题。另一个原因可能是堆栈的问题,因为我在编译项目的原始版本时添加了一些变量不会有这个问题。无论如何,即使使用gcc-9也可以编译没有.cold符号的程序吗?

有关详细信息,您可以参考我的拉取请求,https://github.com/checkpoint-restore/criu/pull/1711

【问题讨论】:

  • 编辑问题以提供minimal reproducible example。
  • 这不是一个真正的 C 问题。 restorer-blob.h 文件甚至不存在于存储库中的文件中,因此必须在构建期间生成。当你在criu/pie/restorer.c 中“更改了一些代码”时,你破坏了一些东西。但是您甚至没有描述更改,更不用说显示更改或显示minimal reproducible example。所以没有足够的信息来诊断你破坏了什么。
  • 好的,我已经给出了我的拉取请求,它可以用 gcc-9 重现这个问题。

标签: c gcc symbols


【解决方案1】:

使用标志-fno-reorder-blocks-and-partition可以解决这个问题,因为标志禁止gcc生成冷热符号。

【讨论】:

    【解决方案2】:
    #define restorer_sym__export_restore_task.cold 0x47a1
    

    意思相同

    #define restorer_sym__export_restore_task .cold 0x47a1
    

    它定义了restorer_sym__export_restore_task 符号。正如它再次定义的那样 - 您会收到 警告。您将警告视为错误。

    改变

    restorer_sym__export_restore_task.cold 到 restorer_sym__export_restore_task_cold 可以正常编译

    【讨论】:

    • 感谢您的回复!但是它在 CI 测试中失败了,所以我想知道是否有什么办法可以避免生成 .cold 符号,因为我无法修改 CI 测试。
    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多