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

cmd/go,cmd/link: "go build" doesn't rebuild the binary after build flags changed #63760

Open
sandy-lcq opened this issue Oct 27, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. GoCommand cmd/go WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@sandy-lcq
Copy link

I am doing cross compile with go, version 1.20.6.

Reproduce steps:

  1. go build -p 48 -v -ldflags="-r /usr/lib/go/pkg/linux_arm64_dynlink -I /lib64/ld-linux-aarch64.so.1 ..." ...
    this command will generate an binary under builds/plugins/bin/brigde
  2. Don't delete builds/plugins/bin/brigde, Don't change any code or others, only change dynamic link path in ldflags, dynamic linker changed from " /lib64/ld-linux-aarch64.so.1" to " /usr/lib/ld-linux-aarch64.so.1".
    Run go build -p 48 -v -ldflags="-r /usr/lib/go/pkg/linux_arm64_dynlink -I /usr/lib/ld-linux-aarch64.so.1 ..." ...
  3. readelf -a builds/plugins/bin/brigde | grep interpre
    we can see the binary brigde still have the old dynamic linker, this will make bridge cannot run on target.

It seems like that "go build" only checks if the cached packagefile is changed, since we don't change any code in step 2, cached packagefile not changed, and bridge is still there, so it did not relink with the new dynamic linker. I think it should relink.

@bcmills bcmills changed the title "go build" don't rebuild the binary after build flags changed cmd/go,cmd/link: "go build" doesn't rebuild the binary after build flags changed Oct 27, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 27, 2023
@bcmills
Copy link
Member

bcmills commented Oct 27, 2023

Please fill out the complete issue template, including the requested output from go version and go env and the complete command lines used to build the binaries.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. GoCommand cmd/go labels Oct 27, 2023
@sandy-lcq
Copy link
Author

sandy-lcq commented Oct 30, 2023

Hi,

$aarch64-wrs-linux-go version
go version go1.20.6 linux/amd64

$aarch64-wrs-linux-go env
see in env.log
env.log

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build/.cache'
GOENV=''
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build-tmp'
GOTOOLDIR='/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native/usr/lib/aarch64-wrs-linux/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.20.6'
GCCGO='gccgo'
AR='aarch64-wrs-linux-gcc-ar'
CC='aarch64-wrs-linux-gcc  -mcpu=cortex-a72 -march=armv8-a+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot'
CXX='aarch64-wrs-linux-g++  -mcpu=cortex-a72 -march=armv8-a+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native='
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native= -fvisibility-inlines-hidden'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native= -Wl,-z,relro,-z,now'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-mbranch-protection=standard -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot -I . -fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build-tmp/go-build748140811=/tmp/go-build -gno-record-gcc-switches'


HASH[gccCompilerID]
HASH[gccCompilerID]: "go1.20.6"
HASH[gccCompilerID]: "gccCompilerID \"/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native/usr/bin/aarch64-wrs-linux/aarch64-wrs-linux-gcc\""
HASH[gccCompilerID]: 57aead5f4bce466be06cbecef3a82f90f90c34fe4ee132cfe8e49bedcddba3ce
HASH[gccCompilerID]: "gccCompilerID [\"/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native/usr/bin/aarch64-wrs-linux/aarch64-wrs-linux-gcc\" \"\"] \"gcc version 12.3.0 (GCC) \"\n"
HASH[gccCompilerID]: 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee
HASH subkey 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee "gccSupportsFlag -fno-caret-diagnostics" = 1cd84bb014fed24a15d1afe3556ce47c195237c1cce6ebde950970dcfbd7c022
HASH subkey 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee "gccSupportsFlag -Qunused-arguments" = ec121adb29c2b5bd57c80734f689279cf86bd40ecfc5c16c3dc5a86ed4827f0b
HASH subkey 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee "gccSupportsFlag -Wl,--no-gc-sections" = 18eee5bb7f7c4b007541244a64f2472c82b2426346ad14c166ddce375052bf5a
HASH subkey 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee "gccSupportsFlag -fdebug-prefix-map=a=b" = 252424c6ec759b4f3ec6f52746eff2567d78d26f897bbeda320443acc980c9f8
HASH subkey 6d889135b5e2cfd1d136ca75ba2be2febb7e11340f87d0c90f0eb0cc8a74e7ee "gccSupportsFlag -gno-record-gcc-switches" = 6d0743d0adde977de6102ea7e386c603fd1bf3a3867d73c19ffee05594653e

$Complete build command line

aarch64-wrs-linux-go build -p 48 -v -ldflags="-r /usr/lib/go/pkg/linux_arm64_dynlink -I /usr/lib/ld-linux-aarch64.so.1 -extldflags ' -mcpu=cortex-a72 -march=armv8-a+crc -mbranch-protection=standard -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot -Wl,-rpath-link=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot/usr/lib/go/pkg/linux_arm64_dynlink -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/cni-v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build=/usr/src/debug/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0 -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fmacro-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot= -fdebug-prefix-map=/build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/recipe-sysroot-native= -Wl,-z,relro,-z,now'" -trimpath -buildmode=pie -o /build/bcm/tmp-glibc/work/cortexa72-wrs-linux/cni/v1.1.2+gitf024754da8d49bdac31d99d04355ddfe0340f8eb-r0/build/plugins/bin/$plugin github.com/containernetworking/plugins/bridge

NOTE:

  1. The bold part in above cmd is the only changed part in step 2.
  2. aarch64-wrs-linux-go is a wrapper of go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. GoCommand cmd/go WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
Status: No status
Development

No branches or pull requests

3 participants