Skip to content

cmd/link: linkerFlagSupported drops trailing arguments from multi-word CC when probing linker flags #81163

Open

Description

@jkrishmys

Go version

go version go1.28-devel_2117d7cf9f Wed Aug 26 21:30:33 2026 -0700 linux/ppc64le

Output of go env in your module/workspace:

GOARCH='ppc64le'
GOHOSTARCH='ppc64le'
GOOS='linux'
CGO_ENABLED='1'
CC='gcc'
CXX='g++'
GOPPC64='power10'
GOVERSION='go1.28-devel_2117d7cf9f Wed Aug 26 21:30:33 2026 -0700'
GOEXPERIMENT=''
GOFLAGS=''
GOTOOLCHAIN='local'
clang version 21.1.8 (Red Hat, Inc. 21.1.8-2.el9)
Target: ppc64le-redhat-linux-gnu

What did you do?

This was first observed in the Go CI/CD builder on ppc64le POWER10, and I then reproduced it locally on a POWER10 system using current Go master. Link

On a ppc64le POWER10 system, I checked out current Go master and ran the full test suite with GOPPC64=power10.

The failure reproduces locally in:

TestScript/cgo_path_space_quote

I then reproduced the test directly with:

GOPPC64=power10 ./bin/go test cmd/go \
    -run='TestScript/cgo_path_space_quote' \
    -count=1 -v

The test sets CC to a wrapper executable whose path contains spaces, followed by clang, for example:

"/tmp/.../program files/which cc" clang

I also verified independently that the compiler supports the Power10 flag:

clang -m64 -mcpu=power10 /tmp/p10.c -o /tmp/p10
echo $?

which returns:

0

What did you see happen?

TestScript/cgo_path_space_quote fails during go run . with:

# test
.../pkg/tool/linux_ppc64le/link: The external toolchain does not support -mcpu=power10. This is required to externally link GOPPC64 >= power10

The test itself successfully preserves the multi-word CC value:

"/tmp/.../program files/which cc" clang

To inspect the Power10 capability probe, I temporarily instrumented linkerFlagSupported. The failing probe executed:

DEBUG linkerFlagSupported: flag="-mcpu=power10"
cmd=["/tmp/.../program files/which cc"
     "-m64"
     "-o" "..."
     "-mcpu=power10"
     ".../trivial.c"]

The trailing clang argument from CC is missing.

The corresponding call site passes only argv[0]:

linkerFlagSupported(ctxt.Arch, argv[0], "", "-mcpu=power10")

while linkerFlagSupported later executes:

exec.Command(linker, flags...)

As a result, the wrapper is invoked without the trailing compiler argument, causing the flag probe to return false.

The compiler itself does support the flag:

$ clang -m64 -mcpu=power10 /tmp/p10.c -o /tmp/p10
$ echo $?
0

What did you expect to see?

TestScript/cgo_path_space_quote should pass when CC contains a quoted executable path followed by additional arguments.

In this case, the external linker command is effectively:

"/tmp/.../program files/which cc" clang

Flag probing should preserve the complete external linker command, including the trailing clang argument.

The Power10 capability probe should therefore invoke the wrapper with clang before -mcpu=power10, detect that the compiler supports the flag, and allow go run . to complete successfully.

Activity

  1. self-assigned this
    on Aug 27, 2026
  2. jkrishmys commented on Aug 27, 2026

    @jkrishmys
    ContributorAuthor

    cc @golang/ppc64

  3. removed their assignment
    on Aug 27, 2026
  4. jkrishmys commented on Aug 27, 2026

    @jkrishmys
    ContributorAuthor

    Also reproduced on ppc64le POWER9 (first observed in Go CI/CD dashboard ).

    In TestScript/cgo_path_space_quote, the same multi-word CC truncation affects the -no-pie / -nopie probes.

    The test sets:

    CC="/tmp/.../program files/which cc" clang
    

    but inside go run ., the probes are executed as:

    DEBUG linkerFlagSupported: flag="-no-pie"
    cmd=["/tmp/.../program files/which cc" "-m64" "-o" "..." "-no-pie" ".../trivial.c"]
    
    DEBUG linkerFlagSupported: flag="-nopie"
    cmd=["/tmp/.../program files/which cc" "-m64" "-o" "..." "-nopie" ".../trivial.c"]
    

    The trailing clang argument is missing in both cases.

    On this POWER9 system, Clang defaults to PIE:

    $ readelf -h /tmp/default | grep 'Type:'
    Type: DYN (Position-Independent Executable file)
    

    while -no-pie produces:

    $ readelf -h /tmp/nopie | grep 'Type:'
    Type: EXEC (Executable file)
    

    Since both -no-pie and -nopie probes falsely fail, the external link proceeds without either flag. The resulting executable then fails at load time with:

    R_PPC64_ADDR16_HA reloc ... out of range
    exit status 127
    

    The same missing trailing compiler argument is also visible in the probes for -Wl,--build-id=..., -Wl,--export-dynamic-symbol=main, -Qunused-arguments, and -Wl,--compress-debug-sections=zlib.

    So the issue is not limited to the Power10 -mcpu=power10 check; the same linkerFlagSupported argument loss affects multiple generic flag probes.

  5. changed the title [-]cmd/link: linkerFlagSupported drops trailing arguments from multi-word CC, causing false "-mcpu=power10" unsupported error on ppc64le[/-] [+]cmd/link: linkerFlagSupported drops trailing arguments from multi-word CC when probing linker flags[/+] on Aug 27, 2026
  6. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Aug 28, 2026
  7. added this to the Backlog milestone on Sep 8, 2026
  8. added 6 commits that reference this issue on Sep 9, 2026
    5bf0803
    266a138
    86f5a03
    db5ef02
    b0c78be
    91ed8ce
  9. KingLizard1020 commented on Sep 9, 2026

    @KingLizard1020

    A proposed fix is in #81410. The linker now passes the full CC / -extld command when probing flags, so wrapper-prefixed compilers are no longer dropped.

  10. gopherbot commented on Sep 9, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/829964 mentions this issue: cmd/link: preserve extra CC arguments when probing linker flags

  11. ianlancetaylor commented on Sep 10, 2026

    @ianlancetaylor
    Contributor

    I suspect that this is fixed by https://go.dev/cl/823024.

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

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions