Skip to contentSkip to conversation

pkg-golang: add strip, asmflags, gcflags support

PATCH New Christian Stewart 2 participants 3 messages Jan 24, 2019 – Jan 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pkg-golang: add strip, asmflags, gcflags support

Adding package-level variables to set asmflags, gcflags.

Conditionally sets ldflags -s -w when buildroot is configured to strip binaries.

---
 package/pkg-golang.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
package/pkg-golang.mk +8 -0
index 4f2c7e77e1..79ebec94be 100644
@@ -55,7 +55,15 @@ ifeq ($(BR2_STATIC_LIBS),y)
 $(2)_LDFLAGS += -extldflags '-static'
 endif
 
+ifeq ($(BR2_STRIP_strip),y)
+$(2)_LDFLAGS += -s -w
+endif
+
+$(2)_ASMFLAGS += -trimpath=$(BUILD_DIR)
+$(2)_GCFLAGS  += -trimpath=$(BUILD_DIR)
 $(2)_BUILD_OPTS += \
+	-asmflags "$$($(2)_ASMFLAGS)" \
+	-gcflags "$$($(2)_GCFLAGS)" \
 	-ldflags "$$($(2)_LDFLAGS)" \
 	-tags "$$($(2)_TAGS)" \
 	-p $(PARALLEL_JOBS)
Signature · 1 line
2.19.2
#1 lore raw

PATCH 1/1 pkg-golang: add strip, asmflags, gcflags support

Quoted 14 lines · Christian Stewart

Adding package-level variables to set asmflags, gcflags.

Conditionally sets ldflags -s -w when buildroot is configured to strip binaries.

---
 package/pkg-golang.mk | 8 ++++++++
 1 file changed, 8 insertions(+)
package/pkg-golang.mk +0 -0
index 4f2c7e77e1..79ebec94be 100644

package/pkg-golang.mk ifeq ($(BR2_STATIC_LIBS),y) · line 63

Quoted 9 lines
package/pkg-golang.mk +6 -0
@@ -55,7 +55,15 @@ ifeq ($(BR2_STATIC_LIBS),y)
 $(2)_LDFLAGS += -extldflags '-static'
 endif
 
+ifeq ($(BR2_STRIP_strip),y)
+$(2)_LDFLAGS += -s -w
+endif
+
+$(2)_ASMFLAGS += -trimpath=$(BUILD_DIR)
+$(2)_GCFLAGS  += -trimpath=$(BUILD_DIR)

I see that you added trimpath here, which is useful for removing the build path from the binaries, (and having reproducible builds), but it isn't mentionned in the commit message.

As a sidenote, it seems that this option is broken when building a package with go modules:
https://github.com/golang/go/issues/28008

Regards,

Anisse

#2 lore raw

PATCH 1/1 pkg-golang: add strip, asmflags, gcflags support

Anisse,

Quoted 3 lines · Anisse Astier

I see that you added trimpath here, which is useful for removing the build path from the binaries, (and having reproducible builds), but it isn't mentionned in the commit message.

Yes, I had originally intended for this to be a separate commit, but the functionality works as intended and I am happy to keep it as part of this commmit.

Quoted 3 lines

As a sidenote, it seems that this option is broken when building a package with go modules:
https://github.com/golang/go/issues/28008

There will never be a Buildroot core package with Go modules in use nor enabled, as this would imply a separate network resource fetching mechanism from the core Buildroot tarball download + hash cycle.

Even so, the option would then not break the build, but would merely fail to trim the paths in the output binary.

Best,
Christian