sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

Rust cross compiling using MinGW

Open xdm67x opened this issue 2 years ago • 13 comments

Hi,

I cross compile my code from Mac OS to Windows using MinGW and the target x86_64-pc-windows-gnu. I use the RUSTFLAGS="-g -C opt-level=3" to generate debug information when being in release mode. Then, I run the command,

x86_64-w64-mingw32-objcopy --only-keep-debug library.dll library.debug
x86_64-w64-mingw32-objcopy --strip-debug library.dll
x86_64-w64-mingw32-objcopy --add-gnu-debuglink=library.debug library.dll

After that, I use to have the library.debug file containing all the debug information but when I want to check if it is usable by Sentry using sentry-cli difutil check library.debug I have this result,

Debug Info File Check
  Type: pe
  Contained debug identifiers:
  Contained debug information:
    > none
  Usable: no (missing debug identifier, likely stripped)

Do you know, what I can do to get the debug information send to Sentry correctly to be able to map it with my library?

xdm67x avatar Jun 22 '23 13:06 xdm67x

I believe this is because we do not (yet) support DWARF in PE. If you want to use DWARF as debug format, it has to be in an ELF or Mach-O file. Otherwise, Windows Debug Info usually is in PDB format. I’m not too familiar with MinGW myself, but you would have to teach it to output dwarf in an elf file I presume.

Swatinem avatar Jun 22 '23 13:06 Swatinem

Also when I use the .dll file without stripping I got this result with the sentry-cli command,

Debug Info File Check
  Type: pe library
  Contained debug identifiers:
    > Debug ID: 00000000-0000-0000-0000-000000000000
      Code ID:  6494408637f90000
      Arch:     x86_64
  Contained debug information:
    > symtab, debug, unwind
  Usable: no (missing debug identifier, likely stripped)

I have the feature debug-images.

xdm67x avatar Jun 22 '23 13:06 xdm67x

Another problem here is also that the file is missing a DebugId.

Swatinem avatar Jun 22 '23 15:06 Swatinem

Yep, but why is it missing? I only cross compile using Rust and MinGW.

xdm67x avatar Jun 22 '23 15:06 xdm67x

The issue is similar with https://github.com/getsentry/sentry-rust/issues/354, wdyt?

xdm67x avatar Jun 23 '23 13:06 xdm67x

Any news, please?

xdm67x avatar Jun 27 '23 08:06 xdm67x

It might have something to do with the mingw tools. The issue you linked above is using cv2pdb to create a pdb file, which appears to be usable.

Another member of our team is trying to reproduce this.

Swatinem avatar Jun 27 '23 11:06 Swatinem

Ok, thx, if you need any help please keep in touch with me.

xdm67x avatar Jun 27 '23 14:06 xdm67x

The team has had a look at this and we were able to reproduce this, though did not find a proper way to make this work.

In general we appreciate community contributions related to MinGW very much, but we do not actively support it, neither for the native SDK nor for Rust.

MinGW in general is a very broad target with a diverse set of tools. In general we need debug files/formats in their "native" container type. Which means that PDB needs to be in a PDB file, and DWARF needs to be in either an ELF or Mach-O container. We do support using ELF/DWARF debug info in combination with a PE executable though.

Swatinem avatar Jun 29 '23 08:06 Swatinem

So you mean I need to convert the dwarf debug info to PDB?

xdm67x avatar Jul 04 '23 11:07 xdm67x

Either convert the whole debuginfo to pdb, or just make sure that the DWARF is in a container format that is appropriate for it, like ELF.

Swatinem avatar Jul 04 '23 12:07 Swatinem

Is it normal that after I used the ELF debug information format, I'm also missing the Debug ID?

Debug Info File Check
  Type: elf debug companion
  Contained debug identifiers:
    > Debug ID: 00000000-0000-0000-0000-000000000000
      Arch:     x86_64
  Contained debug information:
    > symtab, debug, unwind
  Usable: no (missing debug identifier, likely stripped)

xdm67x avatar Sep 19 '23 09:09 xdm67x

I don't know how to read 😄 , everything is written here, https://docs.sentry.io/platforms/native/guides/minidumps/data-management/debug-files/identifiers/#gnu-build-identifiers.

But after doing that, I got the identifier for the executable, such as,

Debug Info File Check
  Type: pe library
  Contained debug identifiers:
    > Debug ID: c8627651-8de4-7cb7-f6ba-dc6faa7317b0-1
      Code ID:  65099b543f203000
      Arch:     x86_64
  Contained debug information:
    > symtab, debug, unwind
  Usable: yes

But when I used the command x86_64-w64-mingw32-objcopy --only-keep-debug -O elf64-x86-64 mylib.dll mylib.dbg, I lost the debug identifier.

xdm67x avatar Sep 19 '23 13:09 xdm67x