[PATCH v2 2/4] gold: Correctly get and put r_info for Mips64el.

H.J. Lu hjl.tools@gmail.com
Tue Jan 12 18:08:00 GMT 2016


On Mon, Jan 11, 2016 at 7:01 PM, Cary Coutant <ccoutant@gmail.com> wrote:
>> elfcpp/
>>         * elfcpp.h (class Rel): Add new constructor.
>>         (class Rel_write): Likewise.
>>         (class Rela): Likewise.
>>         (class Rela_write): Likewise.
>>         (Rela::get_r_info): Correctly get r_info for Mips64 little endian.
>>         (Rela_write::put_r_info): Correctly put r_info for Mips64 little endian.
>>
>> gold/
>>         * gc.h (gc_process_relocs): Call new constructor for Reltype.
>>         * target-reloc.h (scan_relocs): Likewise.
>>         (relocate_section): Likewise.
>>         (scan_relocatable_relocs): Likewise.
>>         (relocate_relocs): Call new constructor for Reltype and for Reltype_write.
>>         * target.h (Target::is_mips64el): New virtual function.
>
> I've taken a different approach. Rather than store a flag in the
> elfcpp accessor class, which will have to be tested every time the
> r_info field is accessed, I've extended the Classify_reloc interface
> to provide methods for reading the r_sym and r_type fields. For the
> templated routines in gc.h and target-reloc.h that use Classify_reloc
> or Default_scan_relocatable_relocs, this allows us to provide the MIPS
> accessor functions without a runtime check.
>
> The commit description and ChangeLog entry are copied below. The patch
> is attached.
>
> -cary
>
>
> For MIPS-64, the r_info field in the relocation format is
> replaced by several individual fields, including r_sym and
> r_type. To enable support for this format, I've refactored
> target-independent code to remove almost all uses of the r_info
> field. (I've left alone a couple of routines used only for
> incremental linking, which I can update if/when the MIPS target
> adds support for incremental linking.)
>
> For routines that are already templated on a Classify_reloc class
> (namely, gc_process_relocs, relocate_section, and
> relocate_relocs), I've extended the Classify_reloc interface to
> include sh_type (which no longer needs to be a separate template
> parameter) as well as get_r_sym() and get_r_type() methods for
> extracting the r_sym and r_type fields. For
> scan_relocatable_relocs, I've extended the
> Default_scan_relocatable_relocs class by converting it to a class
> template with Classify_reloc as a template parameter. For the
> remaining routines that need to access r_sym, I've added a
> virtual Target::get_r_sym() method with an override for the MIPS
> target.
>
> In elfcpp, I've added Mips64_rel, etc., accessor classes and
> corresponding internal data structures. The MIPS target uses
> these new classes within its own Mips_classify_reloc class.
> The Mips64_ accessor classes also expose the r_ssym, r_type2,
> and r_type3 fields from the relocation.
>
> These changes should be functionally the same for all but the
> MIPS target.
>
>
> 2016-01-11  Cary Coutant  <ccoutant@gmail.com>
>
> elfcpp/
>         * elfcpp.h (Mips64_rel, Mips64_rel_write): New classes.
>         (Mips64_rela, Mips64_rela_write): New classes.
>         * elfcpp_internal.h (Mips64_rel_data, Mips64_rela_data): New structs.
>
>

It failed to build with GCC 4.2:

/net/gnu-6/export/linux/src/binutils/binutils/gold/../elfcpp/elfcpp_internal.h:187:
error: using ‘typename’ outside of template
/net/gnu-6/export/linux/src/binutils/binutils/gold/../elfcpp/elfcpp_internal.h:197:
error: using ‘typename’ outside of template
/net/gnu-6/export/linux/src/binutils/binutils/gold/../elfcpp/elfcpp_internal.h:203:
error: using ‘typename’ outside of template

This patch fixes the build.

-- 
H.J.
---
diff --git a/elfcpp/elfcpp_internal.h b/elfcpp/elfcpp_internal.h
index edca55f..2aaeeba 100644
--- a/elfcpp/elfcpp_internal.h
+++ b/elfcpp/elfcpp_internal.h
@@ -184,7 +184,7 @@ struct Rela_data

 struct Mips64_rel_data
 {
-  typename Elf_types<64>::Elf_Addr r_offset;
+  Elf_types<64>::Elf_Addr r_offset;
   Elf_Word r_sym;
   unsigned char r_ssym;
   unsigned char r_type3;
@@ -194,13 +194,13 @@ struct Mips64_rel_data

 struct Mips64_rela_data
 {
-  typename Elf_types<64>::Elf_Addr r_offset;
+  Elf_types<64>::Elf_Addr r_offset;
   Elf_Word r_sym;
   unsigned char r_ssym;
   unsigned char r_type3;
   unsigned char r_type2;
   unsigned char r_type;
-  typename Elf_types<64>::Elf_Swxword r_addend;
+  Elf_types<64>::Elf_Swxword r_addend;
 };

 // An entry in the ELF SHT_DYNAMIC section aka PT_DYNAMIC segment.



More information about the Binutils mailing list