Skip to content

gcc: amend __FILE__ mangling patch to only affect -fmacro-prefix-map=#285662

Merged
marsam merged 1 commit intoNixOS:stagingfrom
trofi:gcc-amend-__FILE__-just-for-macro-prefix
Feb 19, 2024
Merged

gcc: amend __FILE__ mangling patch to only affect -fmacro-prefix-map=#285662
marsam merged 1 commit intoNixOS:stagingfrom
trofi:gcc-amend-__FILE__-just-for-macro-prefix

Conversation

@trofi
Copy link
Contributor

@trofi trofi commented Feb 1, 2024

THe initial intent of the change was to only affect -fmacro-prefix-map= option.

Due to the bug of if (maps == macro_prefix_maps) condition of initial setting all three of:

static file_prefix_map *macro_prefix_maps; /* -fmacro-prefix-map  */
static file_prefix_map *debug_prefix_maps; /* -fdebug-prefix-map  */
static file_prefix_map *profile_prefix_maps; /* -fprofile-prefix-map  */

matches the comparison and applied the mangling (as long as on options were passed into those before).

As a result not only (intended) __FILE__ embedding happened in .data section, but also (unintended) debugging symbols (-fdebug-prefix-map) and profiling data (-fprofile-prefix-map) were broken by mangling.

The patch update fixes it by explicitly passing a boolean that controls the mangling in a single call site relevant to -fmacro-prefix-map.

While at it fixed int / size_t mismatch that caused build failure on upcoming gcc-14.

Tested as:

  • nix still has no nlohmann_json retention
  • gdb can now resolve stdc++ debugging symbols in templates
  • --coverage has working source file paths

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Feb 2, 2024
Copy link
Member

@symphorien symphorien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message of the patch mentions debug symbols but as far as I understand this is now outdated.

THe initial intent of the change was to only affect
`-fmacro-prefix-map=` option.

Due to the bug of `if (maps == macro_prefix_maps)` condition of initial
setting all three of:

    static file_prefix_map *macro_prefix_maps; /* -fmacro-prefix-map  */
    static file_prefix_map *debug_prefix_maps; /* -fdebug-prefix-map  */
    static file_prefix_map *profile_prefix_maps; /* -fprofile-prefix-map  */

matches the comparison and applied the mangling (as long as on options
were passed into those before).

As a result not only (intended) `__FILE__` embedding happened in `.data`
section, but also (unintended) debugging symbols (`-fdebug-prefix-map`)
and profiling data (`-fprofile-prefix-map`) were broken by mangling.

The patch update fixes it by explicitly passing a boolean that controls
the mangling in a single call site relevant to `-fmacro-prefix-map`.

While at it fixed `int / size_t` mismatch that caused build failure on
upcoming `gcc-14`.

Tested as:

- `nix` still has no `nlohmann_json` retention
- `gdb` can now resolve `stdc++` debugging symbols in templates
- `--coverage` has working source file paths
@trofi trofi force-pushed the gcc-amend-__FILE__-just-for-macro-prefix branch from 5c72622 to be41f86 Compare February 2, 2024 21:00
@trofi
Copy link
Contributor Author

trofi commented Feb 2, 2024

The message of the patch mentions debug symbols but as far as I understand this is now outdated.

Good catch! Dropped mention of debugging symbols.

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 3, 2024
@marsam marsam merged commit c7cd3aa into NixOS:staging Feb 19, 2024
@trofi trofi deleted the gcc-amend-__FILE__-just-for-macro-prefix branch February 19, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants