Skip to content

cmd/link: reject >2GB static data #9862

@randall77

Description

@randall77

The following code prints 2!

package main
var a[1<<31]byte
func main() {
     println(a[0])
}

It seems that when bss is big, bad things happen on darwin. At 1<<30, it works (prints 0). It also fails at 1<<31, 1<<32, 1<<33. We get a compile error at 1<<31 - 1:

runtime.mallocinit: non-pc-relative relocation address is too big: 0x80070dbf

We should fail instead of silently generating bad code.

Linux works correctly: succeeds for up to close to 1<<32, fails with the above error for larger sizes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions