Skip to content

Clang linker script support - incorrect argument #127183

@boozook

Description

@boozook

Using clang as linker with any custom target (spec in json) that contains linker-script (field link-script) produces invocation like

# clang or cc, or gcc
"clang" "--script" "/path/to/link-script/exported/from/my-target-json"

But clang doesn't support --script and returns error clang: error: unsupported option '--script'.
Instead of that, according documentation, we just need to pass it with -T,
e.g.: -T/path/to/link-script.ld.

How to reproduce:

  1. Prepare spec json file for your custom target. It could be anything, just one thing matter - add link-script field. Something like this:

    {
      "llvm-target": "Your-HOST-target",
      "link-script": "ENTRY(main)",
      "linker": "clang"
    }
  2. Compile anything targeting to your custom target, e.g.: --target=./your-target.json

Expected result:
Clang should be invoked with -T<link-script> instead of --script <link-script>.

I can reproduce with target-spec with explicitly set linker as clang, gcc, arm-none-eabi-gcc and cc.

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (72fdf913c 2024-06-05)
binary: rustc
commit-hash: 72fdf913c53dd0e75313ba83e4aa80df3f6e2871
commit-date: 2024-06-05
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions