[PATCH 3/3] ld/PE: use in_reloc_p()
Jan Beulich
jbeulich@suse.com
Fri Nov 6 11:14:15 GMT 2026
Fill in missing relocation types in the per-arch implementations, such
that the linker's custom recording of section, section relative, image
base relative, and ABS/NONE relocation types can be dropped.
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -474,7 +474,12 @@ static bool
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
reloc_howto_type * howto)
{
- return !howto->pc_relative;
+ return !howto->pc_relative
+ && howto->type != IMAGE_REL_ARM64_ABSOLUTE
+ && howto->type != IMAGE_REL_ARM64_ADDR32NB
+ && howto->type != IMAGE_REL_ARM64_SECREL
+ && howto->type != IMAGE_REL_ARM64_SECREL_LOW12L
+ && howto->type != IMAGE_REL_ARM64_SECTION;
}
#endif
--- a/bfd/coff-arm.c
+++ b/bfd/coff-arm.c
@@ -517,7 +517,12 @@ static bool
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
reloc_howto_type * howto)
{
- return !howto->pc_relative && howto->type != ARM_RVA32;
+ return !howto->pc_relative
+# ifdef ARM_WINCE
+ && howto->type != ARM_SECREL
+ && howto->type != ARM_SECTION
+# endif
+ && howto->type != ARM_RVA32;
}
#endif
--- a/bfd/coff-mcore.c
+++ b/bfd/coff-mcore.c
@@ -343,7 +343,8 @@ coff_mcore_rtype_to_howto (bfd * abfd AT
static bool
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, reloc_howto_type * howto)
{
- return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA;
+ return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA
+ && howto->type != IMAGE_REL_MCORE_ABSOLUTE;
}
/* The reloc processing routine for the optimized COFF linker. */
--- a/bfd/coff-x86_64.c
+++ b/bfd/coff-x86_64.c
@@ -227,6 +227,7 @@ in_reloc_p (bfd *abfd ATTRIBUTE_UNUSED,
&& howto->type != R_AMD64_ABS
&& howto->type != R_AMD64_IMAGEBASE
&& howto->type != R_AMD64_SECREL
+ && howto->type != R_AMD64_SECREL7
&& howto->type != R_AMD64_SECTION;
}
#endif /* COFF_WITH_PE */
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -184,10 +184,6 @@ typedef struct
{
const char *target_name;
const char *object_target;
- unsigned int imagebase_reloc;
- unsigned int secrel_reloc_lo;
- unsigned int secrel_reloc_hi;
- unsigned int section_reloc;
int pe_arch;
int bfd_arch;
bool underscored;
@@ -265,16 +261,9 @@ static pe_details_type pe_detail_list[]
#ifdef pe_use_plus
"pei-x86-64",
"pe-x86-64",
- 3 /* R_AMD64_IMAGEBASE */,
- 11 /* R_AMD64_SECREL32 */,
- 12 /* R_AMD64_SECREL7 */,
- 10 /* R_AMD64_SECTION */,
#else
"pei-i386",
"pe-i386",
- 7 /* R_IMAGEBASE */,
- 11, 11 /* R_SECREL32 */,
- 10 /* R_SECTION */,
#endif
PE_ARCH_i386,
bfd_arch_i386,
@@ -289,10 +278,6 @@ static pe_details_type pe_detail_list[]
{
"pei-x86-64",
"pe-bigobj-x86-64",
- 3 /* R_AMD64_IMAGEBASE */,
- 11 /* R_AMD64_SECREL32 */,
- 12 /* R_AMD64_SECREL7 */,
- 10 /* R_AMD64_SECTION */,
PE_ARCH_i386,
bfd_arch_i386,
false,
@@ -302,9 +287,6 @@ static pe_details_type pe_detail_list[]
{
"pei-i386",
"pe-bigobj-i386",
- 7 /* R_IMAGEBASE */,
- 11, 11 /* R_SECREL32 */,
- 10 /* R_SECTION */,
PE_ARCH_i386,
bfd_arch_i386,
true,
@@ -313,8 +295,6 @@ static pe_details_type pe_detail_list[]
{
"pei-shl",
"pe-shl",
- 16 /* R_SH_IMAGEBASE */,
- ~0, 0, ~0, /* none */
PE_ARCH_sh,
bfd_arch_sh,
true,
@@ -323,8 +303,6 @@ static pe_details_type pe_detail_list[]
{
"pei-mcore-little",
"pe-mcore-little",
- 7 /* IMAGE_REL_MCORE_RVA */,
- ~0, 0, ~0, /* none */
PE_ARCH_mcore,
bfd_arch_mcore,
false,
@@ -333,8 +311,6 @@ static pe_details_type pe_detail_list[]
{
"pei-mcore-big",
"pe-mcore-big",
- 7 /* IMAGE_REL_MCORE_RVA */,
- ~0, 0, ~0, /* none */
PE_ARCH_mcore,
bfd_arch_mcore,
false,
@@ -343,8 +319,6 @@ static pe_details_type pe_detail_list[]
{
"pei-arm-little",
"pe-arm-little",
- 11 /* ARM_RVA32 */,
- ~0, 0, ~0, /* none */
PE_ARCH_arm,
bfd_arch_arm,
true,
@@ -353,9 +327,6 @@ static pe_details_type pe_detail_list[]
{
"pei-arm-wince-little",
"pe-arm-wince-little",
- 2, /* ARM_RVA32 on Windows CE, see bfd/coff-arm.c. */
- 15, 15, /* ARM_SECREL (dito) */
- 14, /* ARM_SECTION (dito) */
PE_ARCH_arm_wince,
bfd_arch_arm,
false,
@@ -365,10 +336,6 @@ static pe_details_type pe_detail_list[]
{
"pei-aarch64-little",
"pe-aarch64-little",
- 2, /* IMAGE_REL_ARM64_ADDR32NB */
- 8, /* IMAGE_REL_ARM64_SECREL */
- 11, /* IMAGE_REL_ARM64_SECREL_LOW12L */
- 13, /* IMAGE_REL_ARM64_SECTION */
PE_ARCH_aarch64,
bfd_arch_aarch64,
false,
@@ -377,16 +344,12 @@ static pe_details_type pe_detail_list[]
{
"pei-aarch64-little",
"pe-bigobj-aarch64-little",
- 2, /* IMAGE_REL_ARM64_ADDR32NB */
- 8, /* IMAGE_REL_ARM64_SECREL */
- 11, /* IMAGE_REL_ARM64_SECREL_LOW12L */
- 13, /* IMAGE_REL_ARM64_SECTION */
PE_ARCH_aarch64,
bfd_arch_aarch64,
false,
autofilter_symbollist_generic
},
- { NULL, NULL, 0, 0, 0, 0, 0, 0, false, NULL }
+ { NULL, NULL, 0, 0, false, NULL }
};
static const pe_details_type *pe_details;
@@ -1657,10 +1620,8 @@ generate_reloc (bfd *abfd, struct bfd_li
}
if (!relocs[i]->howto->pc_relative
&& (bfd_get_flavour (b) != bfd_target_coff_flavour
- || (relocs[i]->howto->type != pe_details->imagebase_reloc
- && (relocs[i]->howto->type < pe_details->secrel_reloc_lo
- || relocs[i]->howto->type > pe_details->secrel_reloc_hi)
- && relocs[i]->howto->type != pe_details->section_reloc)))
+ || pe_data (info->output_bfd)->in_reloc_p
+ (info->output_bfd, relocs[i]->howto)))
{
struct bfd_symbol *sym = *relocs[i]->sym_ptr_ptr;
const struct bfd_link_hash_entry *blhe
More information about the Binutils
mailing list