aboutsummaryrefslogtreecommitdiffstats
path: root/prog/target.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-10-19 19:08:19 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-10-19 19:11:22 +0100
commitecb386fe6f6849c451955e16556d04b388b1fde1 (patch)
tree96b30f75d77e5c950103da0ee202bb42b587265a /prog/target.go
parent9aba67b521aa5a2669f2f0c3cee2c4f46d23a4f3 (diff)
sys: check that target consts are defined
Currently when we get target consts with target.ConstMap["name"] during target initialization, we just get 0 for missing consts. This is error-prone as we can mis-type a const, or a const may be undefined only on some archs (as we have common unix code shared between several OSes). Check that all the consts are actually defined. The check detects several violations, to fix them: 1. move mremap to linux as it's only defined on linux 2. move S_IFMT to openbsd, as it's only defined and used on openbsd 3. define missing MAP_ANONYMOUS for freebsd and netbsd 4. fix extract for netbsd
Diffstat (limited to 'prog/target.go')
-rw-r--r--prog/target.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/prog/target.go b/prog/target.go
index bff59ea4f..db8b1835e 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -169,6 +169,17 @@ func (target *Target) initTarget() {
initAnyTypes(target)
}
+func (target *Target) GetConst(name string) uint64 {
+ if target.ConstMap == nil {
+ panic("GetConst can only be used during target initialization")
+ }
+ v, ok := target.ConstMap[name]
+ if !ok {
+ panic(fmt.Sprintf("const %v is not defined for %v/%v", name, target.OS, target.Arch))
+ }
+ return v
+}
+
type Gen struct {
r *randGen
s *state