Skip to content

cmd/compile: -buildmode=pie should specify a random base address above 32bits to avoid using 32bits compatibility ASLR mode #73561

Closed

Description

@adreed-msft

Go version

go version go1.24.2 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\adreed\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\adreed\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\adreed\AppData\Local\Temp\go-build3436564709=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\adreed\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\adreed\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\adreed\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.2
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Build a go executable (for instance, AzCopy) and fire it into binskim analyze

What did you see happen?

In attempts to resolve this by setting --buildmode=pie (which I acknowledge is a default, but, figured I'd do a little science anyway)

C:\Users\adreed\Downloads\azcopy.exe: error BA2001: 'azcopy-pie.exe' is a 64-bit image with a preferred base address below the 4GB boundary.
Having a preferred base address below this boundary triggers a compatibility mode in Address Space Layout Randomization (ASLR) on recent versions of Windows that reduces the number of locations to which ASLR may relocate the binary. This reduces the effectiveness of ASLR at mitigating memory corruption vulnerabilities.
To resolve this issue, either use the default preferred base address by removing any uses of /baseaddress from compiler command lines, or /BASE from linker command lines (recommended), or configure your program to start at a base address above 4GB when compiled for 64 bit platforms (by changing the constant passed to /baseaddress or /BASE).
Note that if you choose to continue using a custom preferred base address, you will need to make this modification only for 64-bit builds, as base addresses above 4GB are not valid for 32-bit binaries.
For VC projects make sure that ItemDefinitionGroup - Link - BaseAddress property is not set.

What did you expect to see?

Ideally, we'd be able to either move the base address or remove the preferred base address entirely to address this.

Activity

  1. adreed-msft commented on Apr 30, 2025

    @adreed-msft
    Author

    For reference, this comes to us over in AzCopy land via Azure/azure-storage-azcopy#3012

  2. changed the title [-]cmd/go: Preferred base address below the 4GB boundary[/-] [+]cmd/comple: preferred base address below the 4GB boundary[/+] on Apr 30, 2025
  3. changed the title [-]cmd/comple: preferred base address below the 4GB boundary[/-] [+]cmd/compile: preferred base address below the 4GB boundary[/+] on Apr 30, 2025
  4. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Apr 30, 2025
  5. adonovan commented on May 1, 2025

    @adonovan
    Member

    A Go process's text section is already mapped to an unpredictable address, so I'm not sure there's actually a problem to be fixed here. (IIRC, the heap base offset is constant, but heap allocation is likely to be less predictable in general.)

  6. changed the title [-]cmd/compile: preferred base address below the 4GB boundary[/-] [+]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid 32 bits compatibility ASLR detections[/+] on May 1, 2025
  7. changed the title [-]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid 32 bits compatibility ASLR detections[/-] [+]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid using 32bits compatibility ASLR mode[/+] on May 1, 2025
  8. gabyhelp commented on May 1, 2025

    @gabyhelp

    Related Issues

    (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

  9. adreed-msft commented on May 6, 2025

    @adreed-msft
    Author

    A Go process's text section is already mapped to an unpredictable address, so I'm not sure there's actually a problem to be fixed here. (IIRC, the heap base offset is constant, but heap allocation is likely to be less predictable in general.)

    I will turn around and file this as a bug against binskim; I'm curious to see what their view on this is.

  10. adreed-msft commented on May 6, 2025

    @adreed-msft
    Author
  11. prattmic commented on May 7, 2025

    @prattmic
    Member
  12. qmuntal commented on May 9, 2025

    @qmuntal
    Member

    BinSkim reports the issue correctly. Go binaries support ASLR, but the Go internal linker sets the preferred base address to 4MB rather than 4GB on windows/amd64, which triggers the undesired ASLR compatibility mode mentioned in the BinSkim report. This is the offending code:

    PEBASE = 1 << 32
    if ctxt.Arch.Family == sys.AMD64 {
    // TODO(rsc): For cgo we currently use 32-bit relocations
    // that fail when PEBASE is too large.
    // We need to fix this, but for now, use a smaller PEBASE.
    PEBASE = 1 << 22
    }

    Note that windows/arm64 do get a 4GB preferred base address.

    There is a comment made by @rsc in that code saying that there is a cgo issue that doesn't allow us to increase the limit. More investigation is needed.

  13. self-assigned this
    on May 9, 2025
  14. gopherbot commented on May 9, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/671515 mentions this issue: cmd/link: use a 4GB base address for 64-bit PE binaries

  15. qmuntal commented on May 9, 2025

    @qmuntal
    Member

    Looks like the Go linker still can't handle 4GB relocations: https://ci.chromium.org/ui/p/golang/builders/try/gotip-windows-amd64/b8715335171107040657/overview. That will need to be fixed.

  16. added a commit that references this issue on May 24, 2025
    08037e6
  17. locked and limited conversation to collaborators on May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windowsarch-amd64compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions