[go] cmd/go: clear GOROOT for func ldShared when -trimpath is used

7 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Feb 28, 2025, 10:48:36 PMFeb 28
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

cmd/go: clear GOROOT for func ldShared when -trimpath is used

In commit [cmd: remove support for GOROOT_FINAL][1], it clear GOROOT for func ld when -trimpath is used. [2]

This commit do the same thing for func ldShared, otherwise run go_bootstrap with -trimpath does not remove build path directory from the generated share libarary

$ ./make.bash --target-only --no-banner std
$ go_bootstrap install -linkshared -buildmode=shared -trimpath std
$ grep "$(pwd)" ./pkg/linux_amd64_dynlink/libstd.so
Binary file ./pkg/linux_amd64_dynlink/libstd.so matches

[1] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98
[2] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98#diff-cab5921f94f2667bb0bc1b935d2d46b4c03541b4351b33438ab7290b94dea212R669

This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.

**Please ensure you adhere to every item in this list.**

More info can be found at https://github.com/golang/go/wiki/CommitMessage

+ The PR title is formatted as follows: `net/http: frob the quux before blarfing`
+ The package name goes before the colon
+ The part after the colon uses the verb tense + phrase that completes the blank in,
"This change modifies Go to ___________"
+ Lowercase verb after the colon
+ No trailing period
+ Keep the title as short as possible. ideally under 76 characters or shorter
+ No Markdown
+ The first PR comment (this one) is wrapped at 76 characters, unless it's
really needed (ASCII art, table, or long link)
+ If there is a corresponding issue, add either `Fixes #1234` or `Updates #1234`
(the latter if this is not a complete fix) to this comment
+ If referring to a repo other than `golang/go` you can use the
`owner/repo#issue_number` syntax: `Fixes golang/tools#1234`
+ We do not use Signed-off-by lines in Go. Please don't add them.
Our Gerrit server & GitHub bots enforce CLA compliance instead.
+ Delete these instructions once you have read and applied them
Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
GitHub-Last-Rev: 199cf2a198094d60b29c145b9d60a4d0c52d95c4
GitHub-Pull-Request: golang/go#72047

Change diff

diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go
index 3a173ef..8b7a44e 100644
--- a/src/cmd/go/internal/work/gc.go
+++ b/src/cmd/go/internal/work/gc.go
@@ -728,7 +728,14 @@
// the output file path is recorded in the .gnu.version_d section.
dir, targetPath := filepath.Split(targetPath)

- return b.Shell(root).run(dir, targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
+ env := []string{}
+ // When -trimpath is used, GOROOT is cleared
+ if cfg.BuildTrimpath {
+ env = append(env, "GOROOT=")
+ } else {
+ env = append(env, "GOROOT="+cfg.GOROOT)
+ }
+ return b.Shell(root).run(dir, targetPath, env, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
}

func (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {

Change information

Files:
  • M src/cmd/go/internal/work/gc.go
Change size: XS
Delta: 1 file changed, 8 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
Gerrit-Change-Number: 653855
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Feb 28, 2025, 10:48:36 PMFeb 28
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems.

These findings are based on simple heuristics. If a finding appears wrong, briefly reply here saying so. Otherwise, please address any problems and update the GitHub PR. When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above.

Possible problems detected:
1. Do you still have the GitHub PR instructions in your commit message text? The PR instructions should be deleted once you have applied them.
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

The commit title and commit message body come from the GitHub PR title and description, and must be edited in the GitHub web interface (not via git). For instructions, see [here](https://go.dev/wiki/GerritBot/#how-does-gerritbot-determine-the-final-commit-message). For guidelines on commit messages for the Go project, see [here](https://go.dev/doc/contribute#commit_messages).


(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
    Gerrit-Change-Number: 653855
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Sat, 01 Mar 2025 03:48:32 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Feb 28, 2025, 10:55:01 PMFeb 28
    to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Message from Gopher Robot

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
    Gerrit-Change-Number: 653855
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Sat, 01 Mar 2025 03:54:55 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    hongxu jia (Gerrit)

    unread,
    Feb 28, 2025, 11:06:58 PMFeb 28
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    hongxu jia has uploaded the change for review

    Commit message

    cmd/go: clear GOROOT for func ldShared when -trimpath is used

    In commit [cmd: remove support for GOROOT_FINAL][1], it clear GOROOT
    for func ld when -trimpath is used. [2]

    This commit do the same thing for func ldShared, otherwise run go_bootstrap
    with -trimpath does not remove build path directory from the generated share
    libarary

    $ ./make.bash --target-only --no-banner std
    $ go_bootstrap install -linkshared -buildmode=shared -trimpath std
    $ grep "$(pwd)" ./pkg/linux_amd64_dynlink/libstd.so
    Binary file ./pkg/linux_amd64_dynlink/libstd.so matches

    [1] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98
    [2] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98#diff-cab5921f94f2667bb0bc1b935d2d46b4c03541b4351b33438ab7290b94dea212R669
    Signed-off-by: Hongxu Jia <hongx...@windriver.com>
    Change-Id: I9fba0a69a37172ab2f20ca8123f82592de04bbce

    Change diff

    diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go
    index 3a173ef..8b7a44e 100644
    --- a/src/cmd/go/internal/work/gc.go
    +++ b/src/cmd/go/internal/work/gc.go
    @@ -728,7 +728,14 @@
    // the output file path is recorded in the .gnu.version_d section.
    dir, targetPath := filepath.Split(targetPath)

    - return b.Shell(root).run(dir, targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
    + env := []string{}
    + // When -trimpath is used, GOROOT is cleared
    + if cfg.BuildTrimpath {
    + env = append(env, "GOROOT=")
    + } else {
    + env = append(env, "GOROOT="+cfg.GOROOT)
    + }
    + return b.Shell(root).run(dir, targetPath, env, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
    }

    func (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {

    Change information

    Files:
    • M src/cmd/go/internal/work/gc.go
    Change size: XS
    Delta: 1 file changed, 8 insertions(+), 1 deletion(-)

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Signed-off-by-Footer
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newchange
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I9fba0a69a37172ab2f20ca8123f82592de04bbce
      Gerrit-Change-Number: 653895
      Gerrit-PatchSet: 1
      Gerrit-Owner: hongxu jia <hongx...@gmail.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      hongxu jia (Gerrit)

      unread,
      Mar 1, 2025, 5:05:48 AMMar 1
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Sam Thanawalla, Michael Matloob, Russ Cox, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Michael Matloob and Sam Thanawalla

      hongxu jia added 1 comment

      Patchset-level comments
      hongxu jia . resolved
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Michael Matloob
      • Sam Thanawalla
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
        Gerrit-Change-Number: 653855
        Gerrit-PatchSet: 1
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
        Gerrit-Reviewer: Sam Thanawalla <samtha...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-CC: hongxu jia <hongx...@gmail.com>
        Gerrit-Attention: Sam Thanawalla <samtha...@google.com>
        Gerrit-Attention: Michael Matloob <mat...@golang.org>
        Gerrit-Comment-Date: Sat, 01 Mar 2025 10:05:42 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        unsatisfied_requirement
        open
        diffy

        hongxu jia (Gerrit)

        unread,
        Mar 1, 2025, 5:07:49 AMMar 1
        to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
        Attention needed from Constantin Konstantinidis and Dmitri Shuralyov

        hongxu jia uploaded new patchset

        hongxu jia uploaded patch set #2 to this change.
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Constantin Konstantinidis
        • Dmitri Shuralyov
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Signed-off-by-Footer
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I9fba0a69a37172ab2f20ca8123f82592de04bbce
          Gerrit-Change-Number: 653895
          Gerrit-PatchSet: 2
          Gerrit-Owner: hongxu jia <hongx...@gmail.com>
          Gerrit-Reviewer: Constantin Konstantinidis <constantinko...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-Attention: Constantin Konstantinidis <constantinko...@gmail.com>
          Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
          unsatisfied_requirement
          satisfied_requirement
          open
          diffy

          t hepudds (Gerrit)

          unread,
          Mar 1, 2025, 3:19:11 PMMar 1
          to Gerrit Bot, hongxu jia, goph...@pubsubhelper.golang.org, Sam Thanawalla, Michael Matloob, Russ Cox, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Michael Matloob and Sam Thanawalla

          t hepudds added 1 comment

          Patchset-level comments
          hongxu jia . unresolved

          Duplicated with https://go-review.googlesource.com/c/go/+/653895

          t hepudds

          Hi, if this is duplicate, can you close the GitHub PR in the GitHub UI? That should automatically close this CL as well a few minutes later.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Michael Matloob
          • Sam Thanawalla
          Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            • requirement is not satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Id4f11c19713d79c5e32ab3e89dfddcc90c7590c9
            Gerrit-Change-Number: 653855
            Gerrit-PatchSet: 1
            Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
            Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
            Gerrit-Reviewer: Sam Thanawalla <samtha...@google.com>
            Gerrit-CC: Gopher Robot <go...@golang.org>
            Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
            Gerrit-CC: Russ Cox <r...@golang.org>
            Gerrit-CC: hongxu jia <hongx...@gmail.com>
            Gerrit-CC: t hepudds <thepud...@gmail.com>
            Gerrit-Attention: Sam Thanawalla <samtha...@google.com>
            Gerrit-Attention: Michael Matloob <mat...@golang.org>
            Gerrit-Comment-Date: Sat, 01 Mar 2025 20:19:07 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            Comment-In-Reply-To: hongxu jia <hongx...@gmail.com>
            unsatisfied_requirement
            open
            diffy

            Gopher Robot (Gerrit)

            unread,
            Mar 2, 2025, 5:03:32 AMMar 2
            to Gerrit Bot, hongxu jia, goph...@pubsubhelper.golang.org, t hepudds, Sam Thanawalla, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

            Gopher Robot abandoned this change

            Related details

            Attention set is empty
            Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            • requirement is not satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: abandon
            unsatisfied_requirement
            open
            diffy

            Constantin Konstantinidis (Gerrit)

            unread,
            Mar 10, 2025, 10:42:10 AMMar 10
            to hongxu jia, goph...@pubsubhelper.golang.org, Michael Matloob, Dmitri Shuralyov, golang-co...@googlegroups.com
            Attention needed from Michael Matloob and hongxu jia

            Constantin Konstantinidis added 1 comment

            Patchset-level comments
            File-level comment, Patchset 2 (Latest):
            Constantin Konstantinidis . resolved

            CL seems to implement proposal https://github.com/golang/go/issues/69565 which is pending processing.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Michael Matloob
            • hongxu jia
            Submit Requirements:
              • requirement is not satisfiedCode-Review
              • requirement is not satisfiedNo-Signed-off-by-Footer
              • requirement satisfiedNo-Unresolved-Comments
              • requirement is not satisfiedReview-Enforcement
              • requirement is not satisfiedTryBots-Pass
              Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
              Gerrit-MessageType: comment
              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I9fba0a69a37172ab2f20ca8123f82592de04bbce
              Gerrit-Change-Number: 653895
              Gerrit-PatchSet: 2
              Gerrit-Owner: hongxu jia <hongx...@gmail.com>
              Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
              Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
              Gerrit-Attention: Michael Matloob <mat...@golang.org>
              Gerrit-Attention: hongxu jia <hongx...@gmail.com>
              Gerrit-Comment-Date: Mon, 10 Mar 2025 14:42:04 +0000
              Gerrit-HasComments: Yes
              Gerrit-Has-Labels: No
              unsatisfied_requirement
              satisfied_requirement
              open
              diffy

              Michael Matloob (Gerrit)

              unread,
              Nov 3, 2025, 4:49:10 PM (3 days ago) Nov 3
              to hongxu jia, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, golang-co...@googlegroups.com
              Attention needed from hongxu jia

              Michael Matloob added 1 comment

              Patchset-level comments
              Constantin Konstantinidis . unresolved

              CL seems to implement proposal https://github.com/golang/go/issues/69565 which is pending processing.

              Michael Matloob

              Is that the right proposal link? In any case we should have a link to the issue in the change description.

              Open in Gerrit

              Related details

              Attention is currently required from:
              • hongxu jia
              Submit Requirements:
                • requirement is not satisfiedCode-Review
                • requirement is not satisfiedNo-Signed-off-by-Footer
                • requirement is not satisfiedNo-Unresolved-Comments
                • requirement is not satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: comment
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I9fba0a69a37172ab2f20ca8123f82592de04bbce
                Gerrit-Change-Number: 653895
                Gerrit-PatchSet: 2
                Gerrit-Owner: hongxu jia <hongx...@gmail.com>
                Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
                Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
                Gerrit-Attention: hongxu jia <hongx...@gmail.com>
                Gerrit-Comment-Date: Mon, 03 Nov 2025 21:49:07 +0000
                Gerrit-HasComments: Yes
                Gerrit-Has-Labels: No
                Comment-In-Reply-To: Constantin Konstantinidis <constantinko...@gmail.com>
                unsatisfied_requirement
                open
                diffy
                Reply all
                Reply to author
                Forward
                0 new messages