This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix inverted EF_SH_PIC flag on sh/fdpic target


This patch is the result of the discussion and findings in the
following thread cross-posted with the linux-sh kernel list:
https://sourceware.org/ml/binutils/2015-09/msg00186.html

In short, all of the FDPIC ABI documents (FRV, Blackfin, SH) specify
their EF_*_PIC flag with exactly the opposite meaning Linux interprets
it to have. For FRV and Blackfin, binutils matches the kernel behavior
and therefore produces binaries that run correctly with shared text.
For SH, however, binutils followed the wrong information in the ABI
document and therefore produces binaries that gratuitously fail to
share text at runtime due to their header bits.

This patch brings the SH behavior into alignment with the kernel and
other FDPIC targets.

2015-09-14  Rich Felker  <dalias@libc.org>

	* bfd/elf32-sh.c (sh_elf_relocate_section): Set EF_SH_PIC flag
	instead of clearing it on cross-section relocations.
	(sh_elf_merge_private_data): Clear EF_SH_PIC flag by default.

diff -ur binutils-2.25.1.orig/bfd/elf32-sh.c binutils-2.25.1/bfd/elf32-sh.c
--- binutils-2.25.1.orig/bfd/elf32-sh.c	2015-09-03 21:52:17.000000000 +0000
+++ binutils-2.25.1/bfd/elf32-sh.c	2015-09-14 17:08:48.114426847 +0000
@@ -5487,7 +5487,7 @@
 		   input_bfd, input_section, rel->r_offset, symname);
 	    }
 
-	  elf_elfheader (output_bfd)->e_flags &= ~EF_SH_PIC;
+	  elf_elfheader (output_bfd)->e_flags |= EF_SH_PIC;
 	}
 
       if (r != bfd_reloc_ok)
@@ -6644,7 +6644,7 @@
       elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
       sh_elf_set_mach_from_flags (obfd);
       if (elf_elfheader (obfd)->e_flags & EF_SH_FDPIC)
-	elf_elfheader (obfd)->e_flags |= EF_SH_PIC;
+	elf_elfheader (obfd)->e_flags &= ~EF_SH_PIC;
     }
 
   if (! sh_merge_bfd_arch (ibfd, obfd))

Attachment: 0004-shfdpicflag.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]