Skip to content

Commit

Permalink
dev builds: keep debug symbols, no inline and no optimisations (#29961)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ authored Jan 26, 2022
1 parent a563681 commit e0053f7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dev-tools/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func DefaultBuildArgs() BuildArgs {
args := BuildArgs{
Name: BeatName,
CGO: build.Default.CgoEnabled,
LDFlags: []string{
"-s", // Strip all debug symbols from binary (does not affect Go stack traces).
},
Vars: map[string]string{
elasticBeatsModulePath + "/libbeat/version.buildTime": "{{ date }}",
elasticBeatsModulePath + "/libbeat/version.commit": "{{ commit }}",
Expand All @@ -63,18 +60,26 @@ func DefaultBuildArgs() BuildArgs {
args.Vars[elasticBeatsModulePath+"/libbeat/version.qualifier"] = "{{ .Qualifier }}"
}

if positionIndependendCodeSupported() {
if positionIndependentCodeSupported() {
args.ExtraFlags = append(args.ExtraFlags, "-buildmode", "pie")
}

if DevBuild {
// Disable optimizations (-N) and inlining (-l) for debugging.
args.ExtraFlags = append(args.ExtraFlags, `-gcflags`, `"all=-N -l"`)
} else {
// Strip all debug symbols from binary (does not affect Go stack traces).
args.LDFlags = append(args.LDFlags, "-s")
}

return args
}

// positionIndependendCodeSupported checks if the target platform support position independen code (or ASLR).
// positionIndependentCodeSupported checks if the target platform support position independent code (or ASLR).
//
// The list of supported platforms is compiled based on the Go release notes: https://golang.org/doc/devel/release.html
// The list has been updated according to the Go version: 1.16
func positionIndependendCodeSupported() bool {
func positionIndependentCodeSupported() bool {
return oneOf(Platform.GOOS, "darwin") ||
(Platform.GOOS == "linux" && oneOf(Platform.GOARCH, "riscv64", "amd64", "arm", "arm64", "ppc64le", "386")) ||
(Platform.GOOS == "aix" && Platform.GOARCH == "ppc64") ||
Expand Down

0 comments on commit e0053f7

Please sign in to comment.