Source file src/cmd/link/internal/sym/reloc.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sym
     6  
     7  import (
     8  	"cmd/internal/objabi"
     9  	"cmd/internal/sys"
    10  	"debug/elf"
    11  )
    12  
    13  // RelocVariant is a linker-internal variation on a relocation.
    14  type RelocVariant uint8
    15  
    16  const (
    17  	RV_NONE RelocVariant = iota
    18  	RV_POWER_LO
    19  	RV_POWER_HI
    20  	RV_POWER_HA
    21  	RV_POWER_DS
    22  
    23  	// RV_390_DBL is a s390x-specific relocation variant that indicates that
    24  	// the value to be placed into the relocatable field should first be
    25  	// divided by 2.
    26  	RV_390_DBL
    27  
    28  	RV_CHECK_OVERFLOW RelocVariant = 1 << 7
    29  	RV_TYPE_MASK      RelocVariant = RV_CHECK_OVERFLOW - 1
    30  )
    31  
    32  func RelocName(arch *sys.Arch, r objabi.RelocType) string {
    33  	// We didn't have some relocation types at Go1.4.
    34  	// Uncomment code when we include those in bootstrap code.
    35  
    36  	switch {
    37  	case r >= objabi.MachoRelocOffset: // Mach-O
    38  		// nr := (r - objabi.MachoRelocOffset)>>1
    39  		// switch ctxt.Arch.Family {
    40  		// case sys.AMD64:
    41  		// 	return macho.RelocTypeX86_64(nr).String()
    42  		// case sys.ARM:
    43  		// 	return macho.RelocTypeARM(nr).String()
    44  		// case sys.ARM64:
    45  		// 	return macho.RelocTypeARM64(nr).String()
    46  		// case sys.I386:
    47  		// 	return macho.RelocTypeGeneric(nr).String()
    48  		// default:
    49  		// 	panic("unreachable")
    50  		// }
    51  	case r >= objabi.ElfRelocOffset: // ELF
    52  		nr := r - objabi.ElfRelocOffset
    53  		switch arch.Family {
    54  		case sys.AMD64:
    55  			return elf.R_X86_64(nr).String()
    56  		case sys.ARM:
    57  			return elf.R_ARM(nr).String()
    58  		case sys.ARM64:
    59  			return elf.R_AARCH64(nr).String()
    60  		case sys.I386:
    61  			return elf.R_386(nr).String()
    62  		case sys.MIPS, sys.MIPS64:
    63  			return elf.R_MIPS(nr).String()
    64  		case sys.PPC64:
    65  			return elf.R_PPC64(nr).String()
    66  		case sys.S390X:
    67  			return elf.R_390(nr).String()
    68  		default:
    69  			panic("unreachable")
    70  		}
    71  	}
    72  
    73  	return r.String()
    74  }
    75  

View as plain text