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

linker_param_file only added to command line if it starts with "@" #18074

Closed
Taldoras opened this issue Apr 13, 2023 · 5 comments
Closed

linker_param_file only added to command line if it starts with "@" #18074

Taldoras opened this issue Apr 13, 2023 · 5 comments
Assignees
Labels
area-Windows Windows-specific issues and feature requests P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug

Comments

@Taldoras
Copy link

Description of the bug:

The tasking compiler for c/c++ requires a different format to pass a param file (--options-file=%{linker_param_file} or -f %{linker_param_file}.
When I add a custom linker_param_file_feature to a custom cc_toolchain_config, it will only be added to the command line if the flag starts with "@".

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create a custom cc_toolchain_config and add a custom "linker_param_file" feature.
Add a flag with ["--option-file=%{linker_param_file}"].
Build a c/cpp file with the custom toolchain configured. When the linker is being called, the flag wont be added.
Now, add an @ at the beginning of the flag (e.g. ["@ --option-file=%{linker_param_file}"].) and build again. The flag should now be shown in the command line.

Which operating system are you running Bazel on?

Windows 11

What is the output of bazel info release?

release 6.1.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@Pavank1992 Pavank1992 added team-Rules-CPP Issues for C++ rules and removed type: bug labels Apr 13, 2023
@Pavank1992 Pavank1992 added type: bug area-Windows Windows-specific issues and feature requests labels Apr 13, 2023
@buildbreaker2021 buildbreaker2021 added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Apr 25, 2023
@comius comius self-assigned this Dec 28, 2023
@brentleyjones
Copy link
Contributor

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jan 5, 2024
@iancha1992
Copy link
Member

@bazel-io fork 6.5.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jan 5, 2024
@iancha1992
Copy link
Member

@bazel-io fork 7.1.0

@meteorcloudy
Copy link
Member

@comius Can you help backport the fixes?

comius added a commit to comius/bazel that referenced this issue Feb 7, 2024
Before `getRawLinkArgv` generated a joint/mixed command line, which was composed of 'linker executable' (first argument) and regular arguments. Reference to 'param file' was mixed into the regular arguments.

Linker command line is long, too long. To fix this, most of linkers are called like `linker @param.file`. The long list of arguments is hidden in `param.file`.

`splitCommandline` used `isLikelyParamFile` to filter out what that `param file` reference was. The result were 2 command lines. First one with 'linker executable' and reference to 'param file' and second command line contained regular arguments, that are written to param file.

Generate those 2 command lines directly. First one is returned by `getCommandLine` and second one (the regular arguments) by `getParamCommandLine`

Param file reference is formatted using `linker_param_file` feature, using `%{linker_param_file}` substitution. In most cases this is just `@%{linker_param_file}`, but there are some linkers that need different formatting.

This change is also needed for Starlarkification of CppLinkAction, because the Starlark interface requires to set how param file is formatted, directly. See https://bazel.build/rules/lib/builtins/Args#use_param_file

Fixes: bazelbuild#18074
PiperOrigin-RevId: 595912823
Change-Id: I54b36113d87f975af63341b2dec17b2f861c0ffa
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

10 participants