Skip to content

cc_binary's linkopts should expand labels used with "-Wl," #4440

Closed

Description

@pmuetschard

Description of the problem / feature request:

Passing options to the linker requires -Wl,<option>. To pass an option with a value, one can do one of the following:

  • -Wl,<option> -Wl,<value>
  • -Wl,<option>=<value>
  • -Wl,<option>,<value>

Bazel's cc_binary rule, however, only expands labels in the linkopts field if the string "does not start with $ or -". This makes it impossible to pass a file that is a label as a value to a link option.

For example, to pass a linker version script, one would need to cause the following flag passed to gcc:
-Wl,--version-script,<script>
However this is impossible:
linkopts = ["-Wl,--version-script,", "script.ldscript"] although performing label expansion, passes the script.ldscript file as a separate argument, which gets ignored.
linkopts = ["-Wl,--version-script", "-Wl,script.ldscript"] doesn't do label expansion, nor does it if using any of the other formats, and $(location script.ldscript) is not allowed.

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

cc_binary(
  ...
  deps = [..., "script.ldscript"],
  linkopts = ["-Wl,--version-script,script.ldscript"]
  ...
)

What operating system are you running Bazel on?

Linux, but this is likely present on all OSs.

What's the output of bazel info release?

0.9.0, but also TOTT

Activity

  1. pmuetschard commented on Jan 12, 2018

    @pmuetschard
    ContributorAuthor

    Oops, never mind ["-Wl,--version-script,", "script.ldscript"] actually works. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions