[PATCH] Improved elf linker error message
Thiemo Seufer
ica2_ts@csv.ica.uni-stuttgart.de
Tue May 14 09:33:00 GMT 2002
Ian Lance Taylor wrote:
> Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> writes:
>
> > + else
> > + {
> > + (*_bfd_error_handler) (
> > + _("%s: relocation size mismatch in %s section %s"),
> > + bfd_get_filename (output_bfd),
> > + bfd_get_filename (input_section->owner),
> > + input_section->name);
> > + abort();
> > + }
>
> It seems to me that this error could occur if the user calls the
> linker with the wrong input files.
Yes, that's why I found the mesage insufficient.
> If that is true, it seems vaguely
> troubling to me that the linker calls abort(). The linker should only
> call abort() on an internal error. This is a user error. For a user
> error, the linker should print an error message and fail.
>
> Would it be possible to change elf_link_output_relocs() to have a
> non-void return type, and check for an error return?
Like this?
Thiemo
2002-05-14 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/bfd/ChangeLog
* elf-bfd.h (elf_backend_emit_relocs): Change prototype to return
an error value.
* elflink.h (elf_link_output_relocs): Likewise. Improve error message.
return with false on error.
(elf_link_input_bfd): Check reloc_emitter return value.
diff -BurpNX /bigdisk/src/binutils-exclude source-orig/bfd/elf-bfd.h source/bfd/elf-bfd.h
--- source-orig/bfd/elf-bfd.h Fri May 10 21:34:01 2002
+++ source/bfd/elf-bfd.h Tue May 14 18:11:15 2002
@@ -705,7 +705,7 @@ struct elf_backend_data
/* Emit relocations. Overrides default routine for emitting relocs,
except during a relocatable link, or if all relocs are being emitted. */
- void (*elf_backend_emit_relocs)
+ boolean (*elf_backend_emit_relocs)
PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *));
/* Count relocations. Not called for relocatable links
diff -BurpNX /bigdisk/src/binutils-exclude source-orig/bfd/elflink.h source/bfd/elflink.h
--- source-orig/bfd/elflink.h Fri May 10 21:34:03 2002
+++ source/bfd/elflink.h Tue May 14 18:12:21 2002
@@ -65,7 +65,7 @@ static boolean elf_link_read_relocs_from
PARAMS ((bfd *, Elf_Internal_Shdr *, PTR, Elf_Internal_Rela *));
static size_t compute_bucket_count
PARAMS ((struct bfd_link_info *));
-static void elf_link_output_relocs
+static boolean elf_link_output_relocs
PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *));
static boolean elf_link_size_reloc_section
PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
@@ -6251,7 +6251,7 @@ elf_link_output_extsym (h, data)
originated from the section given by INPUT_REL_HDR) to the
OUTPUT_BFD. */
-static void
+static boolean
elf_link_output_relocs (output_bfd, input_section, input_rel_hdr,
internal_relocs)
bfd *output_bfd;
@@ -6283,8 +6283,16 @@ elf_link_output_relocs (output_bfd, inpu
output_rel_hdr = elf_section_data (output_section)->rel_hdr2;
rel_countp = &elf_section_data (output_section)->rel_count2;
}
-
- BFD_ASSERT (output_rel_hdr != NULL);
+ else
+ {
+ (*_bfd_error_handler) (
+ _("%s: relocation size mismatch in %s section %s"),
+ bfd_get_filename (output_bfd),
+ bfd_archive_filename (input_section->owner),
+ input_section->name);
+ bfd_set_error (bfd_error_wrong_object_format);
+ return false;
+ }
bed = get_elf_backend_data (output_bfd);
irela = internal_relocs;
@@ -6341,6 +6349,8 @@ elf_link_output_relocs (output_bfd, inpu
/* Bump the counter, so that we know where to add the next set of
relocations. */
*rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);
+
+ return true;
}
/* Link an input file into the linker output file. This function
@@ -6751,9 +6761,9 @@ elf_link_input_bfd (finfo, input_bfd)
struct elf_link_hash_entry **rel_hash;
Elf_Internal_Shdr *input_rel_hdr;
unsigned int next_erel;
- void (*reloc_emitter) PARAMS ((bfd *, asection *,
- Elf_Internal_Shdr *,
- Elf_Internal_Rela *));
+ boolean (*reloc_emitter) PARAMS ((bfd *, asection *,
+ Elf_Internal_Shdr *,
+ Elf_Internal_Rela *));
boolean rela_normal;
input_rel_hdr = &elf_section_data (o)->rel_hdr;
@@ -6910,15 +6920,18 @@ elf_link_input_bfd (finfo, input_bfd)
else
reloc_emitter = elf_link_output_relocs;
- (*reloc_emitter) (output_bfd, o, input_rel_hdr, internal_relocs);
+ if (! (*reloc_emitter) (output_bfd, o, input_rel_hdr,
+ internal_relocs))
+ return false;
input_rel_hdr = elf_section_data (o)->rel_hdr2;
if (input_rel_hdr)
{
internal_relocs += (NUM_SHDR_ENTRIES (input_rel_hdr)
* bed->s->int_rels_per_ext_rel);
- (*reloc_emitter) (output_bfd, o, input_rel_hdr,
- internal_relocs);
+ if (! (*reloc_emitter) (output_bfd, o, input_rel_hdr,
+ internal_relocs))
+ return false;
}
}
More information about the Binutils
mailing list