Fix PR18841 ifunc relocation ordering
authorChristophe Lyon <christophe.lyon@arm.com>
Mon, 2 Jan 2023 15:46:31 +0000 (15:46 +0000)
committerChristophe Lyon <christophe.lyon@arm.com>
Mon, 9 Jan 2023 15:51:53 +0000 (16:51 +0100)
In order to get the ifunc relocs properly sorted the correct class
needs to be returned.  The code mimics what has been done for AArch64.

Fixes:
FAIL: Run pr18841 with libpr18841b.so
FAIL: Run pr18841 with libpr18841c.so
FAIL: Run pr18841 with libpr18841bn.so (-z now)
FAIL: Run pr18841 with libpr18841cn.so (-z now)

bfd/
PR ld/18841
* elf32-arm.c (elf32_arm_reloc_type_class): Return
reloc_class_ifunc for ifunc symbols.

ld/testsuite/
* ld-arm/ifunc-12.rd: Update relocations order.
* ld-arm/ifunc-3.rd: Likewise.
* ld-arm/ifunc-4.rd: Likewise.

bfd/elf32-arm.c
ld/testsuite/ld-arm/ifunc-12.rd
ld/testsuite/ld-arm/ifunc-3.rd
ld/testsuite/ld-arm/ifunc-4.rd

index 0cd3aec143683c339dc41c0852c2bafa124b9aac..96ba509f505dde0d88f23d595e7520e4dc737624 100644 (file)
@@ -17691,6 +17691,35 @@ elf32_arm_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
                            const asection *rel_sec ATTRIBUTE_UNUSED,
                            const Elf_Internal_Rela *rela)
 {
+  struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
+
+  if (htab->root.dynsym != NULL
+      && htab->root.dynsym->contents != NULL)
+    {
+      /* Check relocation against STT_GNU_IFUNC symbol if there are
+        dynamic symbols.  */
+      bfd *abfd = info->output_bfd;
+      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+      unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
+      if (r_symndx != STN_UNDEF)
+       {
+         Elf_Internal_Sym sym;
+         if (!bed->s->swap_symbol_in (abfd,
+                                      (htab->root.dynsym->contents
+                                       + r_symndx * bed->s->sizeof_sym),
+                                      0, &sym))
+           {
+             /* xgettext:c-format */
+             _bfd_error_handler (_("%pB symbol number %lu references"
+                                   " nonexistent SHT_SYMTAB_SHNDX section"),
+                                 abfd, r_symndx);
+             /* Ideally an error class should be returned here.  */
+           }
+         else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
+           return reloc_class_ifunc;
+       }
+    }
+
   switch ((int) ELF32_R_TYPE (rela->r_info))
     {
     case R_ARM_RELATIVE:
index 69ed420e0d645ad28d550e93dda13f1a3d5c866b..c5d62c1ac520b49400fc69f9a583636b8a87aa46 100644 (file)
@@ -5,10 +5,6 @@ Relocation section '\.rel\.dyn' at offset 0x8000 contains 16 entries:
 00010020  ......17 R_ARM_RELATIVE   
 0001100c  ......17 R_ARM_RELATIVE   
 00011018  ......17 R_ARM_RELATIVE   
-00010008  ......02 R_ARM_ABS32       f2\(\)       f2
-00011024  ......15 R_ARM_GLOB_DAT    f2\(\)       f2
-00010014  ......02 R_ARM_ABS32       f2t\(\)      f2t
-0001101c  ......15 R_ARM_GLOB_DAT    f2t\(\)      f2t
 00010004  ......a0 R_ARM_IRELATIVE  
 0001000c  ......a0 R_ARM_IRELATIVE  
 00010010  ......a0 R_ARM_IRELATIVE  
@@ -17,3 +13,7 @@ Relocation section '\.rel\.dyn' at offset 0x8000 contains 16 entries:
 00011014  ......a0 R_ARM_IRELATIVE  
 00011020  ......a0 R_ARM_IRELATIVE  
 00011028  ......a0 R_ARM_IRELATIVE  
+00010008  ......02 R_ARM_ABS32       f2\(\)       f2
+00011024  ......15 R_ARM_GLOB_DAT    f2\(\)       f2
+00010014  ......02 R_ARM_ABS32       f2t\(\)      f2t
+0001101c  ......15 R_ARM_GLOB_DAT    f2t\(\)      f2t
index e3973e44c3d3ed490e4d9ae112d88896fb79d785..274a4e45ac42bb293955544aeb4ba7a0422269a5 100644 (file)
@@ -4,16 +4,16 @@ Relocation section '\.rel\.dyn' at offset 0x8000 contains 13 entries:
 00010004  ......17 R_ARM_RELATIVE   
 0001101c  ......17 R_ARM_RELATIVE   
 00011020  ......17 R_ARM_RELATIVE   
-00010014  ......02 R_ARM_ABS32       f2\(\)       f2
-00010018  ......03 R_ARM_REL32       f2\(\)       f2
-00011024  ......15 R_ARM_GLOB_DAT    f2\(\)       f2
-00010024  ......02 R_ARM_ABS32       f4\(\)       f4
-00011028  ......15 R_ARM_GLOB_DAT    f4\(\)       f4
 0001000c  ......a0 R_ARM_IRELATIVE  
 0001001c  ......a0 R_ARM_IRELATIVE  
 00011010  ......a0 R_ARM_IRELATIVE  
 00011014  ......a0 R_ARM_IRELATIVE  
 00011018  ......a0 R_ARM_IRELATIVE  
+00010014  ......02 R_ARM_ABS32       f2\(\)       f2
+00010018  ......03 R_ARM_REL32       f2\(\)       f2
+00011024  ......15 R_ARM_GLOB_DAT    f2\(\)       f2
+00010024  ......02 R_ARM_ABS32       f4\(\)       f4
+00011028  ......15 R_ARM_GLOB_DAT    f4\(\)       f4
 
 Relocation section '\.rel\.plt' at offset 0x8068 contains 1 entry:
  Offset     Info    Type            Sym\.Value  Sym\. Name
index 43a0019ca91e91d293ec85b197f958a5719ca7d3..b8079d5c6155f34d7838791ce756c4d145427369 100644 (file)
@@ -3,36 +3,6 @@ Relocation section '\.rel\.dyn' at offset 0x8000 contains 62 entries:
  Offset     Info    Type            Sym\.Value  Sym\. Name
 0001106c  ......17 R_ARM_RELATIVE   
 00011070  ......17 R_ARM_RELATIVE   
-00010034  ......02 R_ARM_ABS32       aaf2\(\)     aaf2
-00010038  ......03 R_ARM_REL32       aaf2\(\)     aaf2
-00011088  ......15 R_ARM_GLOB_DAT    aaf2\(\)     aaf2
-0001003c  ......02 R_ARM_ABS32       atf2\(\)     atf2
-00010040  ......03 R_ARM_REL32       atf2\(\)     atf2
-00011074  ......15 R_ARM_GLOB_DAT    atf2\(\)     atf2
-00010044  ......02 R_ARM_ABS32       abf2\(\)     abf2
-00010048  ......03 R_ARM_REL32       abf2\(\)     abf2
-000110a0  ......15 R_ARM_GLOB_DAT    abf2\(\)     abf2
-0001004c  ......02 R_ARM_ABS32       taf2\(\)     taf2
-00010050  ......03 R_ARM_REL32       taf2\(\)     taf2
-00011084  ......15 R_ARM_GLOB_DAT    taf2\(\)     taf2
-00010054  ......02 R_ARM_ABS32       ttf2\(\)     ttf2
-00010058  ......03 R_ARM_REL32       ttf2\(\)     ttf2
-0001107c  ......15 R_ARM_GLOB_DAT    ttf2\(\)     ttf2
-0001005c  ......02 R_ARM_ABS32       tbf2\(\)     tbf2
-00010060  ......03 R_ARM_REL32       tbf2\(\)     tbf2
-00011080  ......15 R_ARM_GLOB_DAT    tbf2\(\)     tbf2
-00010094  ......02 R_ARM_ABS32       aaf4\(\)     aaf4
-00011078  ......15 R_ARM_GLOB_DAT    aaf4\(\)     aaf4
-0001009c  ......02 R_ARM_ABS32       atf4\(\)     atf4
-00011098  ......15 R_ARM_GLOB_DAT    atf4\(\)     atf4
-000100a4  ......02 R_ARM_ABS32       abf4\(\)     abf4
-0001108c  ......15 R_ARM_GLOB_DAT    abf4\(\)     abf4
-000100ac  ......02 R_ARM_ABS32       taf4\(\)     taf4
-0001109c  ......15 R_ARM_GLOB_DAT    taf4\(\)     taf4
-000100b4  ......02 R_ARM_ABS32       ttf4\(\)     ttf4
-00011094  ......15 R_ARM_GLOB_DAT    ttf4\(\)     ttf4
-000100bc  ......02 R_ARM_ABS32       tbf4\(\)     tbf4
-00011090  ......15 R_ARM_GLOB_DAT    tbf4\(\)     tbf4
 00010004  ......a0 R_ARM_IRELATIVE  
 0001000c  ......a0 R_ARM_IRELATIVE  
 00010014  ......a0 R_ARM_IRELATIVE  
@@ -63,6 +33,36 @@ Relocation section '\.rel\.dyn' at offset 0x8000 contains 62 entries:
 00011060  ......a0 R_ARM_IRELATIVE  
 00011064  ......a0 R_ARM_IRELATIVE  
 00011068  ......a0 R_ARM_IRELATIVE  
+00010034  ......02 R_ARM_ABS32       aaf2\(\)     aaf2
+00010038  ......03 R_ARM_REL32       aaf2\(\)     aaf2
+00011088  ......15 R_ARM_GLOB_DAT    aaf2\(\)     aaf2
+0001003c  ......02 R_ARM_ABS32       atf2\(\)     atf2
+00010040  ......03 R_ARM_REL32       atf2\(\)     atf2
+00011074  ......15 R_ARM_GLOB_DAT    atf2\(\)     atf2
+00010044  ......02 R_ARM_ABS32       abf2\(\)     abf2
+00010048  ......03 R_ARM_REL32       abf2\(\)     abf2
+000110a0  ......15 R_ARM_GLOB_DAT    abf2\(\)     abf2
+0001004c  ......02 R_ARM_ABS32       taf2\(\)     taf2
+00010050  ......03 R_ARM_REL32       taf2\(\)     taf2
+00011084  ......15 R_ARM_GLOB_DAT    taf2\(\)     taf2
+00010054  ......02 R_ARM_ABS32       ttf2\(\)     ttf2
+00010058  ......03 R_ARM_REL32       ttf2\(\)     ttf2
+0001107c  ......15 R_ARM_GLOB_DAT    ttf2\(\)     ttf2
+0001005c  ......02 R_ARM_ABS32       tbf2\(\)     tbf2
+00010060  ......03 R_ARM_REL32       tbf2\(\)     tbf2
+00011080  ......15 R_ARM_GLOB_DAT    tbf2\(\)     tbf2
+00010094  ......02 R_ARM_ABS32       aaf4\(\)     aaf4
+00011078  ......15 R_ARM_GLOB_DAT    aaf4\(\)     aaf4
+0001009c  ......02 R_ARM_ABS32       atf4\(\)     atf4
+00011098  ......15 R_ARM_GLOB_DAT    atf4\(\)     atf4
+000100a4  ......02 R_ARM_ABS32       abf4\(\)     abf4
+0001108c  ......15 R_ARM_GLOB_DAT    abf4\(\)     abf4
+000100ac  ......02 R_ARM_ABS32       taf4\(\)     taf4
+0001109c  ......15 R_ARM_GLOB_DAT    taf4\(\)     taf4
+000100b4  ......02 R_ARM_ABS32       ttf4\(\)     ttf4
+00011094  ......15 R_ARM_GLOB_DAT    ttf4\(\)     ttf4
+000100bc  ......02 R_ARM_ABS32       tbf4\(\)     tbf4
+00011090  ......15 R_ARM_GLOB_DAT    tbf4\(\)     tbf4
 
 Relocation section '\.rel\.plt' at offset 0x81f0 contains 6 entries:
  Offset     Info    Type            Sym\.Value  Sym\. Name