Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 77527 - Build unstripped binaries on-demand #77549

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 43 additions & 2 deletions hack/lib/golang.sh
Expand Up @@ -750,6 +750,29 @@ kube::golang::get_physmem() {
echo 1
}

# Build unstripped binary on-demand
# return value
# 0: build unstripped binary
# 1: build stripped binary
kube::golang::build_unstripped_binary() {
local nflag lflag retval

nflag=0
lflag=0
retval=1

# Once "-N" and "-l" are specified together,
# binaries are built as unstripped
for flag in ${GOGCFLAGS:-}; do
[[ "${flag}" = "-N" ]] && nflag=1
[[ "${flag}" = "-l" ]] && lflag=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do -N and -l come from. i can't seem to find them under:
https://golang.org/cmd/link/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neolit123

The user specified in GOGCFLAGS and please refer the explaination in Makefile from Line 81 to Line 84

https://github.com/kubernetes/kubernetes/blob/master/build/root/Makefile#L81~L84

done

[[ ${nflag} -eq 1 ]] && [[ ${lflag} -eq 1 ]] && retval=0

return ${retval}
}

# Build binaries targets specified
#
# Input:
Expand All @@ -767,12 +790,30 @@ kube::golang::build_binaries() {
local host_platform
host_platform=$(kube::golang::host_platform)

local goflags goldflags goasmflags gogcflags
local goflags goldflags goasmflags gogcflags ldflags
# If GOLDFLAGS is unset, then set it to the a default of "-s -w".
# Disable SC2153 for this, as it will throw a warning that the local
# variable goldflags will exist, and it suggest changing it to this.
# shellcheck disable=SC2153
goldflags="${GOLDFLAGS=-s -w} $(kube::version::ldflags)"
# If the user prefers to build unstripped binaries,
# both "-s" and "-w" should be ignored

if kube::golang::build_unstripped_binary; then
ldflags=""
for v in ${GOLDFLAGS:=-s -w}; do
case "${v}" in
"-s" | "-w")
;;
*)
ldflags="${ldflags} ${v}"
;;
esac
done
else
ldflags="${GOLDFLAGS:=-s -w}"
fi

goldflags="${ldflags} $(kube::version::ldflags)"
goasmflags="-trimpath=${KUBE_ROOT}"
gogcflags="${GOGCFLAGS:-} -trimpath=${KUBE_ROOT}"

Expand Down