aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-06-02 12:17:03 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-06-04 09:50:32 +0000
commit11f2afa5a3c8cc88e10b001d6eb8790c8a3b91a7 (patch)
treeaed911ddb145445af02d18db7c0e73699522c2ef
parent06bf8101debe879447d0ef3a7a5b84cb11fa5acf (diff)
sys/targets: mark big-endian targets
Litte-endian is kind of default (except for s390). So instead of saying that each arch is litte-endian, mark only s390 as big-endian.
-rw-r--r--pkg/csource/csource.go4
-rw-r--r--pkg/report/linux.go12
-rw-r--r--pkg/runtest/run.go2
-rw-r--r--prog/target.go16
-rw-r--r--sys/syz-sysgen/sysgen.go4
-rw-r--r--sys/targets/targets.go77
-rw-r--r--sys/test/test/align02
-rw-r--r--sys/test/test/align0_be2
-rw-r--r--sys/test/test/bf2
-rw-r--r--sys/test/test/bf22
-rw-r--r--sys/test/test/bf2_be2
-rw-r--r--sys/test/test/bf_be2
-rw-r--r--sys/test/test/expressions4
-rw-r--r--sys/test/test/nla2
-rw-r--r--sys/test/test/overlay2
-rw-r--r--sys/test/test/overlay_be2
16 files changed, 55 insertions, 82 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 1f338b893..198ddf7df 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -409,11 +409,11 @@ func (ctx *context) copyin(w *bytes.Buffer, csumSeq *int, copyin prog.ExecCopyin
panic("bitfield+string format")
}
htobe := ""
- if ctx.target.LittleEndian && arg.Format == prog.FormatBigEndian {
+ if !ctx.target.BigEndian && arg.Format == prog.FormatBigEndian {
htobe = fmt.Sprintf("htobe%v", arg.Size*8)
}
bitfieldOffset := arg.BitfieldOffset
- if !ctx.target.LittleEndian {
+ if ctx.target.BigEndian {
bitfieldOffset = arg.Size*8 - arg.BitfieldOffset - arg.BitfieldLength
}
fmt.Fprintf(w, "\tNONFAILING(STORE_BY_BITMASK(uint%v, %v, 0x%x, %v, %v, %v));\n",
diff --git a/pkg/report/linux.go b/pkg/report/linux.go
index 50877e382..1dd5879cf 100644
--- a/pkg/report/linux.go
+++ b/pkg/report/linux.go
@@ -5,7 +5,6 @@ package report
import (
"bytes"
- "encoding/binary"
"fmt"
"path/filepath"
"regexp"
@@ -580,11 +579,6 @@ func (ctx *linux) decompileWithOffset(parsed parsedOpcodes) (*decompiledOpcodes,
}
func (ctx *linux) parseOpcodes(codeSlice string) (parsedOpcodes, error) {
- binaryOps := binary.ByteOrder(binary.BigEndian)
- if ctx.target.LittleEndian {
- binaryOps = binary.LittleEndian
- }
-
width := 0
bytes := []byte{}
trapOffset := -1
@@ -620,11 +614,11 @@ func (ctx *linux) parseOpcodes(codeSlice string) (parsedOpcodes, error) {
case 1:
extraBytes[0] = byte(number)
case 2:
- binaryOps.PutUint16(extraBytes, uint16(number))
+ ctx.target.HostEndian.PutUint16(extraBytes, uint16(number))
case 4:
- binaryOps.PutUint32(extraBytes, uint32(number))
+ ctx.target.HostEndian.PutUint32(extraBytes, uint32(number))
case 8:
- binaryOps.PutUint64(extraBytes, number)
+ ctx.target.HostEndian.PutUint64(extraBytes, number)
default:
return parsedOpcodes{}, fmt.Errorf("invalid opcodes string: invalid width %v", width)
}
diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go
index 79d47d603..e0bf59816 100644
--- a/pkg/runtest/run.go
+++ b/pkg/runtest/run.go
@@ -232,7 +232,7 @@ nextSandbox:
properties := map[string]bool{
"manual": ctx.Tests != "", // "manual" tests run only if selected by the filter explicitly.
"sandbox=" + sandbox: true,
- "littleendian": ctx.Target.LittleEndian,
+ "bigendian": sysTarget.BigEndian,
}
for _, threaded := range []bool{false, true} {
name := name
diff --git a/prog/target.go b/prog/target.go
index 4ac0e9a27..d32d8a8ae 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -14,14 +14,14 @@ import (
// Target describes target OS/arch pair.
type Target struct {
- OS string
- Arch string
- Revision string // unique hash representing revision of the descriptions
- PtrSize uint64
- PageSize uint64
- NumPages uint64
- DataOffset uint64
- LittleEndian bool
+ OS string
+ Arch string
+ Revision string // unique hash representing revision of the descriptions
+ PtrSize uint64
+ PageSize uint64
+ NumPages uint64
+ DataOffset uint64
+ BigEndian bool
Syscalls []*Syscall
Resources []*ResourceDesc
diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go
index 0022cea12..f03972a9f 100644
--- a/sys/syz-sysgen/sysgen.go
+++ b/sys/syz-sysgen/sysgen.go
@@ -251,11 +251,11 @@ func generate(target *targets.Target, prg *compiler.Prog, consts map[string]uint
fmt.Fprintf(out, "func init() {\n")
fmt.Fprintf(out, "\tRegisterTarget(&Target{"+
"OS: %q, Arch: %q, Revision: revision_%v, PtrSize: %v, PageSize: %v, "+
- "NumPages: %v, DataOffset: %v, LittleEndian: %v, "+
+ "NumPages: %v, DataOffset: %v, BigEndian: %v, "+
"Syscalls: syscalls_%v, Resources: resources_%v, Consts: consts_%v,"+
"Flags: flags_%v}, types_%v, InitTarget)\n}\n\n",
target.OS, target.Arch, target.Arch, target.PtrSize, target.PageSize,
- target.NumPages, target.DataOffset, target.LittleEndian,
+ target.NumPages, target.DataOffset, target.BigEndian,
target.Arch, target.Arch, target.Arch, target.Arch, target.Arch)
fmt.Fprintf(out, "var resources_%v = ", target.Arch)
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index 5483897a1..4e3e37e66 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -25,7 +25,7 @@ type Target struct {
NumPages uint64
DataOffset uint64
Int64Alignment uint64
- LittleEndian bool
+ BigEndian bool
CFlags []string
CxxFlags []string
Triple string
@@ -250,7 +250,6 @@ var List = map[string]map[string]*Target{
AMD64: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
CFlags: []string{"-m64"},
Triple: "x86_64-linux-gnu",
KernelArch: "x86_64",
@@ -266,7 +265,6 @@ var List = map[string]map[string]*Target{
PtrSize: 4,
PageSize: 4 << 10,
Int64Alignment: 4,
- LittleEndian: true,
CFlags: []string{"-m32"},
Triple: "x86_64-linux-gnu",
KernelArch: "i386",
@@ -275,7 +273,6 @@ var List = map[string]map[string]*Target{
ARM64: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
Triple: "aarch64-linux-gnu",
KernelArch: "arm64",
KernelHeaderArch: "arm64",
@@ -284,7 +281,6 @@ var List = map[string]map[string]*Target{
VMArch: ARM64,
PtrSize: 4,
PageSize: 4 << 10,
- LittleEndian: true,
CFlags: []string{"-D__LINUX_ARM_ARCH__=6", "-march=armv6"},
Triple: "arm-linux-gnueabi",
KernelArch: "arm",
@@ -293,7 +289,6 @@ var List = map[string]map[string]*Target{
MIPS64LE: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
CFlags: []string{"-march=mips64r2", "-mabi=64", "-EL"},
Triple: "mips64el-linux-gnuabi64",
KernelArch: "mips",
@@ -302,7 +297,6 @@ var List = map[string]map[string]*Target{
PPC64LE: {
PtrSize: 8,
PageSize: 64 << 10,
- LittleEndian: true,
CFlags: []string{"-D__powerpc64__"},
Triple: "powerpc64le-linux-gnu",
KernelArch: "powerpc",
@@ -313,7 +307,7 @@ var List = map[string]map[string]*Target{
PageSize: 4 << 10,
DataOffset: 0xfffff000,
CFlags: []string{"-fPIE"},
- LittleEndian: false,
+ BigEndian: true,
Triple: "s390x-linux-gnu",
KernelArch: "s390",
KernelHeaderArch: "s390",
@@ -328,7 +322,6 @@ var List = map[string]map[string]*Target{
RiscV64: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
Triple: "riscv64-linux-gnu",
KernelArch: "riscv",
KernelHeaderArch: "riscv",
@@ -336,22 +329,20 @@ var List = map[string]map[string]*Target{
},
FreeBSD: {
AMD64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- LittleEndian: true,
- CCompiler: "clang",
- CFlags: []string{"-m64", "--target=x86_64-unknown-freebsd14.0"},
+ PtrSize: 8,
+ PageSize: 4 << 10,
+ CCompiler: "clang",
+ CFlags: []string{"-m64", "--target=x86_64-unknown-freebsd14.0"},
NeedSyscallDefine: func(nr uint64) bool {
// freebsd_12_shm_open, shm_open2, shm_rename, __realpathat, close_range, copy_file_range
return nr == 482 || nr >= 569
},
},
ARM64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- LittleEndian: true,
- CCompiler: "clang",
- CFlags: []string{"-m64", "--target=aarch64-unknown-freebsd14.0"},
+ PtrSize: 8,
+ PageSize: 4 << 10,
+ CCompiler: "clang",
+ CFlags: []string{"-m64", "--target=aarch64-unknown-freebsd14.0"},
NeedSyscallDefine: func(nr uint64) bool {
// freebsd_12_shm_open, shm_open2, shm_rename, __realpathat, close_range, copy_file_range
return nr == 482 || nr >= 569
@@ -365,7 +356,6 @@ var List = map[string]map[string]*Target{
// FreeBSD and using ld.lld due to collisions.
DataOffset: 256 << 20,
Int64Alignment: 4,
- LittleEndian: true,
CCompiler: "clang",
CFlags: []string{"-m32", "--target=i386-unknown-freebsd14.0"},
NeedSyscallDefine: func(nr uint64) bool {
@@ -374,11 +364,10 @@ var List = map[string]map[string]*Target{
},
},
RiscV64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- LittleEndian: true,
- CCompiler: "clang",
- CFlags: []string{"-m64", "--target=riscv64-unknown-freebsd14.0"},
+ PtrSize: 8,
+ PageSize: 4 << 10,
+ CCompiler: "clang",
+ CFlags: []string{"-m64", "--target=riscv64-unknown-freebsd14.0"},
NeedSyscallDefine: func(nr uint64) bool {
// freebsd_12_shm_open, shm_open2, shm_rename, __realpathat, close_range, copy_file_range
return nr == 482 || nr >= 569
@@ -387,11 +376,10 @@ var List = map[string]map[string]*Target{
},
Darwin: {
AMD64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- DataOffset: 512 << 24,
- LittleEndian: true,
- CCompiler: "clang",
+ PtrSize: 8,
+ PageSize: 4 << 10,
+ DataOffset: 512 << 24,
+ CCompiler: "clang",
CFlags: []string{
"-m64",
"-I", sourceDirVar + "/san",
@@ -403,9 +391,8 @@ var List = map[string]map[string]*Target{
},
NetBSD: {
AMD64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- LittleEndian: true,
+ PtrSize: 8,
+ PageSize: 4 << 10,
CFlags: []string{
"-m64",
"-static-pie",
@@ -416,10 +403,9 @@ var List = map[string]map[string]*Target{
},
OpenBSD: {
AMD64: {
- PtrSize: 8,
- PageSize: 4 << 10,
- LittleEndian: true,
- CCompiler: "c++",
+ PtrSize: 8,
+ PageSize: 4 << 10,
+ CCompiler: "c++",
// PIE is enabled on OpenBSD by default, so no need for -static-pie.
CFlags: []string{"-m64", "-static", "-lutil"},
NeedSyscallDefine: func(nr uint64) bool {
@@ -453,7 +439,6 @@ var List = map[string]map[string]*Target{
AMD64: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
KernelHeaderArch: "x64",
CCompiler: sourceDirVar + "/prebuilt/third_party/clang/linux-x64/bin/clang",
Objdump: sourceDirVar + "/prebuilt/third_party/clang/linux-x64/bin/llvm-objdump",
@@ -462,7 +447,6 @@ var List = map[string]map[string]*Target{
ARM64: {
PtrSize: 8,
PageSize: 4 << 10,
- LittleEndian: true,
KernelHeaderArch: ARM64,
CCompiler: sourceDirVar + "/prebuilt/third_party/clang/linux-x64/bin/clang",
Objdump: sourceDirVar + "/prebuilt/third_party/clang/linux-x64/bin/llvm-objdump",
@@ -473,15 +457,13 @@ var List = map[string]map[string]*Target{
AMD64: {
PtrSize: 8,
// TODO(dvyukov): what should we do about 4k vs 64k?
- PageSize: 4 << 10,
- LittleEndian: true,
+ PageSize: 4 << 10,
},
},
Trusty: {
ARM: {
PtrSize: 4,
PageSize: 4 << 10,
- LittleEndian: true,
NeedSyscallDefine: dontNeedSyscallDefine,
},
},
@@ -738,15 +720,12 @@ func initTarget(target *Target, OS, arch string) {
target.CFlags = append(target.CFlags, flags...)
}
if OS == TestOS {
- if runtime.GOARCH != S390x {
- target.LittleEndian = true
- } else {
- target.LittleEndian = false
+ if runtime.GOARCH == S390x {
+ target.BigEndian = true
}
}
- if target.LittleEndian {
- target.HostEndian = binary.LittleEndian
- } else {
+ target.HostEndian = binary.LittleEndian
+ if target.BigEndian {
target.HostEndian = binary.BigEndian
}
// Temporal hack.
diff --git a/sys/test/test/align0 b/sys/test/test/align0
index e2aaf61ee..fd78e5032 100644
--- a/sys/test/test/align0
+++ b/sys/test/test/align0
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 littleendian
+# requires: -arch=32 -bigendian
syz_compare(&AUTO="010000000200000003000400000000000500000000000000", 0x18, &AUTO=@align0={0x1, 0x2, 0x3, 0x4, 0x5}, AUTO)
syz_compare(&AUTO="", 0x18, &AUTO=@align0={0x0, 0x0, 0x0, 0x0, 0x0}, 0x17) # EBADF
diff --git a/sys/test/test/align0_be b/sys/test/test/align0_be
index f9072e841..26463e154 100644
--- a/sys/test/test/align0_be
+++ b/sys/test/test/align0_be
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 -littleendian
+# requires: -arch=32 bigendian
syz_compare(&AUTO="000100000000000203000004000000000000000000000005", 0x18, &AUTO=@align0={0x1, 0x2, 0x3, 0x4, 0x5}, AUTO)
syz_compare(&AUTO="", 0x18, &AUTO=@align0={0x0, 0x0, 0x0, 0x0, 0x0}, 0x17) # EBADF
diff --git a/sys/test/test/bf b/sys/test/test/bf
index 6d7bb6364..ddd329b5c 100644
--- a/sys/test/test/bf
+++ b/sys/test/test/bf
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 littleendian
+# requires: -arch=32 -bigendian
syz_compare(&AUTO="ab03000000000000cdcdcdcdcdcdcdcdebffff03ab0303abaa00000000000000", 0x20, &AUTO=@bf0={0xabab, 0xcdcdcdcdcdcdcdcd, 0xabab, 0xffff, 0xffffff, 0xabab, 0xabab, 0xaaa}, AUTO)
syz_compare(&AUTO="dcfcde563422f10e", 0x8, &AUTO=@bf2={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, AUTO)
diff --git a/sys/test/test/bf2 b/sys/test/test/bf2
index 82b9a0a1f..4ed1b7540 100644
--- a/sys/test/test/bf2
+++ b/sys/test/test/bf2
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 littleendian
+# requires: -arch=32 -bigendian
syz_compare(&AUTO="1200000034067800", AUTO, &AUTO=@bf4={0x12, {0x34, 0x56, 0x78}}, AUTO)
syz_compare(&AUTO="1200000034060000", AUTO, &AUTO=@bf5={0x12, {0x34, 0x56}}, AUTO)
diff --git a/sys/test/test/bf2_be b/sys/test/test/bf2_be
index 1c39a9f99..d3c715e86 100644
--- a/sys/test/test/bf2_be
+++ b/sys/test/test/bf2_be
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 -littleendian
+# requires: -arch=32 bigendian
syz_compare(&AUTO="1200000034607800", AUTO, &AUTO=@bf4={0x12, {0x34, 0x56, 0x78}}, AUTO)
syz_compare(&AUTO="1200000034600000", AUTO, &AUTO=@bf5={0x12, {0x34, 0x56}}, AUTO)
diff --git a/sys/test/test/bf_be b/sys/test/test/bf_be
index b03794e91..cd6f4a73b 100644
--- a/sys/test/test/bf_be
+++ b/sys/test/test/bf_be
@@ -1,5 +1,5 @@
# 32 has 4-byte alignment for int64 and everything goes havoc.
-# requires: -arch=32 -littleendian
+# requires: -arch=32 bigendian
syz_compare(&AUTO="eac0000000000000cdcdcdcdcdcdcdcd5fffffc075607560aa", 0x20, &AUTO=@bf0={0xabab, 0xcdcdcdcdcdcdcdcd, 0xabab, 0xffff, 0xffffff, 0xabab, 0xabab, 0xaaa}, AUTO)
syz_compare(&AUTO="ccddef23456ef120", 0x8, &AUTO=@bf2={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, AUTO)
diff --git a/sys/test/test/expressions b/sys/test/test/expressions
index 9ecaaf30c..63100c05c 100644
--- a/sys/test/test/expressions
+++ b/sys/test/test/expressions
@@ -1,4 +1,4 @@
-# requires: littleendian
+# requires: -bigendian
syz_compare(&AUTO="00000000", 0x4, &AUTO=@conditional={0x0, @void, @void}, AUTO)
syz_compare(&AUTO="02000000ffffffff", 0x8, &AUTO=@conditional={0x2, @value={AUTO}, @void}, AUTO)
@@ -7,4 +7,4 @@ syz_compare(&AUTO="06000000ffffffffaaaa000000000000", 0x10, &AUTO=@conditional={
syz_compare(&AUTO="00ff0000", 0x4, &AUTO=@conditional2={0x0, @void, 0xff}, AUTO)
syz_compare(&AUTO="0134120000ff0000", 0x8, &AUTO=@conditional2={0x1, @value=0x1234, 0xff}, AUTO)
syz_compare(&AUTO="1100220000330000", 0x8, &AUTO=@conditional3={0x11, {0x0, @void, 0x22}, 0x33}, AUTO)
-syz_compare(&AUTO="1101ddccbbaa220000330000", 0xc, &AUTO=@conditional3={0x11, {0x1, @value=0xaabbccdd, 0x22}, 0x33}, AUTO) \ No newline at end of file
+syz_compare(&AUTO="1101ddccbbaa220000330000", 0xc, &AUTO=@conditional3={0x11, {0x1, @value=0xaabbccdd, 0x22}, 0x33}, AUTO)
diff --git a/sys/test/test/nla b/sys/test/test/nla
index b2c5bf1a9..bb7c74275 100644
--- a/sys/test/test/nla
+++ b/sys/test/test/nla
@@ -1,4 +1,4 @@
-# requires: littleendian
+# requires: -bigendian
syz_compare(&AUTO="0500aa0055000000", AUTO, &AUTO=@nla=[@a0={AUTO, AUTO, 0x55, ''}], AUTO)
syz_compare(&AUTO="0600bb0055550000", AUTO, &AUTO=@nla=[@a1={AUTO, AUTO, 0x5555, ''}], AUTO)
diff --git a/sys/test/test/overlay b/sys/test/test/overlay
index e15d62b5e..0dbf49ed6 100644
--- a/sys/test/test/overlay
+++ b/sys/test/test/overlay
@@ -1,4 +1,4 @@
-# requires: littleendian
+# requires: -bigendian
syz_compare(&AUTO="1111111122222222", AUTO, &AUTO=@overlay0={0x11111111, 0x22222222, <r0=>0x0, <r1=>0x0}, AUTO)
syz_compare(&AUTO="11111111", AUTO, &AUTO=@overlayres=@res32=r0, AUTO)
diff --git a/sys/test/test/overlay_be b/sys/test/test/overlay_be
index b1eb65f8d..91f7c9f69 100644
--- a/sys/test/test/overlay_be
+++ b/sys/test/test/overlay_be
@@ -1,4 +1,4 @@
-# requires: -littleendian
+# requires: bigendian
syz_compare(&AUTO="1111111122222222", AUTO, &AUTO=@overlay0={0x11111111, 0x22222222, <r0=>0x0, <r1=>0x0}, AUTO)
syz_compare(&AUTO="11111111", AUTO, &AUTO=@overlayres=@res32=r0, AUTO)