Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT ignores PdbFile compiler option #78337

Closed
dmex opened this issue Nov 14, 2022 · 7 comments
Closed

NativeAOT ignores PdbFile compiler option #78337

dmex opened this issue Nov 14, 2022 · 7 comments

Comments

@dmex
Copy link

dmex commented Nov 14, 2022

Hello,

When compiling projects with <PublishAot>true</PublishAot> and <PdbFile>abcd.pdb</PdbFile> there are two invalid PDBs created in the directory and the wrong filename is added to the PE debug directory.

We use the PdbFile option to strip some of the directory path from the PDB filename. The option is documented here:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/advanced#pdbfile

Duplicate PDBs (the first one is invalid):

image

Adding true results in an incorrect filename in the PE debug directory:

image

Removing <PublishAot>true</PublishAot> results in the correct path:

image

Reproduction Steps

  1. Create project
  2. Add <PublishAot>true</PublishAot> and <PdbFile>abcd.pdb</PdbFile>
  3. Publish project

Expected behavior

Value from PdbFile field in .csproj is used instead of the actual filename.

Actual behavior

Real filename is used instead of the PdbFile option.

Regression?

The PdbFile option works in all other versions of .NET except when using <PublishAot>true</PublishAot>

Known Workarounds

No response

Configuration

.NET 7.0 (x64)

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 14, 2022
@ghost
Copy link

ghost commented Nov 14, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Hello,

When compiling projects with <PublishAot>true</PublishAot> and <PdbFile>abcd.pdb</PdbFile> there are two invalid PDBs created in the directory and the wrong filename is added to the PE debug directory.

We use the PdbFile option to strip some of the directory path from the PDB filename. The option is documented here:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/advanced#pdbfile

Duplicate PDBs (the first one is invalid):

image

Adding true results in an incorrect filename in the PE debug directory:

image

Removing <PublishAot>true</PublishAot> results in the correct path:

image

Reproduction Steps

  1. Create project
  2. Add <PublishAot>true</PublishAot> and <PdbFile>abcd.pdb</PdbFile>
  3. Publish project

Expected behavior

Value from PdbFile field in .csproj is used instead of the actual filename.

Actual behavior

Real filename is used instead of the PdbFile option.

Regression?

The PdbFile option works in all other versions of .NET except when using <PublishAot>true</PublishAot>

Known Workarounds

No response

Configuration

.NET 7.0 (x64)

Other information

No response

Author: dmex
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@dmex
Copy link
Author

dmex commented Nov 14, 2022

PublishAot also ignores the alignment option:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/advanced#filealignment

image

<PublishAot>true</PublishAot> has the wrong FileAlignment:

image

<PublishAot>false</PublishAot> has the correct FileAlignment:

image

@jkotas
Copy link
Member

jkotas commented Nov 14, 2022

These options are meant to control properties of managed binaries produced by C# compiler.

Controlling properties of the native binary produced by PublishAot is better done by passing extra arguments to the native linker, for example:

  <ItemGroup>
    <LinkerArg Include="/FILEALIGN:0x1000" />
  </ItemGroup>

@dmex
Copy link
Author

dmex commented Nov 15, 2022

These options are meant to control properties of managed binaries

We've been some of these options for a few years. I couldn't find anything about compatibility with PublishAot and just assumed it uses the same properties.

Controlling properties of the native binary produced by PublishAot is better done by passing extra arguments to the native linker

The LinkerArg option is exactly what we needed... thank you🥳

  • /PDBALTPATH:%_PDB% correctly fixes the PdbFile name.
  • /FILEALIGN:0x1000 correctly sets the file alignment.

LinkerArg really needs to be documented. I tried using the same linker command line from our native C/C++ projects and everything works except for BREPRO:

  <ItemGroup>
    <LinkerArg Include="/BREPRO /DEPENDENTLOADFLAG:0x800 /PDBALTPATH:%_PDB% /FILEALIGN:0x1000" />
  </ItemGroup>

EDIT: I found an existing issue https://github.com/dotnet/runtimelab/issues/1632

@MichalStrehovsky
Copy link
Member

Reproducible builds are tracked in #73931 (comment). Assuming you also specified <Determinisitc>true</Deterministic>, the output obj file should be the same. But then link.exe will mess it up. The VC++ doesn't yet have a switch that we can use (there's /EXPERIMENTAL:DETERMINISTIC but it didn't produce the same bits in my testing and the VC++ team said the work is not finished yet so I didn't poke into it more).

@dmex
Copy link
Author

dmex commented Nov 22, 2022

it didn't produce the same bits in my testing

@MichalStrehovsky

I'm not sure if it's the linker, IlCompiler or MSBuild messing up the deterministic build (or combination of all three). I've modified your ZeroSharp project and it's deterministic when compiled from the bat script. I'll update the other thread with the sample.

Controlling properties of the native binary produced by PublishAot is better done by passing extra arguments to the native linker

@jkotas The LinkerArg flags resolved this issue so I'll close it. Thanks for the help :)

@dmex dmex closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants