aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-12-31 06:49:19 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-12-31 07:02:41 -0800
commit831083d300c9e7f5a224df60c3a059725fb04882 (patch)
treed251dc13573462c9d76d0518f3a210c416d6f5dd
parente5b10c4079279db9aa86225a3b4b4c30280c322e (diff)
downloadgdb-831083d300c9e7f5a224df60c3a059725fb04882.zip
gdb-831083d300c9e7f5a224df60c3a059725fb04882.tar.gz
gdb-831083d300c9e7f5a224df60c3a059725fb04882.tar.bz2
Define X86_PCREL_TYPE_P/X86_SIZE_TYPE_P in elfxx-x86.h
* 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.
-rw-r--r--bfd/elf32-i386.c17
-rw-r--r--bfd/elf64-x86-64.c25
-rw-r--r--bfd/elfxx-x86.c2
-rw-r--r--bfd/elfxx-x86.h35
4 files changed, 41 insertions, 38 deletions
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index d4f8ec3..5660e95 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -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
{
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index bb6df79..637f746 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -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;
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index fe4a822..f3435b0 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -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. */
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index aab641a..91a141f 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -28,6 +28,24 @@
#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
@@ -91,10 +109,10 @@
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))) \
@@ -124,8 +142,8 @@
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) \
@@ -136,7 +154,8 @@
|| ((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 \
@@ -151,10 +170,10 @@
/* 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))