nm: 一些符号与任何源文件无关

nm: some symbols are not related to any source file

在我的嵌入式项目中,我这样编译amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c

/opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc \
    -std=gnu11 \
    -mcpu=cortex-m7 \
    -mthumb \
    -mapcs \
    -mfloat-abi=hard \
    -mfpu=fpv5-d16 \
    -fno-common \
    -fno-math-errno \
    -fsingle-precision-constant \
    -fno-trapping-math \
    -fno-signaling-nans \
    -fno-builtin \
    -fstrict-aliasing \
    -fstack-usage \
    -Wstack-usage=300 \
    -DCPU_MIMXRT1051DVL6B  \
    -D__FREERTOS__=1 \
    -DFSL_RTOS_FREE_RTOS \
    -DFSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE \
    -D__MCUXPRESSO \
    -D__USE_CMSIS \
    -DARM_MATH_CM7 \
    -D__NEWLIB__ \
    -DDEBUG=0 \
    -IDSP/source/ \
    -Iamazon-freertos/lib/FreeRTOS-Plus-TCP/ \
    -Iamazon-freertos/lib/FreeRTOS-Plus-TCP/portable/BufferManagement/ \
    -Iamazon-freertos/lib/FreeRTOS-Plus-TCP/portable/NetworkInterface/imxrt105x/ \
    -Iamazon-freertos/lib/FreeRTOS/ \
    -Iamazon-freertos/lib/include/ \
    -Iamazon-freertos/lib/FreeRTOS/portable/GCC/ARM_CM4F/ \
    -Iamazon-freertos/lib/FreeRTOS/portable/MemMang/ \
    -Og \
    -g3 \
    -Wall \
    -ffunction-sections \
    -fdata-sections \
    -c \
    -MMD \
    -MP \
    -Werror \
    -D"ARCPRINTF( ... )=(void)0" \
    --specs=nano.specs  \
    -Wa,-anhlmsd=build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.lst \
    -o build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.o amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c 

我在 amazon-freertos/lib/FreeRTOS-Plus-TCP/include/FreeRTOSIPConfig.h

中将 ipconfigUSE_TCP 设置为 1

FreeRTOS_Sockets.c 声明 xBoundUDPSocketsListxBoundTCPSocketsList

/* The list that contains mappings between sockets and port numbers.  Accesses
to this list must be protected by critical sections of one kind or another. */
List_t xBoundUDPSocketsList;

#if ipconfigUSE_TCP == 1
    List_t xBoundTCPSocketsList;
#endif /* ipconfigUSE_TCP == 1 */

一旦我链接了我的 elf 可执行文件,运行 这个命令:

$ /opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-nm -a -l -n -t x --print-size image/DSP.elf | grep -E '^[[:xdigit:]]{8} [[:xdigit:]]{8} B' | grep SocketsList
2001ac7c 00000014 B xBoundTCPSocketsList
2001ac90 00000014 B xBoundUDPSocketsList    /home/max/Lavori/4202/src/repos/toremove/FW/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c:162

两个符号都存在于可执行文件中,但其中一个 (xBoundTCPSocketsList) 似乎不属于任何 .c 源。 两者都出现在地图文件中:

$ grep -n -A 1 -E 'xBoundTCPSocketsList|xBoundUDPSocketsList' image/DSP.map
61974: .bss.xBoundTCPSocketsList
61975-                0x000000002001ac7c       0x14 ./build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.o
61976:                0x000000002001ac7c                xBoundTCPSocketsList
61977: .bss.xBoundUDPSocketsList
61978-                0x000000002001ac90       0x14 ./build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.o
61979:                0x000000002001ac90                xBoundUDPSocketsList

连 addr2line 都失败了:

$ arm-none-eabi-addr2line -a -e image/DSP.elf  2001ac7c 2001ac90
0x2001ac7c
??:0
0x2001ac90
/home/max/Lavori/4202/src/repos/toremove/FW/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c:162

甚至 FreeRTOS_Sockets.lst 也没有告诉我更多信息:

 7337                   .global xBoundTCPSocketsList
 7338                   .global xBoundUDPSocketsList
 7339                   .section    .bss.xBoundTCPSocketsList,"aw",%nobits
 7340                   .align  2
 7341                   .set    .LANCHOR2,. + 0
 7344               xBoundTCPSocketsList:
 7345 0000 00000000         .space  20
 7345      00000000 
 7345      00000000 
 7345      00000000 
 7345      00000000 
 7346                   .section    .bss.xBoundUDPSocketsList,"aw",%nobits
 7347                   .align  2
 7348                   .set    .LANCHOR1,. + 0
 7351               xBoundUDPSocketsList:
 7352 0000 00000000         .space  20
 7352      00000000 
 7352      00000000 
 7352      00000000 
 7352      00000000 

可执行文件中还有许多其他符号,但它们似乎与任何 .c 源文件都没有关联。

为什么会出现这种行为? xBoundTCPSocketsListxBoundUDPSocketsList 这两个符号之间有什么变化?是我编译错了还是漏掉了一些调试参数?我如何通过 nm 或其他方式获取声明符号的 .c 源代码?

编辑:

我认为问题不在链接中

事实上,即使我分析 ./build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.o:

,我也得到了 arm-none-eabi-nm 的相同输出
$ arm-none-eabi-nm -a -l -n -t x --print-size build/DSP/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.o | grep -E '^[[:xdigit:]]{8} [[:xdigit:]]{8} B' | grep SocketsList
00000000 00000014 B xBoundTCPSocketsList
00000000 00000014 B xBoundUDPSocketsList    /home/max/Lavori/4202/src/repos/toremove/FW/amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c:162

我在 binutils 问题跟踪系统上打开了一个错误:
https://sourceware.org/bugzilla/show_bug.cgi?id=25676

我想我可以说它已经修复了。