Define X86_PCREL_TYPE_P/X86_SIZE_TYPE_P in elfxx-x86.h
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 31 Dec 2021 14:49:19 +0000 (06:49 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 31 Dec 2021 15:02:41 +0000 (07:02 -0800)
* elf32-i386.c: Don't include "elf/i386.h".
(X86_PCREL_TYPE_P): Removed.
(X86_SIZE_TYPE_P): Likewise.
(elf_i386_check_relocs): Pass false to NEED_DYNAMIC_RELOCATION_P.
(elf_i386_relocate_section): Pass false to
GENERATE_DYNAMIC_RELOCATION_P and COPY_INPUT_RELOC_P.
* elf64-x86-64.c: Don't include "elf/x86-64.h".
(X86_PCREL_TYPE_P): Removed.
(X86_SIZE_TYPE_P): Likewise.
(elf_x86_64_check_relocs): Pass true to NEED_DYNAMIC_RELOCATION_P
and X86_PCREL_TYPE_P.
(elf_x86_64_relocate_section): Pass true to X86_PCREL_TYPE_P,
X86_SIZE_TYPE_P, GENERATE_DYNAMIC_RELOCATION_P and
COPY_INPUT_RELOC_P.
* elfxx-x86.c: Don't include "elf/i386.h" nor "elf/x86-64.h".
* elfxx-x86.h (X86_64_PCREL_TYPE_P): New.
(I386_PCREL_TYPE_P): Likewise.
(X86_PCREL_TYPE_P): Likewise.
(X86_64_SIZE_TYPE_P): Likewise.
(I386_SIZE_TYPE_P): Likewise.
(X86_SIZE_TYPE_P): Likewise.
(NEED_DYNAMIC_RELOCATION_P): Add IS_X86_64 and pass it to
X86_PCREL_TYPE_P.
(COPY_INPUT_RELOC_P): Likewise.
(GENERATE_DYNAMIC_RELOCATION_P): Add IS_X86_64, pass it to
X86_PCREL_TYPE_P and X86_SIZE_TYPE_P.

bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index d4f8ec3b21db3906b376d4563ca1e568b452679f..5660e9539af2c397c4decfac404dd98f3d307946 100644 (file)
@@ -26,8 +26,6 @@
 /* 386 uses REL relocations instead of RELA.  */
 #define USE_REL        1
 
-#include "elf/i386.h"
-
 static reloc_howto_type elf_howto_table[]=
 {
   HOWTO(R_386_NONE, 0, 3, 0, false, 0, complain_overflow_dont,
@@ -181,10 +179,6 @@ static reloc_howto_type elf_howto_table[]=
 
 };
 
-#define X86_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
-
-#define X86_SIZE_TYPE_P(TYPE) ((TYPE) == R_386_SIZE32)
-
 #ifdef DEBUG_GEN_RELOC
 #define TRACE(str) \
   fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
@@ -1835,8 +1829,8 @@ elf_i386_check_relocs (bfd *abfd,
          size_reloc = false;
        do_size:
          if (!no_dynreloc
-             && NEED_DYNAMIC_RELOCATION_P (info, false, h, sec, r_type,
-                                           R_386_32))
+             && NEED_DYNAMIC_RELOCATION_P (false, info, false, h, sec,
+                                           r_type, R_386_32))
            {
              struct elf_dyn_relocs *p;
              struct elf_dyn_relocs **head;
@@ -2725,8 +2719,9 @@ elf_i386_relocate_section (bfd *output_bfd,
              || is_vxworks_tls)
            break;
 
-         if (GENERATE_DYNAMIC_RELOCATION_P (info, eh, r_type, sec,
-                                            false, resolved_to_zero,
+         if (GENERATE_DYNAMIC_RELOCATION_P (false, info, eh, r_type,
+                                            sec, false,
+                                            resolved_to_zero,
                                             (r_type == R_386_PC32)))
            {
              Elf_Internal_Rela outrel;
@@ -2752,7 +2747,7 @@ elf_i386_relocate_section (bfd *output_bfd,
 
              if (skip)
                memset (&outrel, 0, sizeof outrel);
-             else if (COPY_INPUT_RELOC_P (info, h, r_type))
+             else if (COPY_INPUT_RELOC_P (false, info, h, r_type))
                outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
              else
                {
index bb6df798d7b04db28756f9d4cad49325c6c18d26..637f7464d949668babff7f4e7181fbbe0f53b25c 100644 (file)
@@ -24,7 +24,6 @@
 #include "libiberty.h"
 
 #include "opcode/i386.h"
-#include "elf/x86-64.h"
 
 #ifdef CORE_HEADER
 #include <stdarg.h>
@@ -193,16 +192,6 @@ static reloc_howto_type x86_64_elf_howto_table[] =
        false)
 };
 
-#define X86_PCREL_TYPE_P(TYPE)         \
-  (   ((TYPE) == R_X86_64_PC8)         \
-   || ((TYPE) == R_X86_64_PC16)                \
-   || ((TYPE) == R_X86_64_PC32)                \
-   || ((TYPE) == R_X86_64_PC32_BND)    \
-   || ((TYPE) == R_X86_64_PC64))
-
-#define X86_SIZE_TYPE_P(TYPE)          \
-  ((TYPE) == R_X86_64_SIZE32 || (TYPE) == R_X86_64_SIZE64)
-
 /* Map BFD relocs to the x86_64 elf relocs.  */
 struct elf_reloc_map
 {
@@ -2284,7 +2273,8 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          size_reloc = false;
        do_size:
          if (!no_dynreloc
-             && NEED_DYNAMIC_RELOCATION_P (info, true, h, sec, r_type,
+             && NEED_DYNAMIC_RELOCATION_P (true, info, true, h, sec,
+                                           r_type,
                                            htab->pointer_r_type))
            {
              struct elf_dyn_relocs *p;
@@ -2348,7 +2338,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
              p->count += 1;
              /* Count size relocation as PC-relative relocation.  */
-             if (X86_PCREL_TYPE_P (r_type) || size_reloc)
+             if (X86_PCREL_TYPE_P (true, r_type) || size_reloc)
                p->pc_count += 1;
            }
          break;
@@ -3235,10 +3225,11 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                                        || eh->needs_copy
                                        || (h->root.type
                                            == bfd_link_hash_undefined))
-                                   && (X86_PCREL_TYPE_P (r_type)
-                                       || X86_SIZE_TYPE_P (r_type)));
+                                   && (X86_PCREL_TYPE_P (true, r_type)
+                                       || X86_SIZE_TYPE_P (true,
+                                                           r_type)));
 
-         if (GENERATE_DYNAMIC_RELOCATION_P (info, eh, r_type, sec,
+         if (GENERATE_DYNAMIC_RELOCATION_P (true, info, eh, r_type, sec,
                                             need_copy_reloc_in_pie,
                                             resolved_to_zero, false))
            {
@@ -3267,7 +3258,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
              if (skip)
                memset (&outrel, 0, sizeof outrel);
 
-             else if (COPY_INPUT_RELOC_P (info, h, r_type))
+             else if (COPY_INPUT_RELOC_P (true, info, h, r_type))
                {
                  outrel.r_info = htab->r_info (h->dynindx, r_type);
                  outrel.r_addend = rel->r_addend;
index fe4a822041bcaeb970ce2a84af4233608b204708..f3435b07201c12e0d411f8ff81923d9e31033288 100644 (file)
@@ -21,8 +21,6 @@
 #include "elfxx-x86.h"
 #include "elf-vxworks.h"
 #include "objalloc.h"
-#include "elf/i386.h"
-#include "elf/x86-64.h"
 
 /* The name of the dynamic interpreter.  This is put in the .interp
    section.  */
index aab641ab751db9873cca55cfbbc23d67c430baad..91a141f1363505613cbd62abe82df3115f76ae6e 100644 (file)
 #include "elf-bfd.h"
 #include "hashtab.h"
 #include "elf-linker-x86.h"
+#include "elf/i386.h"
+#include "elf/x86-64.h"
+
+#define X86_64_PCREL_TYPE_P(TYPE) \
+  ((TYPE) == R_X86_64_PC8 \
+   || (TYPE) == R_X86_64_PC16 \
+   || (TYPE) == R_X86_64_PC32 \
+   || (TYPE) == R_X86_64_PC32_BND \
+   || (TYPE) == R_X86_64_PC64)
+#define I386_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
+#define X86_PCREL_TYPE_P(IS_X86_64, TYPE) \
+  ((IS_X86_64) ? X86_64_PCREL_TYPE_P (TYPE) : I386_PCREL_TYPE_P (TYPE))
+
+#define X86_64_SIZE_TYPE_P(TYPE) \
+  ((TYPE) == R_X86_64_SIZE32 || (TYPE) == R_X86_64_SIZE64)
+#define I386_SIZE_TYPE_P(TYPE) ((TYPE) == R_386_SIZE32)
+#define X86_SIZE_TYPE_P(IS_X86_64, TYPE) \
+  ((IS_X86_64) ? X86_64_SIZE_TYPE_P(TYPE) : I386_SIZE_TYPE_P (TYPE))
 
 #define PLT_CIE_LENGTH         20
 #define PLT_FDE_LENGTH         36
 
    We also need to generate dynamic pointer relocation against
    STT_GNU_IFUNC symbol in the non-code section.  */
-#define NEED_DYNAMIC_RELOCATION_P(INFO, PCREL_PLT, H, SEC, R_TYPE, \
-                                 POINTER_TYPE) \
+#define NEED_DYNAMIC_RELOCATION_P(IS_X86_64, INFO, PCREL_PLT, H, SEC, \
+                                 R_TYPE, POINTER_TYPE) \
   ((bfd_link_pic (INFO) \
-    && (! X86_PCREL_TYPE_P (R_TYPE) \
+    && (! X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
        || ((H) != NULL \
            && (! (bfd_link_pie (INFO) \
                   || SYMBOLIC_BIND ((INFO), (H))) \
    when PC32_RELOC is TRUE.  Undefined weak symbol is bound locally
    when PIC is false.  Don't generate dynamic relocations against
    non-preemptible absolute symbol.  */
-#define GENERATE_DYNAMIC_RELOCATION_P(INFO, EH, R_TYPE, SEC, \
-                                     NEED_COPY_RELOC_IN_PIE, \
+#define GENERATE_DYNAMIC_RELOCATION_P(IS_X86_64, INFO, EH, R_TYPE, \
+                                     SEC, NEED_COPY_RELOC_IN_PIE, \
                                      RESOLVED_TO_ZERO, PC32_RELOC) \
   ((bfd_link_pic (INFO) \
     && !(bfd_is_abs_section (SEC) \
        || ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \
             && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \
            || (EH)->elf.root.type != bfd_link_hash_undefweak)) \
-    && ((!X86_PCREL_TYPE_P (R_TYPE) && !X86_SIZE_TYPE_P (R_TYPE)) \
+    && ((!X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
+        && !X86_SIZE_TYPE_P (IS_X86_64, R_TYPE)) \
        || ! SYMBOL_CALLS_LOCAL ((INFO), \
                                 (struct elf_link_hash_entry *) (EH)))) \
    || (ELIMINATE_COPY_RELOCS \
 
 /* TRUE if this input relocation should be copied to output.  H->dynindx
    may be -1 if this symbol was marked to become local.  */
-#define COPY_INPUT_RELOC_P(INFO, H, R_TYPE) \
+#define COPY_INPUT_RELOC_P(IS_X86_64, INFO, H, R_TYPE) \
   ((H) != NULL \
    && (H)->dynindx != -1 \
-   && (X86_PCREL_TYPE_P (R_TYPE) \
+   && (X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
        || !(bfd_link_executable (INFO) || SYMBOLIC_BIND ((INFO), (H))) \
        || !(H)->def_regular))