Skip to contentSkip to conversation

go: fix building without SECURITY_LDFLAGS

PATCH In review Dmitry Baryshkov 2 participants 2 messages Jan 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 go: fix building without SECURITY_LDFLAGS

Commit 9985b17a30bb ("go: correctly set debug-prefix-map and build directory") has changed CGO_LDFLAGS to the manually crafted version of LDFLAGS to strip out DEBUG_PREFIX_MAP contents.

However this manually crafted version includes ${SECURITY_LDFLAGS}.

If security_flags.inc is not included, the variable is not defined, thus CGO_LDFLAGS will include the '${SECURITY_LDFLAGS}' literally. When building the recipe, the build would break with the follwing message:

aarch64-linaro-linux-gcc: error: ${SECURITY_LDFLAGS}: No such file or directory

So, instead of manually specifying variable contents, perform the expected action: filter offending arguments out of LDFLAGS.

Cc Alexander Kanavin <[email protected]>
---
 meta/recipes-devtools/go/go-runtime.inc | 3 ++-
 meta/recipes-devtools/go/go-target.inc  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
meta/recipes-devtools/go/go-runtime.inc +2 -1
index a08d44dd3a8c..ccb86d4fe9a6 100644
@@ -10,7 +10,8 @@ DEBUG_PREFIX_MAP = "\
 export CGO_CFLAGS = "${CFLAGS}"
 export CGO_CPPFLAGS = "${CPPFLAGS}"
 export CGO_CXXFLAGS = "${CXXFLAGS}"
-export CGO_LDFLAGS = "-Wl,-O1 ${TARGET_LINK_HASH_STYLE} ${ASNEEDED} ${SECURITY_LDFLAGS}"
+# Filter out -fdebug-prefix-map options as they clash with the GO's build system
+export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
 export GOCACHE = "${B}/.cache"
 
 GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
meta/recipes-devtools/go/go-target.inc +2 -1
index 51f1b79cc320..b0d487ae1c21 100644
@@ -9,7 +9,8 @@ DEBUG_PREFIX_MAP = "\
 export CGO_CFLAGS = "${CFLAGS}"
 export CGO_CPPFLAGS = "${CPPFLAGS}"
 export CGO_CXXFLAGS = "${CXXFLAGS}"
-export CGO_LDFLAGS = "-Wl,-O1 ${TARGET_LINK_HASH_STYLE} ${ASNEEDED} ${SECURITY_LDFLAGS}"
+# Filter out -fdebug-prefix-map options as they clash with the GO's build system
+export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
 
 export GOCACHE = "${B}/.cache"
 GO_LDFLAGS = ""
Signature · 1 line
2.30.2
#1 lore raw

Thanks, this should work.

Alex

Quoted 63 lines · Dmitry Baryshkov

Commit 9985b17a30bb ("go: correctly set debug-prefix-map and build directory") has changed CGO_LDFLAGS to the manually crafted version of LDFLAGS to strip out DEBUG_PREFIX_MAP contents.

However this manually crafted version includes ${SECURITY_LDFLAGS}.

If security_flags.inc is not included, the variable is not defined, thus CGO_LDFLAGS will include the '${SECURITY_LDFLAGS}' literally. When building the recipe, the build would break with the follwing message:

aarch64-linaro-linux-gcc: error: ${SECURITY_LDFLAGS}: No such file or directory

So, instead of manually specifying variable contents, perform the expected action: filter offending arguments out of LDFLAGS.

Cc Alexander Kanavin <[email protected]>
---
 meta/recipes-devtools/go/go-runtime.inc | 3 ++-
 meta/recipes-devtools/go/go-target.inc  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
meta/recipes-devtools/go/go-runtime.inc +0 -1
index a08d44dd3a8c..ccb86d4fe9a6 100644
@@ -10,7 +10,8 @@ DEBUG_PREFIX_MAP = "\
 export CGO_CFLAGS = "${CFLAGS}"
 export CGO_CPPFLAGS = "${CPPFLAGS}"
 export CGO_CXXFLAGS = "${CXXFLAGS}"
-export CGO_LDFLAGS = "-Wl,-O1 ${TARGET_LINK_HASH_STYLE} ${ASNEEDED}

${SECURITY_LDFLAGS}"
+# Filter out -fdebug-prefix-map options as they clash with the GO's build system
+export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
export GOCACHE = "${B}/.cache"

GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"

meta/recipes-devtools/go/go-target.inc +0 -1
index 51f1b79cc320..b0d487ae1c21 100644
@@ -9,7 +9,8 @@ DEBUG_PREFIX_MAP = "\
 export CGO_CFLAGS = "${CFLAGS}"
 export CGO_CPPFLAGS = "${CPPFLAGS}"
 export CGO_CXXFLAGS = "${CXXFLAGS}"
-export CGO_LDFLAGS = "-Wl,-O1 ${TARGET_LINK_HASH_STYLE} ${ASNEEDED}

${SECURITY_LDFLAGS}"
+# Filter out -fdebug-prefix-map options as they clash with the GO's build system
+export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"

export GOCACHE = "${B}/.cache"
GO_LDFLAGS = ""
--
2.30.2