]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: eliminate a bunch of open coded elf64/rela switches
authorMatthew Dempsky <mdempsky@google.com>
Wed, 6 Apr 2016 06:01:10 +0000 (23:01 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 6 Apr 2016 17:25:19 +0000 (17:25 +0000)
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>
src/cmd/link/internal/ld/dwarf.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/symtab.go

index fd177cfef0895a64daf7c082508bb01ef5777746..4465a727a5520c4a39528c57dd7d89d73db2bed0 100644 (file)
@@ -2169,18 +2169,10 @@ func dwarfaddshstrings(shstrtab *LSym) {
        elfstrdbg[ElfStrDebugStr] = Addstring(shstrtab, ".debug_str")
        elfstrdbg[ElfStrGDBScripts] = Addstring(shstrtab, ".debug_gdb_scripts")
        if Linkmode == LinkExternal {
-               switch Thearch.Thechar {
-               case '0', '6', '7', '9', 'z':
-                       elfstrdbg[ElfStrRelDebugInfo] = Addstring(shstrtab, ".rela.debug_info")
-                       elfstrdbg[ElfStrRelDebugAranges] = Addstring(shstrtab, ".rela.debug_aranges")
-                       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")
-               }
+               elfstrdbg[ElfStrRelDebugInfo] = Addstring(shstrtab, elfRelType+".debug_info")
+               elfstrdbg[ElfStrRelDebugAranges] = Addstring(shstrtab, elfRelType+".debug_aranges")
+               elfstrdbg[ElfStrRelDebugLine] = Addstring(shstrtab, elfRelType+".debug_line")
+               elfstrdbg[ElfStrRelDebugFrame] = Addstring(shstrtab, elfRelType+".debug_frame")
 
                infosym = Linklookup(Ctxt, ".debug_info", 0)
                infosym.Attr |= AttrHidden
@@ -2222,10 +2214,9 @@ func dwarfaddelfsectionsyms() {
 
 func dwarfaddelfrelocheader(elfstr int, shdata *ElfShdr, off int64, size int64) {
        sh := newElfShdr(elfstrdbg[elfstr])
-       switch Thearch.Thechar {
-       case '0', '6', '7', '9', 'z':
+       if elfRelType == ".rela" {
                sh.type_ = SHT_RELA
-       default:
+       } else {
                sh.type_ = SHT_REL
        }
 
index ffb7c4bddefa43ae3a2e25eda83c1e2892e1be3d..3b40c6659287364073b917622d7e0951348bec76 100644 (file)
@@ -1885,10 +1885,9 @@ func doelf() {
 
                s.Type = obj.SELFROSECT
                s.Attr |= AttrReachable
-               switch Thearch.Thechar {
-               case '0', '6', '7', '9', 'z':
+               if elf64 {
                        s.Size += ELF64SYMSIZE
-               default:
+               } else {
                        s.Size += ELF32SYMSIZE
                }
 
@@ -1967,10 +1966,9 @@ func doelf() {
                elfwritedynentsym(s, DT_HASH, Linklookup(Ctxt, ".hash", 0))
 
                elfwritedynentsym(s, DT_SYMTAB, Linklookup(Ctxt, ".dynsym", 0))
-               switch Thearch.Thechar {
-               case '0', '6', '7', '9', 'z':
+               if elf64 {
                        Elfwritedynent(s, DT_SYMENT, ELF64SYMSIZE)
-               default:
+               } else {
                        Elfwritedynent(s, DT_SYMENT, ELF32SYMSIZE)
                }
                elfwritedynentsym(s, DT_STRTAB, Linklookup(Ctxt, ".dynstr", 0))
index 3258bc1ff9d625ee46ca97712f1adc083234c0da..0fe0a68c65e942792e00c1a9b94d355b3a1979e2 100644 (file)
@@ -66,8 +66,7 @@ func putelfstr(s string) int {
 }
 
 func putelfsyment(off int, addr int64, size int64, info int, shndx int, other int) {
-       switch Thearch.Thechar {
-       case '0', '6', '7', '9', 'z':
+       if elf64 {
                Thearch.Lput(uint32(off))
                Cput(uint8(info))
                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(size))
                Symsize += ELF64SYMSIZE
-
-       default:
+       } else {
                Thearch.Lput(uint32(off))
                Thearch.Lput(uint32(addr))
                Thearch.Lput(uint32(size))