From d82f74d3ab985da4b217a4942a0b4e2e55021fab Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 17 Nov 2010 01:03:06 +0000 Subject: [PATCH] simple-object.h (simple_object_attributes_merge): Declare, replacing simple_object_attributes_compare. include/: * simple-object.h (simple_object_attributes_merge): Declare, replacing simple_object_attributes_compare. libiberty/: * simple-object.c (simple_object_attributes_merge): Rename from simple_object_attributes_compare. Call merge field. * simple-object-common.h (struct simple_object_functions): Rename attributes_compare field to attribute_merge. * simple-object-elf.c (EM_SPARC): Define. (EM_SPARC32PLUS): Define. (simple_object_elf_attributes_merge): Renamed from simple_object_elf_attributes_compare. Permit EM_SPARC and EM_SPARC32PLUS objects to be merged. (simple_object_elf_functions): Update function name. * simple-object-coff.c (simple_object_coff_attributes_merge): Rename from simple_object_coff_attributes_compare. (simple_object_coff_functions): Update function name. * simple-object-mach-o.c (simple_object_mach_o_attributes_merge): Renamed from simple_object_mach_o_attributes_compare. (simple_object_mach_o_functions): Update function name. gcc/lto/: * lto-object.c (lto_obj_file_open): Call simple_object_attributes_merge rather than simple_object_attributes_compare. From-SVN: r166848 --- gcc/lto/ChangeLog | 6 ++++ gcc/lto/lto-object.c | 4 +-- include/ChangeLog | 5 +++ include/simple-object.h | 13 ++++---- libiberty/ChangeLog | 19 +++++++++++ libiberty/simple-object-coff.c | 15 ++++----- libiberty/simple-object-common.h | 8 ++--- libiberty/simple-object-elf.c | 57 ++++++++++++++++++++++++++------ libiberty/simple-object-mach-o.c | 20 +++++------ libiberty/simple-object.c | 13 ++++---- 10 files changed, 113 insertions(+), 47 deletions(-) diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index 21bbeffefbe0..c254da1a5fae 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,9 @@ +2010-11-16 Ian Lance Taylor + + * lto-object.c (lto_obj_file_open): Call + simple_object_attributes_merge rather than + simple_object_attributes_compare. + 2010-11-12 Joseph Myers * Make-lang.in (lto/lto.o): Use $(OPTS_H). diff --git a/gcc/lto/lto-object.c b/gcc/lto/lto-object.c index e4a998163cf3..4a67580d2d3b 100644 --- a/gcc/lto/lto-object.c +++ b/gcc/lto/lto-object.c @@ -138,8 +138,8 @@ lto_obj_file_open (const char *filename, bool writable) saved_attributes = attrs; else { - errmsg = simple_object_attributes_compare (saved_attributes, attrs, - &err); + errmsg = simple_object_attributes_merge (saved_attributes, attrs, + &err); if (errmsg != NULL) goto fail_errmsg; } diff --git a/include/ChangeLog b/include/ChangeLog index 0be337dbfd46..3a3e2443e7e0 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2010-11-16 Ian Lance Taylor + + * simple-object.h (simple_object_attributes_merge): Declare, + replacing simple_object_attributes_compare. + 2010-11-04 Ian Lance Taylor * dwarf2.h (enum dwarf_source_language): Add DW_LANG_Go. diff --git a/include/simple-object.h b/include/simple-object.h index a72e4a19bc2f..c4786757a1e7 100644 --- a/include/simple-object.h +++ b/include/simple-object.h @@ -117,14 +117,15 @@ extern simple_object_attributes * simple_object_fetch_attributes (simple_object_read *simple_object, const char **errmsg, int *err); -/* Compare ATTRS1 and ATTRS2. If they could be linked together - without error, return NULL. Otherwise, return an error message, - set *ERR to an errno value or 0 if there isn't one. */ +/* Merge the FROM attributes into TO. If two objects with these + attributes could be linked together without error, returns NULL. + Otherwise, returns an error message, and sets *ERR to an errno + value or 0 if there isn't one. */ extern const char * -simple_object_attributes_compare (simple_object_attributes *attrs1, - simple_object_attributes *attrs2, - int *err); +simple_object_attributes_merge (simple_object_attributes *to, + simple_object_attributes *from, + int *err); /* Release all resources associated with ATTRS. */ diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 488fd2d094cf..ed0d0557e16f 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,22 @@ +2010-11-16 Ian Lance Taylor + + * simple-object.c (simple_object_attributes_merge): Rename from + simple_object_attributes_compare. Call merge field. + * simple-object-common.h (struct simple_object_functions): Rename + attributes_compare field to attribute_merge. + * simple-object-elf.c (EM_SPARC): Define. + (EM_SPARC32PLUS): Define. + (simple_object_elf_attributes_merge): Renamed from + simple_object_elf_attributes_compare. Permit EM_SPARC and + EM_SPARC32PLUS objects to be merged. + (simple_object_elf_functions): Update function name. + * simple-object-coff.c (simple_object_coff_attributes_merge): + Rename from simple_object_coff_attributes_compare. + (simple_object_coff_functions): Update function name. + * simple-object-mach-o.c (simple_object_mach_o_attributes_merge): + Renamed from simple_object_mach_o_attributes_compare. + (simple_object_mach_o_functions): Update function name. + 2010-11-16 H.J. Lu PR other/42670 diff --git a/libiberty/simple-object-coff.c b/libiberty/simple-object-coff.c index ff8fee46b74a..a7802a520760 100644 --- a/libiberty/simple-object-coff.c +++ b/libiberty/simple-object-coff.c @@ -457,15 +457,14 @@ simple_object_coff_release_read (void *data) /* Compare two attributes structures. */ static const char * -simple_object_coff_attributes_compare (void *data1, void *data2, int *err) +simple_object_coff_attributes_merge (void *todata, void *fromdata, int *err) { - struct simple_object_coff_attributes *attrs1 = - (struct simple_object_coff_attributes *) data1; - struct simple_object_coff_attributes *attrs2 = - (struct simple_object_coff_attributes *) data2; + struct simple_object_coff_attributes *to = + (struct simple_object_coff_attributes *) todata; + struct simple_object_coff_attributes *from = + (struct simple_object_coff_attributes *) fromdata; - if (attrs1->magic != attrs2->magic - || attrs1->is_big_endian != attrs2->is_big_endian) + if (to->magic != from->magic || to->is_big_endian != from->is_big_endian) { *err = 0; return "COFF object format mismatch"; @@ -797,7 +796,7 @@ const struct simple_object_functions simple_object_coff_functions = simple_object_coff_find_sections, simple_object_coff_fetch_attributes, simple_object_coff_release_read, - simple_object_coff_attributes_compare, + simple_object_coff_attributes_merge, simple_object_coff_release_attributes, simple_object_coff_start_write, simple_object_coff_write_to_file, diff --git a/libiberty/simple-object-common.h b/libiberty/simple-object-common.h index 8f743908e315..264b179955e3 100644 --- a/libiberty/simple-object-common.h +++ b/libiberty/simple-object-common.h @@ -123,10 +123,10 @@ struct simple_object_functions /* Release the private data for an simple_object_read. */ void (*release_read) (void *); - /* Compare the private data for the attributes of two files. If - they are the same, in the sense that they could be linked - together, return NULL. Otherwise return an error message. */ - const char *(*attributes_compare) (void *, void *, int *err); + /* Merge the private data for the attributes of two files. If they + could be linked together, return NULL. Otherwise return an error + message. */ + const char *(*attributes_merge) (void *, void *, int *err); /* Release the private data for an simple_object_attributes. */ void (*release_attributes) (void *); diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c index 5b8cfba1cd64..4196c537cde5 100644 --- a/libiberty/simple-object-elf.c +++ b/libiberty/simple-object-elf.c @@ -115,6 +115,11 @@ typedef struct { #define ET_REL 1 /* Relocatable file */ +/* Values for e_machine field of Ehdr. */ + +#define EM_SPARC 2 /* SUN SPARC */ +#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ + /* Special section index values. */ #define SHN_LORESERVE 0xFF00 /* Begin range of reserved indices */ @@ -604,20 +609,52 @@ simple_object_elf_release_read (void *data) /* Compare two attributes structures. */ static const char * -simple_object_elf_attributes_compare (void *data1, void *data2, int *err) +simple_object_elf_attributes_merge (void *todata, void *fromdata, int *err) { - struct simple_object_elf_attributes *attrs1 = - (struct simple_object_elf_attributes *) data1; - struct simple_object_elf_attributes *attrs2 = - (struct simple_object_elf_attributes *) data2; - - if (attrs1->ei_data != attrs2->ei_data - || attrs1->ei_class != attrs2->ei_class - || attrs1->machine != attrs2->machine) + struct simple_object_elf_attributes *to = + (struct simple_object_elf_attributes *) todata; + struct simple_object_elf_attributes *from = + (struct simple_object_elf_attributes *) fromdata; + + if (to->ei_data != from->ei_data || to->ei_class != from->ei_class) { *err = 0; return "ELF object format mismatch"; } + + if (to->machine != from->machine) + { + int ok; + + /* EM_SPARC and EM_SPARC32PLUS are compatible and force an + output of EM_SPARC32PLUS. */ + ok = 0; + switch (to->machine) + { + case EM_SPARC: + if (from->machine == EM_SPARC32PLUS) + { + to->machine = from->machine; + ok = 1; + } + break; + + case EM_SPARC32PLUS: + if (from->machine == EM_SPARC) + ok = 1; + break; + + default: + break; + } + + if (!ok) + { + *err = 0; + return "ELF machine number mismatch"; + } + } + return NULL; } @@ -908,7 +945,7 @@ const struct simple_object_functions simple_object_elf_functions = simple_object_elf_find_sections, simple_object_elf_fetch_attributes, simple_object_elf_release_read, - simple_object_elf_attributes_compare, + simple_object_elf_attributes_merge, simple_object_elf_release_attributes, simple_object_elf_start_write, simple_object_elf_write_to_file, diff --git a/libiberty/simple-object-mach-o.c b/libiberty/simple-object-mach-o.c index 4067b16bab5c..bbbbd09de580 100644 --- a/libiberty/simple-object-mach-o.c +++ b/libiberty/simple-object-mach-o.c @@ -624,16 +624,16 @@ simple_object_mach_o_release_read (void *data) /* Compare two attributes structures. */ static const char * -simple_object_mach_o_attributes_compare (void *data1, void *data2, int *err) +simple_object_mach_o_attributes_merge (void *todata, void *fromdata, int *err) { - struct simple_object_mach_o_attributes *attrs1 = - (struct simple_object_mach_o_attributes *) data1; - struct simple_object_mach_o_attributes *attrs2 = - (struct simple_object_mach_o_attributes *) data2; - - if (attrs1->magic != attrs2->magic - || attrs1->is_big_endian != attrs2->is_big_endian - || attrs1->cputype != attrs2->cputype) + struct simple_object_mach_o_attributes *to = + (struct simple_object_mach_o_attributes *) todata; + struct simple_object_mach_o_attributes *from = + (struct simple_object_mach_o_attributes *) fromdata; + + if (to->magic != from->magic + || to->is_big_endian != from->is_big_endian + || to->cputype != from->cputype) { *err = 0; return "Mach-O object format mismatch"; @@ -1014,7 +1014,7 @@ const struct simple_object_functions simple_object_mach_o_functions = simple_object_mach_o_find_sections, simple_object_mach_o_fetch_attributes, simple_object_mach_o_release_read, - simple_object_mach_o_attributes_compare, + simple_object_mach_o_attributes_merge, simple_object_mach_o_release_attributes, simple_object_mach_o_start_write, simple_object_mach_o_write_to_file, diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c index c9bd82f27141..d000cfc08067 100644 --- a/libiberty/simple-object.c +++ b/libiberty/simple-object.c @@ -257,20 +257,19 @@ simple_object_release_read (simple_object_read *sobj) XDELETE (sobj); } -/* Compare attributes. */ +/* Merge attributes. */ const char * -simple_object_attributes_compare (simple_object_attributes *attrs1, - simple_object_attributes *attrs2, - int *err) +simple_object_attributes_merge (simple_object_attributes *to, + simple_object_attributes *from, + int *err) { - if (attrs1->functions != attrs2->functions) + if (to->functions != from->functions) { *err = 0; return "different object file format"; } - return attrs1->functions->attributes_compare (attrs1->data, attrs2->data, - err); + return to->functions->attributes_merge (to->data, from->data, err); } /* Release an attributes structure. */ -- 2.39.2