This is the mail archive of the binutils@sources.redhat.com 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]

shared libs need to use -fPIC on x86-64


Like a number of other ports, x86-64 needs -fPIC for shared libs.  The
appended patch checks - like it's done on other ports - that certain
relocations are not used and aborts if they're used.  I've tested the
patch extensivly within SuSE and commit it now,

Andreas

2002-06-17  Andreas Jaeger  <aj@suse.de>

	* elf64-x86-64.c (elf64_x86_64_check_relocs): Certain
	  relocations are not allowed in shared libs code, enforce -fPIC.

============================================================
Index: bfd/elf64-x86-64.c
--- bfd/elf64-x86-64.c	3 Jun 2002 01:57:10 -0000	1.43
+++ bfd/elf64-x86-64.c	17 Jun 2002 13:07:45 -0000
@@ -660,11 +660,28 @@ elf64_x86_64_check_relocs (abfd, info, s
 	case R_X86_64_8:
 	case R_X86_64_16:
 	case R_X86_64_32:
-	case R_X86_64_64:
 	case R_X86_64_32S:
+	  /* Let's help debug shared library creation.  These relocs
+	     cannot be used in shared libs.  Don't error our for
+	     sections we don't care about, such as debug sections or
+	     non-constant sections.  */
+	  if (info->shared
+	      && (sec->flags & SEC_ALLOC) != 0
+	      && (sec->flags & SEC_READONLY) != 0)
+	    {
+	      (*_bfd_error_handler)
+		(_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
+		 bfd_archive_filename (abfd),
+		 x86_64_elf_howto_table[ELF64_R_TYPE (rel->r_info)].name);
+	      bfd_set_error (bfd_error_bad_value);
+	      return false;
+	    }
+	  /* Fall through.  */
+
 	case R_X86_64_PC8:
 	case R_X86_64_PC16:
 	case R_X86_64_PC32:
+	case R_X86_64_64:
 	  if (h != NULL && !info->shared)
 	    {
 	      /* If this reloc is in a read-only section, we might

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


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