Register
c[ode]clap»Forums»Expected Date for Windows DWARF Support
Sara
12 posts
Expected Date for Windows DWARF Support
11 months, 3 weeks ago Edited by Sara on Dec. 18, 2018, 9:28 a.m.
Hi there.
Just wondering if you could give a rough estimate as to when the windows version will support the DWARF format.
I try to avoid microsoft products as much as possible and so prefer to use clang/mingw64 which doesn't support PDB generation.
Thanks.
Mārtiņš Možeiko
1989 posts / 1 project
Expected Date for Windows DWARF Support
11 months, 3 weeks ago Edited by Mārtiņš Možeiko on Dec. 18, 2018, 10:02 a.m.
Clang supports pdb generation just fine. For example, to use it with lld.exe from mingw-w64-x86_64-lld package (in msys2) do this:

1
clang.exe -fuse-ld=lld.exe -g -gcodeview -Wl,/debug,/pdb:test.pdb -o test.exe test.c


This will create test.pdb next to test.exe which will work in Visual Studio just fine.

If you are using clang binary build from offical website then replace lld.exe with lld-link.exe.
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
11 months, 3 weeks ago Edited by spx on Dec. 18, 2018, 7:24 p.m.
mmozeiko
Clang supports pdb generation just fine. For example, to use it with lld.exe from mingw-w64-x86_64-lld package (in msys2) do this:

1
clang.exe -fuse-ld=lld.exe -g -gcodeview -Wl,/debug,/pdb:test.pdb -o test.exe test.c


This will create test.pdb next to test.exe which will work in Visual Studio just fine.

If you are using clang binary build from offical website then replace lld.exe with lld-link.exe.

nice, thanks for posting the command line. I did quickly try out clang in the past and never got it to emit line information. Seems it works when invoked this way.

SaraPanda
Hi there.
Just wondering if you could give a rough estimate as to when the windows version will support the DWARF format.
I try to avoid microsoft products as much as possible and so prefer to use clang/mingw64 which doesn't support PDB generation.
Thanks.

Sorry I've not set a target version for this. But maybe the suggestion from Martins could be an option for you. I haven't yet tested codeclap with clang generated debug information but that is targeted for 0.9.x.
Sara
12 posts
Expected Date for Windows DWARF Support
11 months, 3 weeks ago
mmozeiko
Clang supports pdb generation just fine. For example, to use it with lld.exe from mingw-w64-x86_64-lld package (in msys2) do this:

1
clang.exe -fuse-ld=lld.exe -g -gcodeview -Wl,/debug,/pdb:test.pdb -o test.exe test.c


This will create test.pdb next to test.exe which will work in Visual Studio just fine.

If you are using clang binary build from offical website then replace lld.exe with lld-link.exe.


Hi Martins.
Thank you for your command line invocation.
Previously, I had not given any arguments to linker, simply doing:
1
clang.exe -gcodeview test.c -o test.exe

This did not generate a pdb file.
However, your invocation works!
Thanks again!
Mārtiņš Možeiko
1989 posts / 1 project
Expected Date for Windows DWARF Support
11 months, 3 weeks ago
Yeah, by default clang uses ld.exe which is linker from binutils. And that one knows only dwarf, no codeview format. That's why you should use lld, it is also faster.

Alternative is to use clang-cl.exe. That automatically uses lld-link.exe by default to be compatible with cl.exe, but that will require to use cl.exe style arguments:
1
clang-cl.exe /Fetest.exe /Zi test.c


spx
I did quickly try out clang in the past and never got it to emit line information.

It emits not only line information but full symbol table - for global and local variables. Basically everything to debug even with Visual Studio, everything works - stepping, breakpoints, watching variable values, etc...
Sara
12 posts
Expected Date for Windows DWARF Support
10 months, 2 weeks ago
Currently I have tried invoking:
1
clang.exe -target x86_64-windows-gnu -fuse-ld=lld.exe -gcodeview -Wl,/debug,/pdb:example.pdb example.c -o example.exe

However when I open in codeclap I get an error: example.exe is not a 64bit PE file
By running:
1
file example.exe

I get 'PE32+ executable (console) x86-64, for MS Windows', so to my understanding it should work.
Am I doing something wrong here?
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 2 weeks ago Edited by spx on Jan. 25, 2019, 12:30 a.m.
I am pretty certain that there are at least a few issues with clang generated executables (on Windows) that need fixing which should happen for the next build. I have quickly checked a very simple test program which executes but codeclap is not able to find line information (however MSVC does). Misremembered the command line at first, but lld-link.exe worked in the end.

How did you install clang? I've simply downloaded the pre-built setup from http://releases.llvm.org/download.html

Using -target x86_64-windows-gnu I get
1
lld: error: unable to find library -lmingw32

Which makes sense i guess. Are you using msys/mingw clang packages or did you compile it yourself?

btw. DWARF support on windows will probably happen some time around 1.2/1.3

just to be sure, have you checked that the path to the exe is correct? Best is dragging the file onto the configuration window to avoid typos.
Sara
12 posts
Expected Date for Windows DWARF Support
10 months, 2 weeks ago
I too downloaded clang from http://releases.llvm.org/download.html
I downloaded mingw from https://sourceforge.net/projects/mingw-w64/
The
1
-target x86_64-windows-gnu
was to make clang use mingw headers instead of msvc.
I dragged the executable on codeclap 0.8.3 and got the same error as before.
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 2 weeks ago
Thanks for the clarification. When explicitly checking clang compatibility I will make sure to also try that clang target and hopefully will just run into the same error.
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 1 week ago
Still having issues here :(

I tried using the smallest program one can imagine
1
2
3
4
int main(int argc, char **argv)
{
	return(0);
}


Just to be sure I tried the usual msvc target
1
clang.exe -fuse-ld=lld-link.exe -g -gcodeview -Wl,/debug,/pdb:example.pdb example.c -o example.exe

(which uses x86_64-pc-windows-msvc)
This compiles, executes and seems to have correct debug information.

I then installed "x86_64-8.1.0-posix-seh-rt_v6-rev0" using mingw-w64-install.exe and from a mingw terminal compiled with
1
clang.exe -target x86_64-windows-gnu -fuse-ld=lld.exe -g -gcodeview -Wl,/debug,/pdb:example.pdb example.c -o example.exe

This creates an exe which faults on startup in mainCRTStartup (__security_init_cookie to be precise).

In total I tried
x86_64-8.1.0-posix-seh-rt_v6-rev0
x86_64-7.3.0-posix-seh-rt_v5-rev0
x86_64-8.1.0-win32-seh-rt_v6-rev0
x86_64-8.1.0-win32-sjlj-rt_v6-rev0
without any luck producing a functional program.

So I am wondering, is there something obvious simple I am doing wrong here?
Sara
12 posts
Expected Date for Windows DWARF Support
10 months, 1 week ago
I also had issues using lld linker from LLVM, rather than the default ld from binutils.
For example, this works:
1
clang.exe -target x86_64-windows-gnu example.c -o example.exe

However, this faults:
1
clang.exe -fuse-ld=lld.exe -target x86_64-windows-gnu example.c -o example.exe

It seems to be an issue using lld with mingw.
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 1 week ago
SaraPanda
I also had issues using lld linker from LLVM, rather than the default ld from binutils.
For example, this works:
1
clang.exe -target x86_64-windows-gnu example.c -o example.exe

However, this faults:
1
clang.exe -fuse-ld=lld.exe -target x86_64-windows-gnu example.c -o example.exe

It seems to be an issue using lld with mingw.


Yes that seems to be the case. Omitting lld.exe produces a working program.

That brings me to
a) At least my simple test program is run by codeclap without complaining
and I think more important
b) ld.exe refuses both /debug and /pdb so no debug information?
Mārtiņš Možeiko
1989 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 1 week ago
ld.exe is from binutils. Binutils does not know anything about MSVC linker arguments or generating .pdb debug info. To use MSVC style linker arguments you need to use lld which understands both - MSVC linker style and binutils syle arguments. And is capable of generating .pdb file not only dwarf.
spx
119 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 1 week ago Edited by spx on Jan. 26, 2019, 11:02 p.m.
mmozeiko
ld.exe is from binutils. Binutils does not know anything about MSVC linker arguments or generating .pdb debug info. To use MSVC style linker arguments you need to use lld which understands both - MSVC linker style and binutils syle arguments. And is capable of generating .pdb file not only dwarf.


That's what i figured and of course is logical but that also means that I currently don't know a way to use x86_64-windows-gnu and produce a working program and pdb debug information at the same time.
Mārtiņš Možeiko
1989 posts / 1 project
Expected Date for Windows DWARF Support
10 months, 1 week ago
With clang from msys2 project this works for me:
1
clang.exe -fuse-ld=lld -target x86_64-windows-gnu -g -gcodeview -Wl,/debug,/pdb:test.pdb test.c -o test.exe


Here are versions of binaries I used:
1
2
3
4
5
6
7
8
9
C:\msys2\mingw64\bin>clang --version
clang version 7.0.1 (tags/RELEASE_701/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\msys2\mingw64\bin

C:\msys2\mingw64\bin>lld --version
lld is a generic driver.
Invoke ld.lld (Unix), ld64.lld (macOS), lld-link (Windows), wasm-lld (WebAssembly) instead