From a848a2271b9bd45400e875a2518ebedf1efba2fa Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Wed, 10 Aug 2016 20:03:02 +0100 Subject: [PATCH] MIPS/BFD: Add microMIPS annotation to LA25 stub symbols Fix a problem with missing microMIPS symbol annotation with microMIPS LA25 stub symbols. The consequence of the issue is these symbols appear in the symbol table as regular MIPS symbols with the ISA bit set, as shown with the example below: $ cat la25a.s .abicalls .global f1 .ent f1 f1: .set noreorder .cpload $25 .set reorder .option pic0 jal f2 .option pic2 jr $31 .end f1 .global f2 .ent f2 f2: jr $31 .end f2 $ cat la25b.s .abicalls .option pic0 .global __start .ent __start __start: jal f1 jal f2 .end __start $ as -mmicromips -32 -EB -o la25a.o la25a.s $ as -mmicromips -32 -EB -o la25b.o la25b.s $ ld -melf32btsmip -o la25 la25a.o la25b.o $ readelf -s la25 Symbol table '.symtab' contains 18 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00400098 0 SECTION LOCAL DEFAULT 1 2: 004000b0 0 SECTION LOCAL DEFAULT 2 3: 004000d0 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 SECTION LOCAL DEFAULT 4 5: 00000000 0 SECTION LOCAL DEFAULT 5 6: 00418110 0 NOTYPE LOCAL DEFAULT 3 _gp 7: 004000e1 16 FUNC LOCAL DEFAULT 3 .pic.f1 8: 004000d1 16 FUNC LOCAL DEFAULT 3 .pic.f2 9: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _fdata 10: 00400110 16 FUNC GLOBAL DEFAULT [MICROMIPS] 3 __start 11: 00400106 2 FUNC GLOBAL DEFAULT [MICROMIPS] 3 f2 12: 004000d0 0 NOTYPE GLOBAL DEFAULT 3 _ftext 13: 00410120 0 NOTYPE GLOBAL DEFAULT 3 __bss_start 14: 004000f0 22 FUNC GLOBAL DEFAULT [MICROMIPS] 3 f1 15: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _edata 16: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _end 17: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _fbss $ where microMIPS annotation is missing for `.pic.f1' and `.pic.f2' even though these stubs are associated with microMIPS functions `f1' and `f2' respectively. Add the missing annotation then, by copying it from the function symbol an LA25 stub is associated with, correcting the example above: $ readelf -s la25 Symbol table '.symtab' contains 18 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00400098 0 SECTION LOCAL DEFAULT 1 2: 004000b0 0 SECTION LOCAL DEFAULT 2 3: 004000d0 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 SECTION LOCAL DEFAULT 4 5: 00000000 0 SECTION LOCAL DEFAULT 5 6: 00418110 0 NOTYPE LOCAL DEFAULT 3 _gp 7: 004000e0 16 FUNC LOCAL DEFAULT [MICROMIPS] 3 .pic.f1 8: 004000d0 16 FUNC LOCAL DEFAULT [MICROMIPS] 3 .pic.f2 9: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _fdata 10: 00400110 16 FUNC GLOBAL DEFAULT [MICROMIPS] 3 __start 11: 00400106 2 FUNC GLOBAL DEFAULT [MICROMIPS] 3 f2 12: 004000d0 0 NOTYPE GLOBAL DEFAULT 3 _ftext 13: 00410120 0 NOTYPE GLOBAL DEFAULT 3 __bss_start 14: 004000f0 22 FUNC GLOBAL DEFAULT [MICROMIPS] 3 f1 15: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _edata 16: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _end 17: 00410120 0 NOTYPE GLOBAL DEFAULT 3 _fbss $ This problem has been there since the beginning of microMIPS support: commit df58fc944dbc6d5efd8d3826241b64b6af22f447 Author: Richard Sandiford Date: Sun Jul 24 14:20:15 2011 +0000 , ("MIPS: microMIPS ASE support"). bfd/ * elfxx-mips.c (mips_elf_create_stub_symbol): For a microMIPS stub also add STO_MICROMIPS annotation. --- bfd/ChangeLog | 5 +++++ bfd/elfxx-mips.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ac8230d05f6..3ddafcb09d4 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2016-08-10 Maciej W. Rozycki + + * elfxx-mips.c (mips_elf_create_stub_symbol): For a microMIPS + stub also add STO_MICROMIPS annotation. + 2016-08-10 Maciej W. Rozycki * elfxx-mips.c (mips_elf_calculate_relocation): Set the ISA bit diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index cfb9a52af02..6690428c644 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -1578,12 +1578,13 @@ mips_elf_create_stub_symbol (struct bfd_link_info *info, const char *prefix, asection *s, bfd_vma value, bfd_vma size) { + bfd_boolean micromips_p = ELF_ST_IS_MICROMIPS (h->root.other); struct bfd_link_hash_entry *bh; struct elf_link_hash_entry *elfh; char *name; bfd_boolean res; - if (ELF_ST_IS_MICROMIPS (h->root.other)) + if (micromips_p) value |= 1; /* Create a new symbol. */ @@ -1601,6 +1602,8 @@ mips_elf_create_stub_symbol (struct bfd_link_info *info, elfh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); elfh->size = size; elfh->forced_local = 1; + if (micromips_p) + elfh->other = ELF_ST_SET_MICROMIPS (elfh->other); return TRUE; } -- 2.30.2