Skip to content

prelude: Only pass -Wa,--debug-prefix-map to GCC in remap_cwd - #1663

Closed
phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-remap-cwd-clang
Closed

phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-remap-cwd-clang

Conversation

@phr4nky

@phr4nky phr4nky commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

With cxx_toolchain(remap_cwd = True) and a Clang compiler, every compile fails: prelude/cxx/tools/remap_cwd.py appends -Wa,--debug-prefix-map=$PWD=., and the Clang driver rejects that option. This PR adds the option only for compiler_type = "gcc", the case it was added for.

Affected version

Checked at main 4b47e14 and in the latest release, 2026-11-15 (same remap_cwd.py, same Clang wrapping in compile.bzl). First bad commit: e0311d0 ("Enable DWARF debug info for hand-written assembly files"); remap_cwd.py from its parent compiles the same input.

Reproduction

printf 'int f(void){return 1;}\n' > a.c
python3 prelude/cxx/tools/remap_cwd.py clang -c a.c -o a.o -g; echo rc=$?

Expected

The compile succeeds and DW_AT_comp_dir is ., as it was before e0311d0.

Actual

clang: error: unsupported argument '--debug-prefix-map=<cwd>=.' to option '-Wa,'
rc=1

Seen with Apple clang 21.0.0 and clang 21.1.8 (also with --target=x86_64-linux-gnu), for .c, .s and .S inputs.

Analysis

compile.bzl wraps the compiler in remap_cwd for clang, clang_windows, clang_cl and gcc. e0311d0 added -Wa,--debug-prefix-map because GCC does not pass -ffile-prefix-map to the GNU assembler. Clang's integrated assembler honours -ffile-prefix-map: with only that flag, DW_AT_comp_dir is . for .c, .s and .S objects.

Patch

remap_cwd.py takes an optional leading --gnu-assembler and only then appends -Wa,--debug-prefix-map; compile.bzl passes it for compiler_type = "gcc". The Apple index-store path calls remap_cwd without it.

Test plan: with the patched script, Apple clang 21.0.0 and clang 21.1.8 compile .c, .s and .S with -g (rc 0, DW_AT_comp_dir is . in Mach-O and ELF objects); the old script fails on all of them. For GCC, the arguments the script passes to the compiler with --gnu-assembler are identical to the old script's. Not run: a GCC toolchain build, and a full buck2 build.

@meta-cla

meta-cla Bot commented Nov 25, 2026

Copy link
Copy Markdown

Hi @phr4nky!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Since e0311d0, remap_cwd.py appends `-Wa,--debug-prefix-map=$PWD=.`
for every compiler type it wraps. The Clang driver rejects that option
("unsupported argument '--debug-prefix-map=...' to option '-Wa,'"), so
every compile of a clang or clang_windows toolchain with
`remap_cwd = True` fails.

The option is only needed for GCC, which does not pass
-ffile-prefix-map on to the GNU assembler for .s/.S/.sx sources. Clang's
integrated assembler already honours -ffile-prefix-map. Add it only when
compile.bzl passes `--gnu-assembler`, which it does for compiler_type
"gcc"; the command GCC runs is unchanged.
@phr4nky
phr4nky force-pushed the fix-remap-cwd-clang branch from 62eff4a to 4eff7c9 Compare November 25, 2026 21:48
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 25, 2026
@meta-codesync

meta-codesync Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D134594657. (Because this pull request was imported automatically, there will not be any future comments.)

@dtolnay dtolnay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks!

@meta-codesync meta-codesync Bot closed this in 354c000 Nov 28, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 28, 2026
@meta-codesync

meta-codesync Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 354c000.

meta-codesync Bot pushed a commit to meta/buck2-prelude that referenced this pull request Nov 28, 2026
Summary:
With `cxx_toolchain(remap_cwd = True)` and a Clang compiler, every compile fails: `prelude/cxx/tools/remap_cwd.py` appends `-Wa,--debug-prefix-map=$PWD=.`, and the Clang driver rejects that option. This PR adds the option only for `compiler_type = "gcc"`, the case it was added for.

## Affected version

Checked at `main` 4b47e1430e and in the latest release, 2026-11-15 (same `remap_cwd.py`, same Clang wrapping in `compile.bzl`). First bad commit: e0311d0a0c ("Enable DWARF debug info for hand-written assembly files"); `remap_cwd.py` from its parent compiles the same input.

## Reproduction

```
printf 'int f(void){return 1;}\n' > a.c
python3 prelude/cxx/tools/remap_cwd.py clang -c a.c -o a.o -g; echo rc=$?
```

## Expected

The compile succeeds and `DW_AT_comp_dir` is `.`, as it was before e0311d0a0c.

## Actual

```
clang: error: unsupported argument '--debug-prefix-map=<cwd>=.' to option '-Wa,'
rc=1
```

Seen with Apple clang 21.0.0 and clang 21.1.8 (also with `--target=x86_64-linux-gnu`), for `.c`, `.s` and `.S` inputs.

## Analysis

`compile.bzl` wraps the compiler in `remap_cwd` for `clang`, `clang_windows`, `clang_cl` and `gcc`. e0311d0a0c added `-Wa,--debug-prefix-map` because GCC does not pass `-ffile-prefix-map` to the GNU assembler. Clang's integrated assembler honours `-ffile-prefix-map`: with only that flag, `DW_AT_comp_dir` is `.` for `.c`, `.s` and `.S` objects.

## Patch

`remap_cwd.py` takes an optional leading `--gnu-assembler` and only then appends `-Wa,--debug-prefix-map`; `compile.bzl` passes it for `compiler_type = "gcc"`. The Apple index-store path calls `remap_cwd` without it.

X-link: meta/buck2#1663

Reviewed By: dtolnay

Differential Revision: D134594657

fbshipit-source-id: 815723edd632a26c3cee7ef50ad7d03965457317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants