Skip to content

Commit

Permalink
sys/linux: switch ppc64le to little-endian
Browse files Browse the repository at this point in the history
make extract recently broke for powerpc on linux-next with:

include/uapi/linux/byteorder/big_endian.h:6:2: error: #error "Unsupported endianness, check your toolchain"
 #error "Unsupported endianness, check your toolchain"

Turns out we always built ppc64le headers as big-endian.
First, kernel was configured as BE.
Then, we used gcc to build an executable program for host
and on x86 gcc does not define __LITTLE_ENDIAN__ so kernel
thought that the toolchain is BE too.

Configure kernel as LE and define __LITTLE_ENDIAN__.

This actually changes values of some consts,
but fortunately just few of them.
  • Loading branch information
dvyukov committed May 13, 2019
1 parent aa8482a commit 000f08b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion executor/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

#if GOARCH_ppc64le
#define GOARCH "ppc64le"
#define SYZ_REVISION "84345e4c9ab2df204d5e2216e1ee380880b1e68c"
#define SYZ_REVISION "dd812ad5534b0a3035b3aecdae9fb6d47a6e2ffa"
#define SYZ_EXECUTOR_USES_FORK_SERVER 1
#define SYZ_EXECUTOR_USES_SHMEM 1
#define SYZ_PAGE_SIZE 4096
Expand Down
14 changes: 7 additions & 7 deletions sys/linux/gen/ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -6368,8 +6368,8 @@ var structDescs_ppc64le = []*KeyedStruct{
&IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int8", FldName: "control", TypeSize: 1}, BitfieldOff: 5, BitfieldLen: 1, BitfieldMdl: true}},
&IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int8", FldName: "version", TypeSize: 1}, BitfieldOff: 6, BitfieldLen: 2}},
&IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int8", FldName: "proto_ctype", TypeSize: 1}}},
&FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "guehdr_flags", FldName: "flags", TypeSize: 2}}, Vals: []uint64{1}, BitMask: true},
&ArrayType{TypeCommon: TypeCommon{TypeName: "array", FldName: "priv", IsVarlen: true}, Type: &FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "guehdr_prov_flags", TypeSize: 4}}, Vals: []uint64{2147483648}, BitMask: true}, Kind: 1, RangeEnd: 1},
&FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "guehdr_flags", FldName: "flags", TypeSize: 2}}, Vals: []uint64{256}, BitMask: true},
&ArrayType{TypeCommon: TypeCommon{TypeName: "array", FldName: "priv", IsVarlen: true}, Type: &FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "guehdr_prov_flags", TypeSize: 4}}, Vals: []uint64{128}, BitMask: true}, Kind: 1, RangeEnd: 1},
}}},
{Key: StructKey{Name: "hashlimit_cfg1"}, Desc: &StructDesc{TypeCommon: TypeCommon{TypeName: "hashlimit_cfg1", TypeSize: 32}, Fields: []Type{
&FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "xt_hashlimit_modes", FldName: "mode", TypeSize: 4}}, Vals: []uint64{1, 2, 4, 8, 16, 32, 64}, BitMask: true},
Expand Down Expand Up @@ -41295,7 +41295,7 @@ var syscalls_ppc64le = []*Syscall{
{NR: 326, Name: "socket$packet", CallName: "socket", Args: []Type{
&ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "domain", TypeSize: 8}}, Val: 17},
&FlagsType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "packet_socket_type", FldName: "type", TypeSize: 8}}, Vals: []uint64{3, 2}},
&ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "proto", TypeSize: 8}}, Val: 3},
&ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "proto", TypeSize: 8}}, Val: 768},
}, Ret: &ResourceType{TypeCommon: TypeCommon{TypeName: "sock_packet", FldName: "ret", TypeSize: 4, ArgDir: 1}}},
{NR: 326, Name: "socket$pppoe", CallName: "socket", Args: []Type{
&ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "domain", TypeSize: 8}}, Val: 24},
Expand Down Expand Up @@ -43987,7 +43987,7 @@ var consts_ppc64le = []ConstValue{
{Name: "ETH_P_AARP", Value: 33011},
{Name: "ETH_P_AF_IUCV", Value: 64507},
{Name: "ETH_P_ALL", Value: 3},
{Name: "ETH_P_ALL_BE", Value: 3},
{Name: "ETH_P_ALL_BE", Value: 768},
{Name: "ETH_P_AOE", Value: 34978},
{Name: "ETH_P_ARCNET", Value: 26},
{Name: "ETH_P_ARP", Value: 2054},
Expand Down Expand Up @@ -44473,8 +44473,8 @@ var consts_ppc64le = []ConstValue{
{Name: "GIO_UNISCRNMAP", Value: 19305},
{Name: "GRND_NONBLOCK", Value: 1},
{Name: "GRND_RANDOM", Value: 2},
{Name: "GUE_FLAG_PRIV", Value: 1},
{Name: "GUE_PFLAG_REMCSUM", Value: 2147483648},
{Name: "GUE_FLAG_PRIV", Value: 256},
{Name: "GUE_PFLAG_REMCSUM", Value: 128},
{Name: "HASH_ALGO__LAST", Value: 20},
{Name: "HCIBLOCKADDR", Value: 2147764454},
{Name: "HCIDEVDOWN", Value: 2147764426},
Expand Down Expand Up @@ -50590,4 +50590,4 @@ var consts_ppc64le = []ConstValue{
{Name: "bpf_insn_load_imm_dw", Value: 24},
}

const revision_ppc64le = "84345e4c9ab2df204d5e2216e1ee380880b1e68c"
const revision_ppc64le = "dd812ad5534b0a3035b3aecdae9fb6d47a6e2ffa"
2 changes: 1 addition & 1 deletion sys/linux/socket_packet_ppc64le.const
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARPHRD_ETHER = 1
ETH_P_802_2 = 4
ETH_P_802_3 = 1
ETH_P_ALL = 3
ETH_P_ALL_BE = 3
ETH_P_ALL_BE = 768
ETH_P_ARCNET = 26
ETH_P_AX25 = 2
ETH_P_CAIF = 247
Expand Down
4 changes: 2 additions & 2 deletions sys/linux/vnet_ppc64le.const
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ ETH_P_WAN_PPP = 7
ETH_P_WCCP = 34878
ETH_P_X25 = 2053
ETH_P_XDSA = 248
GUE_FLAG_PRIV = 1
GUE_PFLAG_REMCSUM = 2147483648
GUE_FLAG_PRIV = 256
GUE_PFLAG_REMCSUM = 128
ICMPV6_ADDR_UNREACH = 3
ICMPV6_ADM_PROHIBITED = 1
ICMPV6_DEST_UNREACH = 1
Expand Down
3 changes: 2 additions & 1 deletion sys/syz-extract/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func extract(info *compiler.ConstInfo, cc string, args []string, addSource strin
}
bin, out, err = compile(cc, args, data)
if err != nil {
return nil, nil, fmt.Errorf("failed to run compiler: %v\n%v", err, string(out))
return nil, nil, fmt.Errorf("failed to run compiler: %v %v\n%v\n%v",
cc, args, err, string(out))
}
}
defer os.Remove(bin)
Expand Down
20 changes: 10 additions & 10 deletions sys/syz-extract/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ func (*linux) prepareArch(arch *Arch) error {
if err != nil {
return fmt.Errorf("make defconfig failed: %v\n%s", err, out)
}
// Without CONFIG_NETFILTER kernel does not build.
_, err = osutil.RunCmd(time.Minute, buildDir, "sed", "-i",
"s@# CONFIG_NETFILTER is not set@CONFIG_NETFILTER=y@g", ".config")
_, err = osutil.RunCmd(time.Minute, buildDir, filepath.Join(kernelDir, "scripts", "config"),
// powerpc arch is configured to be big-endian by default, but we want little-endian powerpc.
// Since all of our archs are little-endian for now, we just blindly switch it.
"-d", "CPU_BIG_ENDIAN", "-e", "CPU_LITTLE_ENDIAN",
// Without CONFIG_NETFILTER kernel does not build.
"-e", "NETFILTER",
// include/net/mptcp.h is the only header in kernel that guards some
// of the consts with own config, so we need to enable CONFIG_MPTCP.
"-e", "MPTCP")
if err != nil {
return fmt.Errorf("sed .config failed: %v", err)
}
// include/net/mptcp.h is the only header in kernel that guards some of the consts with own config
_, err = osutil.RunCmd(time.Minute, buildDir, "sed", "-i",
"s@# CONFIG_MPTCP is not set@CONFIG_MPTCP=y@g", ".config")
if err != nil {
return fmt.Errorf("sed .config failed: %v", err)
return err
}
out, err = osutil.RunCmd(time.Hour, kernelDir, "make", append(makeArgs, "olddefconfig")...)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions sys/targets/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ var List = map[string]map[string]*Target{
KernelHeaderArch: "arm",
},
"ppc64le": {
PtrSize: 8,
PageSize: 4 << 10,
CFlags: []string{"-D__powerpc64__"},
PtrSize: 8,
PageSize: 4 << 10,
CFlags: []string{
"-D__powerpc64__",
"-D__LITTLE_ENDIAN__=1",
"-D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__",
},
CrossCFlags: []string{"-D__powerpc64__", "-static"},
CCompilerPrefix: "powerpc64le-linux-gnu-",
KernelArch: "powerpc",
Expand Down

2 comments on commit 000f08b

@dvyukov
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajdlinux FYI
Do you also use LE powerpc?
Either way this is better then what we had before, which was an inconsistent mess which broke recently on linux-next.

@ajdlinux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little-endian, much to the disappointment of many of the hard-line PowerPC purists who have stuck with our architecture from the very beginning, is the way of the future and the configuration which IBM focuses on for Linux.

I'll double check that the changes aren't causing any issues for us when I'm back in the office tomorrow but no objection to making everything LE for now. Adding support for BE is not at all a priority for me right now.

Please sign in to comment.