编译器更改函数名称

标签 c compilation symbol-table

我遇到了这种奇怪的情况。我正在尝试取消一些树莓派库函数的前缀。例如我希望 bcm2835_delay() 为delay()。我有两个文件,pi.h 和 pi.c。当我使用 gcc -lm pi.c -c 编译这两个文件时,我的去前缀延迟()变成了 bcm2835_delay()。下面是我的两个文件和 objdump -t pi.o 的输出。

pi.h

#include <bcm2835.h>

#define PIN05 RPI_V2_GPIO_P1_05
#define PIN07 RPI_V2_GPIO_P1_07
#define PIN08 RPI_V2_GPIO_P1_08
#define PIN10 RPI_V2_GPIO_P1_10
#define PIN11 RPI_V2_GPIO_P1_11
#define PIN12 RPI_V2_GPIO_P1_12
#define PIN13 RPI_V2_GPIO_P1_13
#define PIN15 RPI_V2_GPIO_P1_15
#define PIN16 RPI_V2_GPIO_P1_16
#define PIN18 RPI_V2_GPIO_P1_18
#define PIN19 RPI_V2_GPIO_P1_19
#define PIN21 RPI_V2_GPIO_P1_21
#define PIN22 RPI_V2_GPIO_P1_22
#define PIN23 RPI_V2_GPIO_P1_23
#define PIN24 RPI_V2_GPIO_P1_24
#define PIN26 RPI_V2_GPIO_P1_26

#define INPUT BCM2835_GPIO_FSEL_INPT
#define OUTPUT BCM2835_GPIO_FSEL_OUTP

// rename the delay function given already
void delay(unsigned int millis);

// rename the microsecond delay function
void delay_micro(uint64_t micros);

// set the pinout to low, check that the pin is output
void set_low(uint8_t pin);

// ease the input setting
void set_input(uint8_t pin);

// ease the output setting
void set_output(uint8_t pin);

和图片.c

#include <bcm2835.h>
#include "pi.h"

// rename the delay function given already
void delay(unsigned int millis) {
  bcm2835_delay(millis);
}

// rename the microsecond delay function
void delay_micro(uint64_t micros) {
  bcm2835_delayMicroseconds(micros);
}

// set the pinout to low, check that the pin is output
void set_low(uint8_t pin) {

}

// ease the input setting
void set_input(uint8_t pin) {
  bcm2835_gpio_fsel(pin, INPUT);
}

// ease the output setting
void set_output(uint8_t pin) {
  bcm2835_gpio_fsel(pin, OUTPUT);
}

输出

pi.o:文件格式 elf32-littlearm

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 pi.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss 00000000 .bss
00000000 l    d  .note.GNU-stack  00000000 .note.GNU-stack
00000000 l    d  .comment 00000000 .comment
00000000 l    d  .ARM.attributes  00000000 .ARM.attributes
00000000 g     F .text  00000020 bcm2835_delay
00000020 g     F .text  00000020 delay_micro
00000000         *UND*  00000000 bcm2835_delayMicroseconds
00000040 g     F .text  00000020 set_low
00000060 g     F .text  0000002c set_input
00000000         *UND*  00000000 bcm2835_gpio_fsel
0000008c g     F .text  0000002c set_output

在这里你可以看到除了delay()函数之外,我的所有函数定义都很好地进入了符号表。在符号表中它显示为 bcm2835_delay。如果我将delay()更改为my_delay(),它就会像my_delay()一样进入符号表。这是怎么回事?

最佳答案

编译器已将您的函数视为内联函数。

关于编译器更改函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22192463/

相关文章:

检查程序的不同目录

javascript - 如何将多个JS和CSS文件编译成一个大的JS和CSS文件?

linux - 动态加载和弱符号解析

java - 符号表实现

c - 以下 C 结构如何扩展为

c - 将字符数组转换为字符串数组的问题

c++ - 交换整数的代码适用于 C++,但不适用于 C

用 ifort 和 icc 编译和链接 Fortran 和 C

c - 为什么 Sublime Text 报告我的程序以退出代码 1 终止?

compiler-construction - 编译器如何处理符号表中的默认值