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.
This commit is contained in:
H.J. Lu 2021-12-31 06:49:19 -08:00
parent e5b10c4079
commit 831083d300
4 changed files with 41 additions and 38 deletions

View 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
{

View 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;

View 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. */

View File

@ -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))