Why does file command report "not stripped, with debug_info" of the executable file without "-g" option during compilation?
Asked Answered
C

1

5

My OS is Arch Linux, and the test.c program is very simple:

# cat test.c
#include <stdio.h>

int main(void) {
        printf("Hello world!\n");
}

Compile it without -g option, and use file command to check the executable file information:

# gcc test.c
# file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c7a538046222b5209d2daafbfc246de341a652d9, not stripped, with debug_info

The file command outputs "not stripped, with debug_info", but I don't use -g option during compilation. Use gdb to debug a.out:

# gdb a.out
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...(no debugging symbols found)...done.
(gdb)

I can see gdb also prompts "Reading symbols from a.out...(no debugging symbols found)...done.".

Why does file command report "not stripped, with debug_info" of the executable file without "-g" option during compilation?

Codfish answered 3/4, 2017 at 9:43 Comment(1)
There is still minimal info that can be used for debugging (global function and variable names). You can remove them with the strip command.Exhaustion
A
8

Why does file command report "not stripped, with debug_info" of the executable file without "-g" option during compilation?

Your program links in parts of libc_nonshared.a (e.g. the c runtime startup ctr0.o), which may contain some debug info.

You can see what debug info is available and guess where it came from with:

readelf -wl ./a.out
Archenemy answered 3/4, 2017 at 14:45 Comment(1)
This shows that objdump -x ./a.out | grep debug_info is a better way than file to find out if an executable has debug info.Cogent

© 2022 - 2024 — McMap. All rights reserved.