public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb•auug.org.au>
To: Andrew Morton <akpm@linux-foundation•org>,
	Michael Ellerman <mpe@ellerman•id.au>,
	Benjamin Herrenschmidt <benh@kernel•crashing.org>,
	PowerPC <linuxppc-dev@lists•ozlabs.org>
Cc: linux-next@vger•kernel.org, linux-kernel@vger•kernel.org,
	Thiago Jung Bauermann <bauerman@linux•vnet.ibm.com>
Subject: linux-next: manual merge of the akpm tree with the powerpc tree
Date: Tue, 15 Nov 2016 14:52:50 +1100	[thread overview]
Message-ID: <20161115145250.4f38496e@canb.auug.org.au> (raw)

Hi Andrew,

Today's linux-next merge of the akpm tree got a conflict in:

  arch/powerpc/kernel/module_64.c

between commit:

  9f751b82b491 ("powerpc/module: Add support for R_PPC64_REL32 relocations")

from the powerpc tree and patch:

  "powerpc: factor out relocation code in module_64.c"

from the akpm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/powerpc/kernel/module_64.c
index bb1807184bad,61baad036639..000000000000
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@@ -507,6 -507,181 +507,186 @@@ static int restore_r2(u32 *instruction
  	return 1;
  }
  
+ static int elf64_apply_relocate_add_item(const Elf64_Shdr *sechdrs,
+ 					 const char *strtab,
+ 					 const Elf64_Rela *rela,
+ 					 const Elf64_Sym *sym,
+ 					 unsigned long *location,
+ 					 unsigned long value,
+ 					 unsigned long my_r2,
+ 					 const char *obj_name,
+ 					 struct module *me)
+ {
+ 	switch (ELF64_R_TYPE(rela->r_info)) {
+ 	case R_PPC64_ADDR32:
+ 		/* Simply set it */
+ 		*(u32 *)location = value;
+ 		break;
+ 
+ 	case R_PPC64_ADDR64:
+ 		/* Simply set it */
+ 		*(unsigned long *)location = value;
+ 		break;
+ 
+ 	case R_PPC64_TOC:
+ 		*(unsigned long *)location = my_r2;
+ 		break;
+ 
+ 	case R_PPC64_TOC16:
+ 		/* Subtract TOC pointer */
+ 		value -= my_r2;
+ 		if (value + 0x8000 > 0xffff) {
+ 			pr_err("%s: bad TOC16 relocation (0x%lx)\n",
+ 			       obj_name, value);
+ 			return -ENOEXEC;
+ 		}
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xffff)
+ 			| (value & 0xffff);
+ 		break;
+ 
+ 	case R_PPC64_TOC16_LO:
+ 		/* Subtract TOC pointer */
+ 		value -= my_r2;
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xffff)
+ 			| (value & 0xffff);
+ 		break;
+ 
+ 	case R_PPC64_TOC16_DS:
+ 		/* Subtract TOC pointer */
+ 		value -= my_r2;
+ 		if ((value & 3) != 0 || value + 0x8000 > 0xffff) {
+ 			pr_err("%s: bad TOC16_DS relocation (0x%lx)\n",
+ 			       obj_name, value);
+ 			return -ENOEXEC;
+ 		}
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xfffc)
+ 			| (value & 0xfffc);
+ 		break;
+ 
+ 	case R_PPC64_TOC16_LO_DS:
+ 		/* Subtract TOC pointer */
+ 		value -= my_r2;
+ 		if ((value & 3) != 0) {
+ 			pr_err("%s: bad TOC16_LO_DS relocation (0x%lx)\n",
+ 			       obj_name, value);
+ 			return -ENOEXEC;
+ 		}
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xfffc)
+ 			| (value & 0xfffc);
+ 		break;
+ 
+ 	case R_PPC64_TOC16_HA:
+ 		/* Subtract TOC pointer */
+ 		value -= my_r2;
+ 		value = ((value + 0x8000) >> 16);
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xffff)
+ 			| (value & 0xffff);
+ 		break;
+ 
+ 	case R_PPC_REL24:
+ 		/* FIXME: Handle weak symbols here --RR */
+ 		if (sym->st_shndx == SHN_UNDEF) {
+ 			/* External: go via stub */
+ 			value = stub_for_addr(sechdrs, value, me);
+ 			if (!value)
+ 				return -ENOENT;
+ 			if (!restore_r2((u32 *)location + 1, me))
+ 				return -ENOEXEC;
+ 
+ 			squash_toc_save_inst(strtab + sym->st_name, value);
+ 		} else
+ 			value += local_entry_offset(sym);
+ 
+ 		/* Convert value to relative */
+ 		value -= (unsigned long)location;
+ 		if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0) {
+ 			pr_err("%s: REL24 %li out of range!\n",
+ 			       obj_name, (long int)value);
+ 			return -ENOEXEC;
+ 		}
+ 
+ 		/* Only replace bits 2 through 26 */
+ 		*(uint32_t *)location
+ 			= (*(uint32_t *)location & ~0x03fffffc)
+ 			| (value & 0x03fffffc);
+ 		break;
+ 
+ 	case R_PPC64_REL64:
+ 		/* 64 bits relative (used by features fixups) */
+ 		*location = value - (unsigned long)location;
+ 		break;
+ 
++	case R_PPC64_REL32:
++		/* 32 bits relative (used by relative exception tables) */
++		*(u32 *)location = value - (unsigned long)location;
++		break;
++
+ 	case R_PPC64_TOCSAVE:
+ 		/*
+ 		 * Marker reloc indicates we don't have to save r2.
+ 		 * That would only save us one instruction, so ignore
+ 		 * it.
+ 		 */
+ 		break;
+ 
+ 	case R_PPC64_ENTRY:
+ 		/*
+ 		 * Optimize ELFv2 large code model entry point if
+ 		 * the TOC is within 2GB range of current location.
+ 		 */
+ 		value = my_r2 - (unsigned long)location;
+ 		if (value + 0x80008000 > 0xffffffff)
+ 			break;
+ 		/*
+ 		 * Check for the large code model prolog sequence:
+ 		 *	ld r2, ...(r12)
+ 		 *	add r2, r2, r12
+ 		 */
+ 		if ((((uint32_t *)location)[0] & ~0xfffc)
+ 		    != 0xe84c0000)
+ 			break;
+ 		if (((uint32_t *)location)[1] != 0x7c426214)
+ 			break;
+ 		/*
+ 		 * If found, replace it with:
+ 		 *	addis r2, r12, (.TOC.-func)@ha
+ 		 *	addi r2, r12, (.TOC.-func)@l
+ 		 */
+ 		((uint32_t *)location)[0] = 0x3c4c0000 + PPC_HA(value);
+ 		((uint32_t *)location)[1] = 0x38420000 + PPC_LO(value);
+ 		break;
+ 
+ 	case R_PPC64_REL16_HA:
+ 		/* Subtract location pointer */
+ 		value -= (unsigned long)location;
+ 		value = ((value + 0x8000) >> 16);
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xffff)
+ 			| (value & 0xffff);
+ 		break;
+ 
+ 	case R_PPC64_REL16_LO:
+ 		/* Subtract location pointer */
+ 		value -= (unsigned long)location;
+ 		*((uint16_t *) location)
+ 			= (*((uint16_t *) location) & ~0xffff)
+ 			| (value & 0xffff);
+ 		break;
+ 
+ 	default:
+ 		pr_err("%s: Unknown ADD relocation: %lu\n", obj_name,
+ 		       (unsigned long)ELF64_R_TYPE(rela->r_info));
+ 		return -ENOEXEC;
+ 	}
+ 
+ 	return 0;
+ }
+ 
  int apply_relocate_add(Elf64_Shdr *sechdrs,
  		       const char *strtab,
  		       unsigned int symindex,

             reply	other threads:[~2016-11-15  3:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15  3:52 Stephen Rothwell [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-28  9:56 linux-next: manual merge of the akpm tree with the powerpc tree Stephen Rothwell
2020-03-06  6:39 Stephen Rothwell
2020-03-06  5:29 Stephen Rothwell
2016-08-02  3:39 Stephen Rothwell
2013-06-26  6:56 Stephen Rothwell
2013-06-26  8:10 ` Benjamin Herrenschmidt
2013-06-26 13:13   ` Andrew Morton
2013-06-26 14:19   ` Oleg Nesterov
2013-06-26 21:56     ` Benjamin Herrenschmidt
2012-03-13  9:10 Stephen Rothwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161115145250.4f38496e@canb.auug.org.au \
    --to=sfr@canb$(echo .)auug.org.au \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=bauerman@linux$(echo .)vnet.ibm.com \
    --cc=benh@kernel$(echo .)crashing.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=mpe@ellerman$(echo .)id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox