0

I am trying to compile a basic c program to get the binary ELF on my Ubuntu x86-64 machine. I want the binary to comply with the DWARF5 format as I am working on writing a .debug_sup section parser. However I am not sure if this is because I have an older version of gcc or am I passing the wrong flags.

I am pretty sure I have the right binutils version for parsing DWARF5 as the release notes here say.

The C- Program I am trying to build is as follows:

#include    <stdio.h>
#include    <stdlib.h>

/*
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:
 * =====================================================================================
 */
    int
main ( int argc, char *argv[] )
{
    int a = 10, b = 15;
    int *ptra = &a, *ptrb = &b;
    printf ("a = %d and b = %d\n", *ptra, *ptrb) ;
    ptra = &b;
    ptrb = &a;
    printf ("a = %d and b = %d\n", *ptra, *ptrb) ;
    int ** pptra = &ptra, **pptrb = &ptrb;
    printf ("a = %d and b = %d\n", **pptra, **pptrb) ;
    return EXIT_SUCCESS;
}               /* ----------  end of function main  ---------- */

I try to compile it using gcc basic_declaration_of_pointer.c -gdwarf-5 however the objdump of the binary still ends up showing older DWARF3 version. The docs here is where I learned about the dwarf version flag. My gcc version is as follows:

gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

objdump version

└─❯ objdump --version
GNU objdump (GNU Binutils) 2.37
Copyright (C) 2021 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
dg_linux
  • 1
  • 1
  • 1
    The DWARF version may vary between compilation units (source files). Did you notice whether DWARF3 was on *your* source, or in a library provided object? The DWARF data on those comes from the library which is not recompiled during your build. – Seva Alekseyev Apr 01 '22 at 17:54
  • @SevaAlekseyev a small update, I tried the latest gcc 11.2 using their docker image. You can see what I have done [here](https://pastebin.com/GNaES2Sw) Now as you see the DWARF version does say 5 but the ``.debug_sup`` section still is not shown. – dg_linux Apr 04 '22 at 19:10
  • I've checked the DWARF5 reference - `.debug_sup` is entirely optional. It's a way to optimize the debug info after linking. The compiler **may** optimize, but does not **have to**. After all, DWARF5 is a superset of DWARF2..4, so any valid DWARF4 is also valid DWARF5. There is no format violation there. The title of the question should be "how do I make the compiler generate .debug_sup". – Seva Alekseyev Apr 06 '22 at 15:02
  • And, with that in mind, try checking the history behind debug_sup. Was it, by any chance, initially proposed by a a certain compiler vendor? Sometimes the bits history like that can be found on the big wide 'Net. – Seva Alekseyev Apr 06 '22 at 15:05

0 Answers0