Skip to content

cmd/go: confusing error when using cgo with Go assembly code #19448

@FiloSottile

Description

@FiloSottile

Currently if a package has a import "C" all .s files will be compiled by the C compiler, which of course rejects Go assembly.

When the Go tool sees that one or more Go files use the special import "C", it will look for other non-Go files in the directory and compile them as part of the Go package. Any .c, .s, or .S files will be compiled with the C compiler.

clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/github.com/FiloSottile/cgo-assembly/_obj/ -g -O2 -o $WORK/github.com/FiloSottile/cgo-assembly/_obj/add_amd64.o -c ./add_amd64.s
# github.com/FiloSottile/cgo-assembly
./add_amd64.s:1:24: error: unexpected token in memory operand
DATA p256const0<>+0x00(SB)/8, $0x00000000ffffffff
                       ^

I suspect this is asking too much, but it would be useful if there was a way to still compile assembly files with the Go assembler in a cgo package.

As a lower bar, it would be useful to get more meaningful error messages, as syntax errors appearing when adding import "C" in a different file are pretty obscure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions