1
0
mirror of https://github.com/golang/go synced 2024-11-19 05:34:40 -07:00

cmd/link: eliminate a bunch of open coded elf64/rela switches

We already have variables to track whether the target platform is
64-bit vs 32-bit or RELA vs REL, so no point in repeating the list of
obscure architecture characters everywhere.

Passes toolstash/buildall.

Change-Id: I6a07f74188ac592ef229a7c65848a9ba93013cdb
Reviewed-on: https://go-review.googlesource.com/21569
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Matthew Dempsky 2016-04-05 23:01:10 -07:00
parent 63cea5ac2b
commit ec3c5b9d17
3 changed files with 12 additions and 25 deletions

View File

@ -2169,18 +2169,10 @@ func dwarfaddshstrings(shstrtab *LSym) {
elfstrdbg[ElfStrDebugStr] = Addstring(shstrtab, ".debug_str") elfstrdbg[ElfStrDebugStr] = Addstring(shstrtab, ".debug_str")
elfstrdbg[ElfStrGDBScripts] = Addstring(shstrtab, ".debug_gdb_scripts") elfstrdbg[ElfStrGDBScripts] = Addstring(shstrtab, ".debug_gdb_scripts")
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
switch Thearch.Thechar { elfstrdbg[ElfStrRelDebugInfo] = Addstring(shstrtab, elfRelType+".debug_info")
case '0', '6', '7', '9', 'z': elfstrdbg[ElfStrRelDebugAranges] = Addstring(shstrtab, elfRelType+".debug_aranges")
elfstrdbg[ElfStrRelDebugInfo] = Addstring(shstrtab, ".rela.debug_info") elfstrdbg[ElfStrRelDebugLine] = Addstring(shstrtab, elfRelType+".debug_line")
elfstrdbg[ElfStrRelDebugAranges] = Addstring(shstrtab, ".rela.debug_aranges") elfstrdbg[ElfStrRelDebugFrame] = Addstring(shstrtab, elfRelType+".debug_frame")
elfstrdbg[ElfStrRelDebugLine] = Addstring(shstrtab, ".rela.debug_line")
elfstrdbg[ElfStrRelDebugFrame] = Addstring(shstrtab, ".rela.debug_frame")
default:
elfstrdbg[ElfStrRelDebugInfo] = Addstring(shstrtab, ".rel.debug_info")
elfstrdbg[ElfStrRelDebugAranges] = Addstring(shstrtab, ".rel.debug_aranges")
elfstrdbg[ElfStrRelDebugLine] = Addstring(shstrtab, ".rel.debug_line")
elfstrdbg[ElfStrRelDebugFrame] = Addstring(shstrtab, ".rel.debug_frame")
}
infosym = Linklookup(Ctxt, ".debug_info", 0) infosym = Linklookup(Ctxt, ".debug_info", 0)
infosym.Attr |= AttrHidden infosym.Attr |= AttrHidden
@ -2222,10 +2214,9 @@ func dwarfaddelfsectionsyms() {
func dwarfaddelfrelocheader(elfstr int, shdata *ElfShdr, off int64, size int64) { func dwarfaddelfrelocheader(elfstr int, shdata *ElfShdr, off int64, size int64) {
sh := newElfShdr(elfstrdbg[elfstr]) sh := newElfShdr(elfstrdbg[elfstr])
switch Thearch.Thechar { if elfRelType == ".rela" {
case '0', '6', '7', '9', 'z':
sh.type_ = SHT_RELA sh.type_ = SHT_RELA
default: } else {
sh.type_ = SHT_REL sh.type_ = SHT_REL
} }

View File

@ -1885,10 +1885,9 @@ func doelf() {
s.Type = obj.SELFROSECT s.Type = obj.SELFROSECT
s.Attr |= AttrReachable s.Attr |= AttrReachable
switch Thearch.Thechar { if elf64 {
case '0', '6', '7', '9', 'z':
s.Size += ELF64SYMSIZE s.Size += ELF64SYMSIZE
default: } else {
s.Size += ELF32SYMSIZE s.Size += ELF32SYMSIZE
} }
@ -1967,10 +1966,9 @@ func doelf() {
elfwritedynentsym(s, DT_HASH, Linklookup(Ctxt, ".hash", 0)) elfwritedynentsym(s, DT_HASH, Linklookup(Ctxt, ".hash", 0))
elfwritedynentsym(s, DT_SYMTAB, Linklookup(Ctxt, ".dynsym", 0)) elfwritedynentsym(s, DT_SYMTAB, Linklookup(Ctxt, ".dynsym", 0))
switch Thearch.Thechar { if elf64 {
case '0', '6', '7', '9', 'z':
Elfwritedynent(s, DT_SYMENT, ELF64SYMSIZE) Elfwritedynent(s, DT_SYMENT, ELF64SYMSIZE)
default: } else {
Elfwritedynent(s, DT_SYMENT, ELF32SYMSIZE) Elfwritedynent(s, DT_SYMENT, ELF32SYMSIZE)
} }
elfwritedynentsym(s, DT_STRTAB, Linklookup(Ctxt, ".dynstr", 0)) elfwritedynentsym(s, DT_STRTAB, Linklookup(Ctxt, ".dynstr", 0))

View File

@ -66,8 +66,7 @@ func putelfstr(s string) int {
} }
func putelfsyment(off int, addr int64, size int64, info int, shndx int, other int) { func putelfsyment(off int, addr int64, size int64, info int, shndx int, other int) {
switch Thearch.Thechar { if elf64 {
case '0', '6', '7', '9', 'z':
Thearch.Lput(uint32(off)) Thearch.Lput(uint32(off))
Cput(uint8(info)) Cput(uint8(info))
Cput(uint8(other)) Cput(uint8(other))
@ -75,8 +74,7 @@ func putelfsyment(off int, addr int64, size int64, info int, shndx int, other in
Thearch.Vput(uint64(addr)) Thearch.Vput(uint64(addr))
Thearch.Vput(uint64(size)) Thearch.Vput(uint64(size))
Symsize += ELF64SYMSIZE Symsize += ELF64SYMSIZE
} else {
default:
Thearch.Lput(uint32(off)) Thearch.Lput(uint32(off))
Thearch.Lput(uint32(addr)) Thearch.Lput(uint32(addr))
Thearch.Lput(uint32(size)) Thearch.Lput(uint32(size))