summaryrefslogtreecommitdiffstats
path: root/src/cmd/link/internal/sym/symbol.go
blob: 2f2c839006f11d4fbd7b328af63f2d2a8d8def82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sym

import (
	"cmd/internal/obj"
	"internal/buildcfg"
)

const (
	SymVerABI0        = 0
	SymVerABIInternal = 1
	SymVerABICount    = 2  // Number of internal ABIs
	SymVerStatic      = 10 // Minimum version used by static (file-local) syms
)

func ABIToVersion(abi obj.ABI) int {
	switch abi {
	case obj.ABI0:
		return SymVerABI0
	case obj.ABIInternal:
		if !buildcfg.Experiment.RegabiWrappers {
			// If wrappers are not enabled, ABI0 and ABIInternal are actually same
			// so we normalize everything to ABI0.
			return SymVerABI0
		}
		return SymVerABIInternal
	}
	return -1
}

func VersionToABI(v int) (obj.ABI, bool) {
	switch v {
	case SymVerABI0:
		return obj.ABI0, true
	case SymVerABIInternal:
		return obj.ABIInternal, true
	}
	return ^obj.ABI(0), false
}