Commit ea7be517 authored by Russ Cox's avatar Russ Cox

cmd/internal/ld, cmd/internal/obj: delete Ctxt.Endian

Replaced by Ctxt.ByteOrder, which uses the standard binary.ByteOrder type.

Change-Id: I06cec0674c153a9ad75ff937f7eb934891effd0b
Reviewed-on: https://go-review.googlesource.com/6450Reviewed-by: default avatarDave Cheney <dave@cheney.net>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent b38fa898
...@@ -32,6 +32,7 @@ package main ...@@ -32,6 +32,7 @@ package main
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"encoding/binary"
"fmt" "fmt"
"log" "log"
) )
...@@ -185,7 +186,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) { ...@@ -185,7 +186,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
r.Sym = plt r.Sym = plt
r.Add = int64(targ.Plt) r.Add = int64(targ.Plt)
r.Siz = 2 r.Siz = 2
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz) r.Off += int32(r.Siz)
} }
r.Type = ld.R_POWER_TOC r.Type = ld.R_POWER_TOC
...@@ -196,7 +197,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) { ...@@ -196,7 +197,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
r.Sym = plt r.Sym = plt
r.Add = int64(targ.Plt) r.Add = int64(targ.Plt)
r.Siz = 2 r.Siz = 2
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz) r.Off += int32(r.Siz)
} }
r.Type = ld.R_POWER_TOC r.Type = ld.R_POWER_TOC
...@@ -400,7 +401,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -400,7 +401,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
o2 = o2&0xffff0000 | uint32(t)&0xffff o2 = o2&0xffff0000 | uint32(t)&0xffff
// when laid out, the instruction order must always be o1, o2. // when laid out, the instruction order must always be o1, o2.
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o1)<<32 | int64(o2) *val = int64(o1)<<32 | int64(o2)
} else { } else {
*val = int64(o2)<<32 | int64(o1) *val = int64(o2)<<32 | int64(o1)
...@@ -409,7 +410,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -409,7 +410,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
case ld.R_CALLPOWER: case ld.R_CALLPOWER:
// Bits 6 through 29 = (S + A - P) >> 2 // Bits 6 through 29 = (S + A - P) >> 2
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = ld.Be32(s.P[r.Off:]) o1 = ld.Be32(s.P[r.Off:])
} else { } else {
o1 = ld.Le32(s.P[r.Off:]) o1 = ld.Le32(s.P[r.Off:])
...@@ -451,7 +452,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 { ...@@ -451,7 +452,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 {
if r.Variant&ld.RV_CHECK_OVERFLOW != 0 { if r.Variant&ld.RV_CHECK_OVERFLOW != 0 {
// Whether to check for signed or unsigned // Whether to check for signed or unsigned
// overflow depends on the instruction // overflow depends on the instruction
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = ld.Be32(s.P[r.Off-2:]) o1 = ld.Be32(s.P[r.Off-2:])
} else { } else {
o1 = ld.Le32(s.P[r.Off:]) o1 = ld.Le32(s.P[r.Off:])
...@@ -484,7 +485,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 { ...@@ -484,7 +485,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 {
if r.Variant&ld.RV_CHECK_OVERFLOW != 0 { if r.Variant&ld.RV_CHECK_OVERFLOW != 0 {
// Whether to check for signed or unsigned // Whether to check for signed or unsigned
// overflow depends on the instruction // overflow depends on the instruction
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = ld.Be32(s.P[r.Off-2:]) o1 = ld.Be32(s.P[r.Off-2:])
} else { } else {
o1 = ld.Le32(s.P[r.Off:]) o1 = ld.Le32(s.P[r.Off:])
...@@ -507,7 +508,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 { ...@@ -507,7 +508,7 @@ func archrelocvariant(r *ld.Reloc, s *ld.LSym, t int64) int64 {
return int64(int16(t)) return int64(int16(t))
case ld.RV_POWER_DS: case ld.RV_POWER_DS:
if ld.Ctxt.Arch.Endian == ld.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = uint32(ld.Be16(s.P[r.Off:])) o1 = uint32(ld.Be16(s.P[r.Off:]))
} else { } else {
o1 = uint32(ld.Le16(s.P[r.Off:])) o1 = uint32(ld.Le16(s.P[r.Off:]))
......
...@@ -10,7 +10,6 @@ var Linkarm = LinkArch{ ...@@ -10,7 +10,6 @@ var Linkarm = LinkArch{
ByteOrder: binary.LittleEndian, ByteOrder: binary.LittleEndian,
Name: "arm", Name: "arm",
Thechar: '5', Thechar: '5',
Endian: LittleEndian,
Minlc: 4, Minlc: 4,
Ptrsize: 4, Ptrsize: 4,
Regsize: 4, Regsize: 4,
...@@ -20,7 +19,6 @@ var Linkamd64 = LinkArch{ ...@@ -20,7 +19,6 @@ var Linkamd64 = LinkArch{
ByteOrder: binary.LittleEndian, ByteOrder: binary.LittleEndian,
Name: "amd64", Name: "amd64",
Thechar: '6', Thechar: '6',
Endian: LittleEndian,
Minlc: 1, Minlc: 1,
Ptrsize: 8, Ptrsize: 8,
Regsize: 8, Regsize: 8,
...@@ -30,7 +28,6 @@ var Linkamd64p32 = LinkArch{ ...@@ -30,7 +28,6 @@ var Linkamd64p32 = LinkArch{
ByteOrder: binary.LittleEndian, ByteOrder: binary.LittleEndian,
Name: "amd64p32", Name: "amd64p32",
Thechar: '6', Thechar: '6',
Endian: LittleEndian,
Minlc: 1, Minlc: 1,
Ptrsize: 4, Ptrsize: 4,
Regsize: 8, Regsize: 8,
...@@ -40,7 +37,6 @@ var Link386 = LinkArch{ ...@@ -40,7 +37,6 @@ var Link386 = LinkArch{
ByteOrder: binary.LittleEndian, ByteOrder: binary.LittleEndian,
Name: "386", Name: "386",
Thechar: '8', Thechar: '8',
Endian: LittleEndian,
Minlc: 1, Minlc: 1,
Ptrsize: 4, Ptrsize: 4,
Regsize: 4, Regsize: 4,
...@@ -50,7 +46,6 @@ var Linkppc64 = LinkArch{ ...@@ -50,7 +46,6 @@ var Linkppc64 = LinkArch{
ByteOrder: binary.BigEndian, ByteOrder: binary.BigEndian,
Name: "ppc64", Name: "ppc64",
Thechar: '9', Thechar: '9',
Endian: BigEndian,
Minlc: 4, Minlc: 4,
Ptrsize: 8, Ptrsize: 8,
Regsize: 8, Regsize: 8,
...@@ -60,7 +55,6 @@ var Linkppc64le = LinkArch{ ...@@ -60,7 +55,6 @@ var Linkppc64le = LinkArch{
ByteOrder: binary.LittleEndian, ByteOrder: binary.LittleEndian,
Name: "ppc64le", Name: "ppc64le",
Thechar: '9', Thechar: '9',
Endian: LittleEndian,
Minlc: 4, Minlc: 4,
Ptrsize: 8, Ptrsize: 8,
Regsize: 8, Regsize: 8,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package ld package ld
import ( import (
"encoding/binary"
"fmt" "fmt"
"os" "os"
) )
...@@ -755,7 +756,7 @@ func Elfinit() { ...@@ -755,7 +756,7 @@ func Elfinit() {
switch Thearch.Thechar { switch Thearch.Thechar {
// 64-bit architectures // 64-bit architectures
case '9': case '9':
if Ctxt.Arch.Endian == BigEndian { if Ctxt.Arch.ByteOrder == binary.BigEndian {
ehdr.flags = 1 /* Version 1 ABI */ ehdr.flags = 1 /* Version 1 ABI */
} else { } else {
ehdr.flags = 2 /* Version 2 ABI */ ehdr.flags = 2 /* Version 2 ABI */
...@@ -2342,7 +2343,7 @@ elfobj: ...@@ -2342,7 +2343,7 @@ elfobj:
} else { } else {
eh.ident[EI_CLASS] = ELFCLASS32 eh.ident[EI_CLASS] = ELFCLASS32
} }
if Ctxt.Arch.Endian == BigEndian { if Ctxt.Arch.ByteOrder == binary.BigEndian {
eh.ident[EI_DATA] = ELFDATA2MSB eh.ident[EI_DATA] = ELFDATA2MSB
} else { } else {
eh.ident[EI_DATA] = ELFDATA2LSB eh.ident[EI_DATA] = ELFDATA2LSB
......
...@@ -269,11 +269,6 @@ const ( ...@@ -269,11 +269,6 @@ const (
// Link holds the context for writing object code from a compiler // Link holds the context for writing object code from a compiler
// to be linker input or for reading that input into the linker. // to be linker input or for reading that input into the linker.
const (
LittleEndian = 0x04030201
BigEndian = 0x01020304
)
// LinkArch is the definition of a single architecture. // LinkArch is the definition of a single architecture.
/* executable header types */ /* executable header types */
......
...@@ -1066,7 +1066,6 @@ var Linkarm = obj.LinkArch{ ...@@ -1066,7 +1066,6 @@ var Linkarm = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "arm", Name: "arm",
Thechar: '5', Thechar: '5',
Endian: obj.LittleEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span5, Assemble: span5,
Follow: follow, Follow: follow,
......
...@@ -914,7 +914,6 @@ var Link386 = obj.LinkArch{ ...@@ -914,7 +914,6 @@ var Link386 = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "386", Name: "386",
Thechar: '8', Thechar: '8',
Endian: obj.LittleEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span8, Assemble: span8,
Follow: follow, Follow: follow,
......
...@@ -246,7 +246,6 @@ type LinkArch struct { ...@@ -246,7 +246,6 @@ type LinkArch struct {
ByteOrder binary.ByteOrder ByteOrder binary.ByteOrder
Name string Name string
Thechar int Thechar int
Endian int32
Preprocess func(*Link, *LSym) Preprocess func(*Link, *LSym)
Assemble func(*Link, *LSym) Assemble func(*Link, *LSym)
Follow func(*Link, *LSym) Follow func(*Link, *LSym)
...@@ -547,11 +546,6 @@ const ( ...@@ -547,11 +546,6 @@ const (
// Link holds the context for writing object code from a compiler // Link holds the context for writing object code from a compiler
// to be linker input or for reading that input into the linker. // to be linker input or for reading that input into the linker.
const (
LittleEndian = 0x04030201
BigEndian = 0x01020304
)
// LinkArch is the definition of a single architecture. // LinkArch is the definition of a single architecture.
/* executable header types */ /* executable header types */
......
...@@ -31,6 +31,7 @@ package ppc64 ...@@ -31,6 +31,7 @@ package ppc64
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"encoding/binary"
"fmt" "fmt"
"log" "log"
"sort" "sort"
...@@ -2038,7 +2039,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) { ...@@ -2038,7 +2039,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
case 31: /* dword */ case 31: /* dword */
d = vregoff(ctxt, &p.From) d = vregoff(ctxt, &p.From)
if ctxt.Arch.Endian == obj.BigEndian { if ctxt.Arch.ByteOrder == binary.BigEndian {
o1 = uint32(d >> 32) o1 = uint32(d >> 32)
o2 = uint32(d) o2 = uint32(d)
} else { } else {
......
...@@ -970,7 +970,6 @@ var Linkppc64 = obj.LinkArch{ ...@@ -970,7 +970,6 @@ var Linkppc64 = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "ppc64", Name: "ppc64",
Thechar: '9', Thechar: '9',
Endian: obj.BigEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span9, Assemble: span9,
Follow: follow, Follow: follow,
...@@ -986,7 +985,6 @@ var Linkppc64le = obj.LinkArch{ ...@@ -986,7 +985,6 @@ var Linkppc64le = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "ppc64le", Name: "ppc64le",
Thechar: '9', Thechar: '9',
Endian: obj.LittleEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span9, Assemble: span9,
Follow: follow, Follow: follow,
......
...@@ -1116,7 +1116,6 @@ var Linkamd64 = obj.LinkArch{ ...@@ -1116,7 +1116,6 @@ var Linkamd64 = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "amd64", Name: "amd64",
Thechar: '6', Thechar: '6',
Endian: obj.LittleEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span6, Assemble: span6,
Follow: follow, Follow: follow,
...@@ -1132,7 +1131,6 @@ var Linkamd64p32 = obj.LinkArch{ ...@@ -1132,7 +1131,6 @@ var Linkamd64p32 = obj.LinkArch{
Pconv: Pconv, Pconv: Pconv,
Name: "amd64p32", Name: "amd64p32",
Thechar: '6', Thechar: '6',
Endian: obj.LittleEndian,
Preprocess: preprocess, Preprocess: preprocess,
Assemble: span6, Assemble: span6,
Follow: follow, Follow: follow,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment