开发者

Why does gcc add symbols to non-debug build?

开发者 https://www.devze.com 2022-12-23 22:46 出处:网络
When I do a release build with gcc (i.e. I do not specify -g), I still seem to end up with symbols in the binary, and have to use strip to remove them. In fact, I can still breakpoint functions and ge

When I do a release build with gcc (i.e. I do not specify -g), I still seem to end up with symbols in the binary, and have to use strip to remove them. In fact, I can still breakpoint functions and get backtraces in gdb (albeit without line numbers).

This surprised me - can anyone explain why this happens?

e.g.

#include <stdio.h>

static void blah(void)
{
    printf("hello world\n");
}
int main(int argc, char *argv[])
{
    blah();
    return开发者_开发百科 0;
}

gcc -o foo foo.c

nm foo | grep blah:

08048374 t blah


There's a big difference between debug symbols and linker symbols. Debug symbols map code locations etc to source file names and line numbers and various other useful things to help debuggers, profilers, etc. Linker symbols just define the addresses of various entry points and other important locations in your code. If you want to make an executable completely anonymous then you need to use strip, as you have seen.


It is just the default behavior for GCC. A semi useful compromise between having debug information included and not having anything at all. One could of course argue that stripping should be the default, but it's just a matter of adding -s or use the strip command to control it anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号