Skip to content

Commit

Permalink
Support for DWARF 4/5 and fix of issues related to -gdwarf-X options (f…
Browse files Browse the repository at this point in the history
…lang-compiler#92)

* Support for -gdwarf-5 option in Flang driver.

Summary:
  FLANG driver doesnt pass -gdwarf-4/5 to flang1 in form of xbits,
while it passes for -gdwarf-2/3
   -gdwarf-2 => -x 120 0x200
   -gdwarf-3 => -x 120 0x4000

Due to this -gdwarf-5 is never honored and default option -gdwarf-4
is taken.
    # flang -gdwarf-5 test.f90
    # llvm-dwarfdump a.out | grep version
    0x00000000: Compile Unit: length = 0x0000008e version = 0x0004

  Now 0x1000000/0x2000000 will be passed for -gdwarf-4/5
   -gdwarf-4 => -x 120 0x1000000
   -gdwarf-5 => -x 120 0x2000000

Testing:
  - GNU gdb fortran testsuite
  - check-llvm
  - check-debuginfo

* Flang doenst choose correct dwarf version when multiple -g/-gdwarfN mentioned

 Summary:
When multiple -g/-gdwarfN options are passed together at compile time,
flang chooses the least one. Clang/gfortran etc choose the last one.

-gdwarf-5 -gdwarf-3 => flang chooses 5 while clang/gfortran choose 3
-gdwarf-5 -g => flang choses the default while clang/gfortran choose 5

  Testing:
- check-llvm
- check-debuginfo

* Default dwarf version should be 4 for -g with flang

Currently flang dumps dwarf version 2 for -g and 4 for absence of -g

-------------------------
$ flang my.f90
$ llvm-dwarfdump a.out | grep version
0x00000000: Compile Unit: length = 0x0000003d version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x00000041)

$ flang -g my.f90
$ llvm-dwarfdump a.out | grep version
0x00000000: Compile Unit: length = 0x00000047 version = 0x0002 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x0000004b)
-------------------------

It should be 4 for -g as it is the case with clang.
  • Loading branch information
alokkrsharma authored and bryanpkc committed Sep 25, 2024
1 parent 4341503 commit bea6f6d
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions clang/lib/Driver/ToolChains/ClassicFlang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,28 +327,34 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
LowerCmdArgs.push_back("0x8");
}

// -g should produce DWARFv2
for (auto Arg : Args.filtered(options::OPT_g_Flag)) {
Arg->claim();
CommonCmdArgs.push_back("-x");
CommonCmdArgs.push_back("120");
CommonCmdArgs.push_back("0x200");
}
// Last argument of -g/-gdwarfX should be taken.
Arg *GArg = Args.getLastArg(options::OPT_g_Flag);
Arg *GDwarfArg = Args.getLastArg(options::OPT_gdwarf_2,
options::OPT_gdwarf_3,
options::OPT_gdwarf_4,
options::OPT_gdwarf_5);

if (GArg || GDwarfArg) {

for (auto Arg : Args.filtered(options::OPT_g_Flag, options::OPT_gdwarf_2,
options::OPT_gdwarf_3, options::OPT_gdwarf_4,
options::OPT_gdwarf_5)) {
Arg->claim();
}

// -gdwarf-2
for (auto Arg : Args.filtered(options::OPT_gdwarf_2)) {
Arg->claim();
CommonCmdArgs.push_back("-x");
CommonCmdArgs.push_back("120");
CommonCmdArgs.push_back("0x200");
}

// -gdwarf-3
for (auto Arg : Args.filtered(options::OPT_gdwarf_3)) {
Arg->claim();
CommonCmdArgs.push_back("-x");
CommonCmdArgs.push_back("120");
CommonCmdArgs.push_back("0x4000");
if (!GDwarfArg) // -g without -gdwarf-X produces default (DWARFv4)
CommonCmdArgs.push_back("0x1000000");
else if (GDwarfArg->getOption().matches(options::OPT_gdwarf_2)) // -gdwarf-2
CommonCmdArgs.push_back("0x200");
else if (GDwarfArg->getOption().matches(options::OPT_gdwarf_3)) // -gdwarf-3
CommonCmdArgs.push_back("0x4000");
else if (GDwarfArg->getOption().matches(options::OPT_gdwarf_4)) // -gdwarf-4
CommonCmdArgs.push_back("0x1000000");
else if (GDwarfArg->getOption().matches(options::OPT_gdwarf_5)) // -gdwarf-5
CommonCmdArgs.push_back("0x2000000");
}

// -Mipa has no effect
Expand Down

0 comments on commit bea6f6d

Please sign in to comment.