diff mbox series

go: filter out build specific path from the linker flags

Message ID 20240229012140.1355863-1-changqing.li@windriver.com
State Accepted, archived
Commit 6873c6cb000b24c1badd0fb8b5cd2d0a31a63096
Headers show
Series go: filter out build specific path from the linker flags | expand

Commit Message

Changqing Li Feb. 29, 2024, 1:21 a.m. UTC
From: Changqing Li <changqing.li@windriver.com>

patch 0007-exec.go-do-not-write-linker-flags-into-buildids.patch
removes linker flags from buildids for not breaking reproducibility,
but it seems that this will make go not rebuild when linker flag
changes, Refer [1]. So remove this oe-specific patch, and change to
filter out build specific path from the linker flags

[1] https://github.com/golang/go/issues/63760

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 meta/recipes-devtools/go/go-1.20.14.inc       |  2 +-
 ...ut-build-specific-paths-from-linker-.patch | 61 +++++++++++++++++++
 ...not-write-linker-flags-into-buildids.patch | 41 -------------
 3 files changed, 62 insertions(+), 42 deletions(-)
 create mode 100644 meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch
 delete mode 100644 meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch

Comments

Richard Purdie March 3, 2024, 4:32 p.m. UTC | #1
On Thu, 2024-02-29 at 09:21 +0800, Changqing Li wrote:
> From: Changqing Li <changqing.li@windriver.com>
> 
> patch 0007-exec.go-do-not-write-linker-flags-into-buildids.patch
> removes linker flags from buildids for not breaking reproducibility,
> but it seems that this will make go not rebuild when linker flag
> changes, Refer [1]. So remove this oe-specific patch, and change to
> filter out build specific path from the linker flags
> 
> [1] https://github.com/golang/go/issues/63760
> 
> Signed-off-by: Changqing Li <changqing.li@windriver.com>
> ---
>  meta/recipes-devtools/go/go-1.20.14.inc       |  2 +-
>  ...ut-build-specific-paths-from-linker-.patch | 61 +++++++++++++++++++
>  ...not-write-linker-flags-into-buildids.patch | 41 -------------
>  3 files changed, 62 insertions(+), 42 deletions(-)
>  create mode 100644 meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch
>  delete mode 100644 meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch

Whilst I think this is a good change, I decided to take the 1.21
upgrade and this conflicts. Would you be able to rebase against the new
version please?

Thanks,

Richard
Changqing Li March 4, 2024, 7:37 a.m. UTC | #2
On 3/4/24 00:32, Richard Purdie wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Thu, 2024-02-29 at 09:21 +0800, Changqing Li wrote:
>> From: Changqing Li <changqing.li@windriver.com>
>>
>> patch 0007-exec.go-do-not-write-linker-flags-into-buildids.patch
>> removes linker flags from buildids for not breaking reproducibility,
>> but it seems that this will make go not rebuild when linker flag
>> changes, Refer [1]. So remove this oe-specific patch, and change to
>> filter out build specific path from the linker flags
>>
>> [1] https://github.com/golang/go/issues/63760
>>
>> Signed-off-by: Changqing Li <changqing.li@windriver.com>
>> ---
>>   meta/recipes-devtools/go/go-1.20.14.inc       |  2 +-
>>   ...ut-build-specific-paths-from-linker-.patch | 61 +++++++++++++++++++
>>   ...not-write-linker-flags-into-buildids.patch | 41 -------------
>>   3 files changed, 62 insertions(+), 42 deletions(-)
>>   create mode 100644 meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch
>>   delete mode 100644 meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch
> Whilst I think this is a good change, I decided to take the 1.21
> upgrade and this conflicts. Would you be able to rebase against the new
> version please?

OK, I noticed that there is a 1.22 on master-next. I will rebase against 
on 1.22

and send a V2.

Regards

Changqing

>
> Thanks,
>
> Richard
diff mbox series

Patch

diff --git a/meta/recipes-devtools/go/go-1.20.14.inc b/meta/recipes-devtools/go/go-1.20.14.inc
index 7e425effe5..0726da100f 100644
--- a/meta/recipes-devtools/go/go-1.20.14.inc
+++ b/meta/recipes-devtools/go/go-1.20.14.inc
@@ -11,8 +11,8 @@  SRC_URI += "\
     file://0004-make.bash-override-CC-when-building-dist-and-go_boot.patch \
     file://0005-cmd-dist-separate-host-and-target-builds.patch \
     file://0006-cmd-go-make-GOROOT-precious-by-default.patch \
-    file://0007-exec.go-do-not-write-linker-flags-into-buildids.patch \
     file://0008-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \
     file://0009-go-Filter-build-paths-on-staticly-linked-arches.patch \
+    file://0001-exec.go-filter-out-build-specific-paths-from-linker-.patch \
 "
 SRC_URI[main.sha256sum] = "1aef321a0e3e38b7e91d2d7eb64040666cabdcc77d383de3c9522d0d69b67f4e"
diff --git a/meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch b/meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch
new file mode 100644
index 0000000000..c5bf28f54a
--- /dev/null
+++ b/meta/recipes-devtools/go/go/0001-exec.go-filter-out-build-specific-paths-from-linker-.patch
@@ -0,0 +1,61 @@ 
+From 083b5c74b12a1abeb11dd7f58a1cb1593d0000c0 Mon Sep 17 00:00:00 2001
+From: Changqing Li <changqing.li@windriver.com>
+Date: Tue, 27 Feb 2024 18:06:51 +0800
+Subject: [PATCH] exec.go: filter out build-specific paths from linker flags
+
+The flags can contain build-specific paths, breaking reproducibility.
+Filter out options that have build-specific paths.
+
+Upstream-Status: Inappropriate [ Not perfect for upstream ]
+
+Signed-off-by: Changqing Li <changqing.li@windriver.com>
+---
+ src/cmd/go/internal/work/exec.go | 25 ++++++++++++++++++++++++-
+ 1 file changed, 24 insertions(+), 1 deletion(-)
+
+diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
+index cde867b..e3ce17d 100644
+--- a/src/cmd/go/internal/work/exec.go
++++ b/src/cmd/go/internal/work/exec.go
+@@ -1358,6 +1358,29 @@ func (b *Builder) linkActionID(a *Action) cache.ActionID {
+ 	return h.Sum()
+ }
+ 
++func filterLinkerFlags(flags []string) []string {
++	var newflags []string
++	var skipflag bool
++	skipflag = false
++	for i, flag := range flags {
++		if skipflag == true {
++			skipflag = false
++			continue
++		}
++		if strings.HasPrefix(flag, "--sysroot") || strings.HasPrefix(flag, "-fmacro-prefix-map") || strings.HasPrefix(flag, "-fdebug-prefix-map") || strings.HasPrefix(flag, "-ffile-prefix-map") || strings.HasPrefix(flag, "-fcanon-prefix-map") || strings.HasPrefix(flag, "-fprofile-prefix-map") || strings.HasPrefix(flag, "-Wl,-rpath-link"){
++			continue
++		} else if strings.HasPrefix(flag, "-extldflags") {
++			skipflag = true
++			newflags = append(newflags, flag)
++			var filterd_Extldflags []string = filterLinkerFlags(strings.Split(flags[i+1], " "))
++			newflags = append(newflags, strings.Join(filterd_Extldflags, " "))
++		} else {
++			newflags = append(newflags, flag)
++		}
++	}
++	return newflags
++}
++
+ // printLinkerConfig prints the linker config into the hash h,
+ // as part of the computation of a linker-related action ID.
+ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
+@@ -1368,7 +1391,7 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
+ 	case "gc":
+ 		fmt.Fprintf(h, "link %s %q %s\n", b.toolID("link"), forcedLdflags, ldBuildmode)
+ 		if p != nil {
+-			fmt.Fprintf(h, "linkflags %q\n", p.Internal.Ldflags)
++			fmt.Fprintf(h, "linkflags %q\n", filterLinkerFlags(p.Internal.Ldflags))
+ 		}
+ 
+ 		// GOARM, GOMIPS, etc.
+-- 
+2.25.1
+
diff --git a/meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch b/meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch
deleted file mode 100644
index 7d9869b536..0000000000
--- a/meta/recipes-devtools/go/go/0007-exec.go-do-not-write-linker-flags-into-buildids.patch
+++ /dev/null
@@ -1,41 +0,0 @@ 
-From 0ba747e6a4b251a0d9eed0cfd8f8c491bb508040 Mon Sep 17 00:00:00 2001
-From: Alexander Kanavin <alex.kanavin@gmail.com>
-Date: Mon, 23 Nov 2020 19:22:04 +0000
-Subject: [PATCH 7/9] exec.go: do not write linker flags into buildids
-
-The flags can contain build-specific paths, breaking reproducibility.
-
-To make this acceptable to upstream, we probably need to trim the flags,
-removing those known to be buildhost-specific.
-
-Upstream-Status: Inappropriate [needs upstream discussion]
-Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
----
- src/cmd/go/internal/work/exec.go | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
-index cde867b..5cb1812 100644
---- a/src/cmd/go/internal/work/exec.go
-+++ b/src/cmd/go/internal/work/exec.go
-@@ -1331,7 +1331,7 @@ func (b *Builder) linkActionID(a *Action) cache.ActionID {
- 	}
- 
- 	// Toolchain-dependent configuration, shared with b.linkSharedActionID.
--	b.printLinkerConfig(h, p)
-+	//b.printLinkerConfig(h, p)
- 
- 	// Input files.
- 	for _, a1 := range a.Deps {
-@@ -1626,7 +1626,7 @@ func (b *Builder) linkSharedActionID(a *Action) cache.ActionID {
- 	fmt.Fprintf(h, "goos %s goarch %s\n", cfg.Goos, cfg.Goarch)
- 
- 	// Toolchain-dependent configuration, shared with b.linkActionID.
--	b.printLinkerConfig(h, nil)
-+	//b.printLinkerConfig(h, nil)
- 
- 	// Input files.
- 	for _, a1 := range a.Deps {
--- 
-2.30.2
-