Programing

Go가 내 어셈블리를 연결하지 않음 : 정의되지 않은 외부 함수

lottogame 2020. 10. 6. 07:42
반응형

Go가 내 어셈블리를 연결하지 않음 : 정의되지 않은 외부 함수


주로 학습 목적으로 SIMD를 작성하려고합니다. Go가 어셈블리를 연결할 수 있다는 것을 알고 있지만 제대로 작동하지 않습니다.

다음은 제가 만들 수있는 가장 최소한의 예입니다 (요소 별 벡터 곱셈).

vec_amd64.s (참고 : 실제 파일에는 RET오류가 발생하므로 아래에 공백 줄 이 있습니다.)

// func mul(v1, v2 Vec4) Vec4
TEXT .mul(SB),4,$0-48
    MOVUPS v1+0(FP),  X0
    MOVUPS v2+16(FP), X1
    MULPS  X1, X0
    // also tried ret+32 since I've seen some places do that
    MOVUPS X0, toReturn+32(FP)
    RET

vec.go

package simd

type Vec4 [4]float32

func (v1 Vec4) Mul(v2 Vec4) Vec4 {
    return Vec4{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2], v1[3] * v2[3]}
}

func mul(v1, v2 Vec4) Vec4

simd_test.go

package simd

import (
    "testing"
)

func TestMul(t *testing.T) {
    v1 := Vec4{1, 2, 3, 4}
    v2 := Vec4{5, 6, 7, 8}

    res := v1.Mul(v2)
    res2 := mul(v1, v2)

    // Placeholder until I get it to compile
    if res != res2 {
        t.Fatalf("Expected %v; got %v", res, res2)
    }
}

실행하려고 go test하면 오류가 발생합니다.

# testmain
simd.TestMul: call to external function simd.mul
simd.TestMul: undefined: simd.mul

go env명령은 my GOHOSTARCHto be amd64와 my Go 버전을 1.3으로보고합니다. 문제를 일으키는 아키텍처가 아닌지 확인하기 위해 어셈블리를 사용하는 다른 패키지를 발견하고 _amd64.s하나를 제외한 모든 어셈블리 파일을 삭제 했으며 테스트가 정상적으로 실행되었습니다.

I also tried changing it to an exported identifier in case that was causing weirdness, but no dice. I think I pretty closely followed the template in packages like math/big, so hopefully it's something simple and obvious that I'm missing.

I know that Go is at least trying to use the assembly because if I introduce a syntax error to the .s file the build tool will complain about it.

Edit:

To be clear, go build will compile cleanly, but go test causes the error to appear.


You are using the wrong dot. instead of

TEXT .mul(SB),4,$0-48

write

TEXT ·mul(SB),4,$0-48

and everything works just fine.

참고URL : https://stackoverflow.com/questions/25460967/go-isnt-linking-my-assembly-undefined-external-function

반응형