https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127417

            Bug ID: 127417
           Summary: GNAT 16.2 crashes compiling binder output file with
                    CodeView debug switch on trivial code
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cthowie at netzero dot net
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

PLATFORM: GCC, GNAT 16.2 toolchain on Windows 10 Intel x64 using MSYS2
          gprbuild version 2026.0.0 (20260907)
          Clang lld.exe Linker version 22.1.8.

ISSUE #1: the use of the "-gcodeview" compiler switch crashes GNAT in trivial
test case submitted below.

ISSUE #2: attempts to custom-compile GNAT's gprbind output Ada file (called
b__testhello.adb in the test case below) failed to interpret the GPR project
file specification as one would expect. This doesn't fix the compiler crash, it
just seems like another issue/bug.

BACKGROUND TO THE BUG DETECTION 
The goal is to use the Clang "lld" linker when using GNAT toolchain on Windows
on the MSYS2 platform. This is because the GNU "ld" linker currently has a
filed bugreport regarding failure to output a "PDB" debugger file correctly, so
I've been advised to use Clang "lld". I've successfully got Clang "lld" working
on GCC "C Language" output on Windows. In testing for trivial Ada code
compilation with GNAT using "lld" on the backend, I hit the issues reported
here.

Before we get to the submitted appended trivial code and GPR file for GNAT
input, here's a description of the compiler crash reproduction steps:

1) Set up and save the "testhello.adb" and "TestHello.gpr" files whose contents
are pasted below.

2) Run the command "gprbuild -v -PTestHello.gpr" and GNAT will likely crash
with the feedback pasted later below for reference.

3) Cause of the crash: the use of "-gcodeview" switch in Compiler settings
inside the GPR file, specifically if the switch is used to compile binder
output file "b__testhello.adb", whereas the compiler manages to compile
"testhello.adb" with "-gcodeview" successfully.

4) To get successful compilation and linking of everything so as to build
"TestHello.exe", change this line of code in the GPR file:
   FROM: for Switches ("testhello.adb") use Ada_Codeview;
     TO: for Switches ("testhello.adb") use Ada;

That change will remove the "-gcodeview" switch, which we can see by running
gprbuild with "-v" verbose feedback switch. This prevents GNAT/GCC from
crashing, and TestHello.exe gets output from Clang "lld" linker successfully,
including a TestHello.pdf file.

The second issue I'm reporting is possibly a bug: 

As observed when playing with the above issue:
a) GNAT can compile "testhello.adb" with switch "-gcodeview"
b) GNAT cannot, however, compile "b_testhello.adb" with that switch. It crashes
with the bug detection output pasted below.

I've tried to get the gprbuild process to compile the gprbind output
"b__testhello.adb" file using custom switches in the GPR file that omit the
"-gcodeview" switch but leave it in place for "testhello.adb". However,
attempts in the GPR configuration to use:
   for Switches ("b~*.adb") use Ada;
or
   for Switches ("b__testhello.adb") use Ada;
somehow cause the binder output to be compiled with the problematic
"-gcodeview" switch if we permit that switch for compiling "testhello.adb":
   for Switches ("testhello.adb") use Ada_Codeview;

This means there may be some mapping/configuration issue in GPR processing
whereby switches for the project's "main" file, here "testhello.adb" are
somehow taking precedence over attempts to bind different switches for use when
compiling the gprbind output Ada code.


--- HERE'S ADA CODE FOR TEST FILE: testhello.adb

with Ada.Text_IO;
procedure TestHello is
begin
   Ada.Text_IO.Put_Line ("Hello!");
end TestHello;


--- HERE'S GNAT GPR PROJECT FILE: TestHello.gpr

project TestHello is
   for Languages use ("Ada");
   for Main use ("testhello.adb");
   package Builder is
      for Executable ("testhello.adb") use "TestHello";
   end Builder;
   package Compiler is
      Core := ("-m64", "-mconsole", "-O2");
      Clang_lld_pdb := ("-g", "-fuse-ld=lld");
      Ada := Core & Clang_lld_pdb;
      Ada_Codeview := Ada & "-gcodeview";
      for Switches ("Ada") use Ada;
      for Switches ("testhello.adb") use Ada_Codeview;
      for Switches ("b~*.adb") use Ada;
   end Compiler;   
   package Linker is            
       for Default_Switches ("Ada") use 
          ("-fuse-ld=lld", 
           "-Wl,-v",  --verbose feedback for linker to confirm lld running
           "-Wl,-pdb=TestHello.pdb");
    end Linker;    
end TestHello;


---  HERE'S THE PERTITENT CRASH REPORT OUTPUT BY GNAT WHEN USING -gcodeview
     SWITCH AS DESCRIBED ABOVE:

gcc -c -x ada -gnatA -c -gnatA -gnatWb -gnatiw -gnatws -O2 -m64 -mconsole -g
-fuse-ld=lld -gcodeview -mtune=generic -march=nocona b__testhe
llo.adb -o b__testhello.o
+===========================GNAT BUG DETECTED==============================+
| 16.2.0 (x86_64-w64-mingw32) in AT_unsigned, at dwarf2out.cc:4599         |
| Error detected around
C:/msys64/ucrt64/lib/gcc/x86_64-w64-mingw32/16.2.0/adainclude/s-secsta.ads:279:9|
| Compiling b__testhello.adb                                               |
| Please submit a bug report; see https://gcc.gnu.org/bugs/ .              |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact command that you entered.                              |
| Also include sources listed below.                                       |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

b__testhello.adb
b__testhello.ads
  • [Bug ada/127417] New: GNAT 16.2 ... cthowie at netzero dot net via Gcc-bugs

Reply via email to