Committed: fix CRIS synthetic symbols (X@plt)
Hans-Peter Nilsson
hans-peter.nilsson@axis.com
Mon Jun 18 06:22:00 GMT 2012
The bug caused the wrong X in X@plt to be dumped, which caused
some head-scratching while looking into glibc check-localplt
results. Comments in code and test-case says what else needs to
be said. Except, apologies for entering the test-cases into the
ld testsuite; they should better be in the binutils test-suite,
except that run_dump_test in the latter supports just a subset
of the ld run_dump_test (for example, not supporting multiple
source files). And I didn't think it worthwhile to sort that
out as there already is a (trivial) test-case for CRIS
synthesyms in the ld testsuite. And no test-case for
executables; I only did a spot-check. Maybe later (N.B. ld-cris
is #4 in number of target-specific ld test-files; almost feeling
guilty seeing recent mass adjustment edits).
Committed.
bfd:
* elf32-cris.c (cris_elf_plt_sym_val): Rewrite to work in presence
of merged .got and .got.plt entries.
ld/testsuite:
* ld-cris/dso-pltdis1.d, ld-cris/dso-pltdis2.d, dsofng.s
dsofn4g.s: New tests.
Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.122
diff -p -u -r1.122 elf32-cris.c
--- elf32-cris.c 17 Jun 2012 07:28:29 -0000 1.122
+++ elf32-cris.c 18 Jun 2012 06:15:21 -0000
@@ -2719,16 +2719,64 @@ cris_elf_gc_sweep_hook (bfd *abfd,
/* The elf_backend_plt_sym_val hook function. */
static bfd_vma
-cris_elf_plt_sym_val (bfd_vma i, const asection *plt,
- const arelent *rel ATTRIBUTE_UNUSED)
+cris_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, const asection *plt,
+ const arelent *rel)
{
bfd_size_type plt_entry_size;
+ bfd_size_type pltoffs;
+ bfd *abfd = plt->owner;
+ /* Same for CRIS and CRIS v32; see elf_cris_(|pic_)plt_entry(|_v32)[]. */
+ bfd_size_type plt_entry_got_offset = 2;
+ bfd_size_type plt_sec_size;
+ bfd_size_type got_vma_for_dyn;
+ asection *got;
+
+ /* FIXME: the .got section should be readily available also when
+ we're not linking. */
+ if ((got = bfd_get_section_by_name (abfd, ".got")) == NULL)
+ return (bfd_vma) -1;
+
+ plt_sec_size = bfd_section_size (plt->owner, plt);
plt_entry_size
- = (bfd_get_mach (plt->owner) == bfd_mach_cris_v32
+ = (bfd_get_mach (abfd) == bfd_mach_cris_v32
? PLT_ENTRY_SIZE_V32 : PLT_ENTRY_SIZE);
- return plt->vma + (i + 1) * plt_entry_size;
+ /* Data in PLT is GOT-relative for DYN, but absolute for EXE. */
+ got_vma_for_dyn = (abfd->flags & EXEC_P) ? 0 : got->vma;
+
+ /* Because we can have merged GOT entries; a single .got entry for
+ both GOT and the PLT part of the GOT (.got.plt), the index of the
+ reloc in .rela.plt is not the same as the index in the PLT.
+ Instead, we have to hunt down the GOT offset in the PLT that
+ corresponds to that of this reloc. Unfortunately, we will only
+ be called for the .rela.plt relocs, so we'll miss synthetic
+ symbols for .plt entries with merged GOT entries. (FIXME:
+ fixable by providing our own bfd_elf32_get_synthetic_symtab.
+ Doesn't seem worthwile at time of this writing.) FIXME: we've
+ gone from O(1) to O(N) (N number of PLT entries) for finding each
+ PLT address. Shouldn't matter in practice though. */
+
+ for (pltoffs = plt_entry_size;
+ pltoffs < plt_sec_size;
+ pltoffs += plt_entry_size)
+ {
+ bfd_size_type got_offset;
+ bfd_byte gotoffs_raw[4];
+
+ if (!bfd_get_section_contents (abfd, (asection *) plt, gotoffs_raw,
+ pltoffs + plt_entry_got_offset,
+ sizeof (gotoffs_raw)))
+ return (bfd_vma) -1;
+
+ got_offset = bfd_get_32 (abfd, gotoffs_raw);
+ if (got_offset + got_vma_for_dyn == rel->address)
+ return plt->vma + pltoffs;
+ }
+
+ /* While it's tempting to BFD_ASSERT that we shouldn't get here,
+ that'd not be graceful behavior for invalid input. */
+ return (bfd_vma) -1;
}
/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
Index: ld-cris/dso-pltdis1.d
===================================================================
RCS file: ld-cris/dso-pltdis1.d
diff -N ld-cris/dso-pltdis1.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/dso-pltdis1.d 18 Jun 2012 06:13:53 -0000
@@ -0,0 +1,61 @@
+#source: dsov32-1.s
+#source: dsov32-2.s
+#source: dsofn4g.s
+#as: --pic --no-underscore --march=v32 --em=criself
+#ld: --shared -m crislinux
+#objdump: -d -R
+
+# Check dissassembly of the .plt section, specifically the synthetic
+# symbols, in a DSO in which a .got.plt entry has been merged into a
+# regular .got entry. There was a bug in which some (i.e. subsequent
+# with regards to reloc order) synthetic X@plt entries were wrong if
+# there were merged .got entries present; dsofn4@plt below. The
+# alternatives in the matching regexps are placeholders for a future
+# improvement: synthetic symbols for .plt entries with merged .got
+# entries (lost as a consequence of the relocs no longer accounted for
+# in .rela.plt and the default synthetic-symbol implementation just
+# iterating over .rela.plt).
+
+.*: file format elf32-cris
+
+Disassembly of section \.plt:
+
+0+1b4 <(dsofn4@plt-0x1a|dsofn@plt-0x34)>:
+ 1b4: 84e2 subq 4,\$sp
+ 1b6: 0401 addoq 4,\$r0,\$acr
+ 1b8: 7e7a move \$mof,\[\$sp\]
+ 1ba: 3f7a move \[\$acr\],\$mof
+ 1bc: 04f2 addq 4,\$acr
+ 1be: 6ffa move\.d \[\$acr\],\$acr
+ 1c0: bf09 jump \$acr
+ 1c2: b005 nop
+ \.\.\.
+#...
+ 1ce: 6f0d ..00 0000 addo\.d .*
+ 1d4: 6ffa move\.d \[\$acr\],\$acr
+ 1d6: bf09 jump \$acr
+ 1d8: b005 nop
+ 1da: 3f7e .... .... move .*,\$mof
+ 1e0: bf0e .... .... ba .*
+ 1e6: b005 nop
+
+0+1e8 <dsofn@plt>:
+ 1e8: 6f0d ..00 0000 addo\.d .*
+ 1ee: 6ffa move\.d \[\$acr\],\$acr
+ 1f0: bf09 jump \$acr
+ 1f2: b005 nop
+ 1f4: 3f7e .... .... move .*,\$mof
+ 1fa: bf0e baff ffff ba 1b4 <(dsofn4@plt-0x1a|dsofn@plt-0x34)>
+ 200: b005 nop
+
+Disassembly of section \.text:
+#...
+0+202 <dsofn3>:
+ 202: bfbe e6ff ffff bsr 1e8 <dsofn@plt>
+ 208: b005 nop
+
+0+20a <dsofn4>:
+ 20a: 7f0d ae20 0000 lapc 22b8 <_GLOBAL_OFFSET_TABLE_>,\$r0
+ 210: 5f0d 1400 addo\.w 0x14,\$r0,\$acr
+ 214: bfbe baff ffff bsr 1ce <(dsofn4@plt|dsofn@plt-0x1a)>
+#pass
Index: ld-cris/dso-pltdis2.d
===================================================================
RCS file: ld-cris/dso-pltdis2.d
diff -N ld-cris/dso-pltdis2.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/dso-pltdis2.d 18 Jun 2012 06:13:53 -0000
@@ -0,0 +1,54 @@
+#source: dsov32-1.s
+#source: dsov32-2.s
+#source: dsofng.s
+#as: --pic --no-underscore --march=v32 --em=criself
+#ld: --shared -m crislinux
+#objdump: -d
+
+# Complement to dso-pltdis1.d; merging the other .got.plt entry.
+# Depending on reloc order, one of the tests would fail.
+
+.*: file format elf32-cris
+
+Disassembly of section \.plt:
+
+0+1b4 <(dsofn4@plt-0x1a|dsofn@plt-0x34)>:
+
+ 1b4: 84e2 subq 4,\$sp
+ 1b6: 0401 addoq 4,\$r0,\$acr
+ 1b8: 7e7a move \$mof,\[\$sp\]
+ 1ba: 3f7a move \[\$acr\],\$mof
+ 1bc: 04f2 addq 4,\$acr
+ 1be: 6ffa move\.d \[\$acr\],\$acr
+ 1c0: bf09 jump \$acr
+ 1c2: b005 nop
+ \.\.\.
+
+000001ce <dsofn4@plt>:
+ 1ce: 6f0d ..00 0000 addo\.d .*
+ 1d4: 6ffa move\.d \[\$acr\],\$acr
+ 1d6: bf09 jump \$acr
+ 1d8: b005 nop
+ 1da: 3f7e .... .... move .*,\$mof
+ 1e0: bf0e .... .... ba .*
+ 1e6: b005 nop
+#...
+ 1e8: 6f0d ..00 0000 addo\.d .*
+ 1ee: 6ffa move\.d \[\$acr\],\$acr
+ 1f0: bf09 jump \$acr
+ 1f2: b005 nop
+ 1f4: 3f7e .... .... move .*,\$mof
+ 1fa: bf0e .... .... ba .*
+ 200: b005 nop
+
+Disassembly of section \.text:
+#...
+0+202 <dsofn3>:
+ 202: bfbe e6ff ffff bsr 1e8 <(dsofn@plt|dsofn4@plt\+0x1a)>
+ 208: b005 nop
+
+0+20a <dsofn4>:
+ 20a: 7f0d ae20 0000 lapc 22b8 <_GLOBAL_OFFSET_TABLE_>,\$r0
+ 210: 5f0d ..00 addo\.w 0x..,\$r0,\$acr
+ 214: bfbe baff ffff bsr 1ce <dsofn4@plt>
+#pass
Index: ld-cris/dsofn4g.s
===================================================================
RCS file: ld-cris/dsofn4g.s
diff -N ld-cris/dsofn4g.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/dsofn4g.s 18 Jun 2012 06:13:53 -0000
@@ -0,0 +1,3 @@
+ .text
+x:
+ move.d dsofn4:GOT,$r10
Index: ld-cris/dsofng.s
===================================================================
RCS file: ld-cris/dsofng.s
diff -N ld-cris/dsofng.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/dsofng.s 18 Jun 2012 06:13:53 -0000
@@ -0,0 +1,3 @@
+ .text
+x:
+ move.d dsofn:GOT,$r10
brgds, H-P
More information about the Binutils
mailing list