Example #1
0
File: asm.go Project: Mokolea/go
func adddynrel(s *ld.Symbol, r *ld.Reloc) {
	targ := r.Sym
	ld.Ctxt.Cursym = s

	switch r.Type {
	default:
		if r.Type >= 256 {
			ld.Diag("unexpected relocation type %d", r.Type)
			return
		}

		// Handle relocations found in ELF object files.
	case 256 + ld.R_PPC64_REL24:
		r.Type = obj.R_CALLPOWER

		// This is a local call, so the caller isn't setting
		// up r12 and r2 is the same for the caller and
		// callee. Hence, we need to go to the local entry
		// point.  (If we don't do this, the callee will try
		// to use r12 to compute r2.)
		r.Add += int64(r.Sym.Localentry) * 4

		if targ.Type == obj.SDYNIMPORT {
			// Should have been handled in elfsetupplt
			ld.Diag("unexpected R_PPC64_REL24 for dyn import")
		}

		return

	case 256 + ld.R_PPC_REL32:
		r.Type = obj.R_PCREL
		r.Add += 4

		if targ.Type == obj.SDYNIMPORT {
			ld.Diag("unexpected R_PPC_REL32 for dyn import")
		}

		return

	case 256 + ld.R_PPC64_ADDR64:
		r.Type = obj.R_ADDR
		if targ.Type == obj.SDYNIMPORT {
			// These happen in .toc sections
			ld.Adddynsym(ld.Ctxt, targ)

			rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
			ld.Addaddrplus(ld.Ctxt, rela, s, int64(r.Off))
			ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_PPC64_ADDR64))
			ld.Adduint64(ld.Ctxt, rela, uint64(r.Add))
			r.Type = 256 // ignore during relocsym
		}

		return

	case 256 + ld.R_PPC64_TOC16:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_LO | ld.RV_CHECK_OVERFLOW
		return

	case 256 + ld.R_PPC64_TOC16_LO:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_LO
		return

	case 256 + ld.R_PPC64_TOC16_HA:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
		return

	case 256 + ld.R_PPC64_TOC16_HI:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
		return

	case 256 + ld.R_PPC64_TOC16_DS:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_DS | ld.RV_CHECK_OVERFLOW
		return

	case 256 + ld.R_PPC64_TOC16_LO_DS:
		r.Type = obj.R_POWER_TOC
		r.Variant = ld.RV_POWER_DS
		return

	case 256 + ld.R_PPC64_REL16_LO:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_POWER_LO
		r.Add += 2 // Compensate for relocation size of 2
		return

	case 256 + ld.R_PPC64_REL16_HI:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
		r.Add += 2
		return

	case 256 + ld.R_PPC64_REL16_HA:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
		r.Add += 2
		return
	}

	// Handle references to ELF symbols from our own object files.
	if targ.Type != obj.SDYNIMPORT {
		return
	}

	// TODO(austin): Translate our relocations to ELF

	ld.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
}
Example #2
0
File: asm.go Project: hurkgu/go
func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) {
	targ := r.Sym
	ctxt.Cursym = s

	switch r.Type {
	default:
		if r.Type >= 256 {
			ctxt.Diag("unexpected relocation type %d", r.Type)
			return
		}

		// Handle relocations found in ELF object files.
	case 256 + ld.R_390_12,
		256 + ld.R_390_GOT12:
		ctxt.Diag("s390x 12-bit relocations have not been implemented (relocation type %d)", r.Type-256)
		return

	case 256 + ld.R_390_8,
		256 + ld.R_390_16,
		256 + ld.R_390_32,
		256 + ld.R_390_64:
		if targ.Type == obj.SDYNIMPORT {
			ctxt.Diag("unexpected R_390_nn relocation for dynamic symbol %s", targ.Name)
		}
		r.Type = obj.R_ADDR
		return

	case 256 + ld.R_390_PC16,
		256 + ld.R_390_PC32,
		256 + ld.R_390_PC64:
		if targ.Type == obj.SDYNIMPORT {
			ctxt.Diag("unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name)
		}
		if targ.Type == 0 || targ.Type == obj.SXREF {
			ctxt.Diag("unknown symbol %s in pcrel", targ.Name)
		}
		r.Type = obj.R_PCREL
		r.Add += int64(r.Siz)
		return

	case 256 + ld.R_390_GOT16,
		256 + ld.R_390_GOT32,
		256 + ld.R_390_GOT64:
		ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256)
		return

	case 256 + ld.R_390_PLT16DBL,
		256 + ld.R_390_PLT32DBL:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_390_DBL
		r.Add += int64(r.Siz)
		if targ.Type == obj.SDYNIMPORT {
			addpltsym(ctxt, targ)
			r.Sym = ld.Linklookup(ctxt, ".plt", 0)
			r.Add += int64(targ.Plt)
		}
		return

	case 256 + ld.R_390_PLT32,
		256 + ld.R_390_PLT64:
		r.Type = obj.R_PCREL
		r.Add += int64(r.Siz)
		if targ.Type == obj.SDYNIMPORT {
			addpltsym(ctxt, targ)
			r.Sym = ld.Linklookup(ctxt, ".plt", 0)
			r.Add += int64(targ.Plt)
		}
		return

	case 256 + ld.R_390_COPY:
		ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256)

	case 256 + ld.R_390_GLOB_DAT:
		ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256)

	case 256 + ld.R_390_JMP_SLOT:
		ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256)

	case 256 + ld.R_390_RELATIVE:
		ctxt.Diag("unimplemented S390x relocation: %v", r.Type-256)

	case 256 + ld.R_390_GOTOFF:
		if targ.Type == obj.SDYNIMPORT {
			ctxt.Diag("unexpected R_390_GOTOFF relocation for dynamic symbol %s", targ.Name)
		}
		r.Type = obj.R_GOTOFF
		return

	case 256 + ld.R_390_GOTPC:
		r.Type = obj.R_PCREL
		r.Sym = ld.Linklookup(ctxt, ".got", 0)
		r.Add += int64(r.Siz)
		return

	case 256 + ld.R_390_PC16DBL,
		256 + ld.R_390_PC32DBL:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_390_DBL
		r.Add += int64(r.Siz)
		if targ.Type == obj.SDYNIMPORT {
			ctxt.Diag("unexpected R_390_PCnnDBL relocation for dynamic symbol %s", targ.Name)
		}
		return

	case 256 + ld.R_390_GOTPCDBL:
		r.Type = obj.R_PCREL
		r.Variant = ld.RV_390_DBL
		r.Sym = ld.Linklookup(ctxt, ".got", 0)
		r.Add += int64(r.Siz)
		return

	case 256 + ld.R_390_GOTENT:
		addgotsym(ctxt, targ)

		r.Type = obj.R_PCREL
		r.Variant = ld.RV_390_DBL
		r.Sym = ld.Linklookup(ctxt, ".got", 0)
		r.Add += int64(targ.Got)
		r.Add += int64(r.Siz)
		return
	}
	// Handle references to ELF symbols from our own object files.
	if targ.Type != obj.SDYNIMPORT {
		return
	}

	ctxt.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
}