Skip to content

cmd/asm: 386 assembler silently drops indices when indexing symbols #41286

Closed

Description

@clausecker

What version of Go are you using (go version)?

$ go version
go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build142714031=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create an assembly file with the following content, assemble it for 386:

DATA bar<>(SB)/4, $0x0
GLOBL bar<>(SB), 0, $4

TEXT foo<>(SB), 4, $0
	MOVL bar<>(SB)(AX), AX

Then, dump the resulting object file.

What did you expect to see?

Something like

TEXT foo<1>(SB) gofile../.../bug.s
  bug.s:5		0x142			8b0500000000		MOVL 0(AX), AX		[2:6]R_ADDR:bar		

What did you see instead?

TEXT foo<1>(SB) gofile../.../bug.s
  bug.s:5		0x142			8b0500000000		MOVL 0, AX		[2:6]R_ADDR:bar		

It appears that the index register has been dropped silently. Please either fail this kind of code during assembly or add support for indexing into global symbols.

Activity

  1. cherrymui commented on Sep 9, 2020

    @cherrymui
    Member

    Index into a global symbol is not a supported addressing mode. We should emit an error.

  2. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Sep 10, 2020
  3. added this to the Unplanned milestone on Sep 10, 2020
  4. gopherbot commented on Oct 19, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/850566 mentions this issue: cmd/internal/obj/x86: reject base register on global symbol references

  5. added a commit that references this issue on Nov 6, 2026
    5d76a1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions