Skip to content

The /embed option does not allow for portable builds with line directive targets #69659

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

Open
jaredpar opened this issue Aug 22, 2023 · 0 comments
Assignees
Milestone

Comments

@jaredpar
Copy link
Member

jaredpar commented Aug 22, 2023

A lesser known effect of using /embed is that in addition to embedding source files into the PDB it will also embed the target of #line directives as well. For example:

// Program.cs
#line 42 "example.txt"
Console.WriteLite("Hello World");

When built with <EmbedAllSources>true</EmbedAllSources> will cause both Program.cs and _example.txt to be embedded into the PDB file and have entries in the document table.

image

The compiler discovers the file

  1. If it's a relative path then look relative to the file that included it.
  2. Else read the file as specified off of disk.

This feature makes C# code less portable from machine to machine. Essentially anytime a #line directive target is a full path that code cannot be easily ported between machines as a switch to use <EmbedAllSources> will result in the compiler reading the file off of disk at that location. At that point it ceases to be simply an entry in the document table but a physical disk dependency.

This is not a case that can be fixed with /pathmap option. While the target of #line directive does respect /pathmap when writing the entry into the PDB it does not change where the compiler looks on disk for the file. For example if we take the same Program.cs above and compile with a /pathmap entry it will be reflected in the custom document table but the compiler does not look in z:\data for the file.

<PathMap>C:\Users\jaredpar\temp\console=z:\data</PathMap>
image

As more components embrace <EmbedAllSources>true</EmbedAllSources> I worry this will impact the portability of C# builds because they become more dependent on the layout of the machine.

Think there are a few options we could consider for how to resolve this:

  1. Change the code that looks up #line directive targets to respect /pathmap. This is fairly easy to implement but it is a bit of a change to what /pathmap does. Today it only controls how paths are emitted into the PE / PDB, this would cause it to change how paths are ready.
  2. Change the format of /additionalfiles to allow a path to be specified with a file. Example allow for /additionalfiles:example.txt=C:\Users\jarepdar\temp\console\example.txt. All targets of #line should be passed to the compiler as /additionalfiles when /embed is used as they are inputs to the compiler. So this would just be fixing up the location of it a bit.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 22, 2023
@jaredpar jaredpar changed the title The /embed option does not respect /pathmap for line directive targets The /embed option does not allow for portable builds with line directive targets Aug 22, 2023
jaredpar added a commit to jaredpar/complog that referenced this issue Aug 23, 2023
This rounds out a few of the corner cases in `#line` directive support. 

The one issue that remains is when the user combines `/embed` and `#line` directives with full paths the resulting compilation is not 100% portable between machines. There is simply no way to redirect where the compiler attempts to read the target off of disk hence we're stuck with the original path. Filed [a bug](dotnet/roslyn#69659) with roslyn to track fixing this.
@jcouv jcouv added this to the 17.9 milestone Aug 24, 2023
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 24, 2023
@jaredpar jaredpar modified the milestones: 17.9, 17.10 Nov 1, 2023
@jaredpar jaredpar modified the milestones: 17.10, Backlog Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants