MIPS/BFD: Do not redirect to discarded lazy binding stubs
authorMaciej W. Rozycki <macro@mips.com>
Mon, 9 Jul 2018 20:30:44 +0000 (21:30 +0100)
committerMaciej W. Rozycki <macro@mips.com>
Mon, 9 Jul 2018 20:30:44 +0000 (21:30 +0100)
commit4b8377e7dbd9e53149268685ba4810a7b09fb0cb
tree8335ebd705743370595fdb9eb3cd611a3bbad3ed
parent055303e28f70880f7b2c3e44df0ba7646fc85cf8
MIPS/BFD: Do not redirect to discarded lazy binding stubs

Correct a MIPS/BFD linker issue with dynamic symbol and corresponding
GOT entry values being redirected to lazy binding stubs where the stubs
section has been discarded by assigning to the `/DISCARD/' output
section in the linker script used.  The issue manifests itself by the
values entered being relative to the absolute section, which is what any
discarded sections are internally assigned in the linker.

For the `stub-dynsym-2.s' piece of code included as a test case with
this change this issue results in the dynamic symbol table and the GOT
looking like:

Symbol table '.dynsym' contains 3 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000010     0 FUNC    GLOBAL DEFAULT  UND bar
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND foo

Primary GOT:
 Canonical gp value: 00097ff0

 Reserved entries:
   Address     Access  Initial Purpose
  00090000 -32752(gp) 00000000 Lazy resolver
  00090004 -32748(gp) 80000000 Module pointer (GNU extension)

 Global entries:
   Address     Access  Initial Sym.Val. Type    Ndx Name
  00090008 -32744(gp) 00000010 00000010 FUNC    UND bar
  0009000c -32740(gp) 00000000 00000000 FUNC    UND foo

if assembled to regular MIPS code, or:

Symbol table '.dynsym' contains 3 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000d     0 FUNC    GLOBAL DEFAULT  UND bar
     2: 00000001     0 FUNC    GLOBAL DEFAULT  UND foo

Primary GOT:
 Canonical gp value: 00097ff0

 Reserved entries:
   Address     Access  Initial Purpose
  00090000 -32752(gp) 00000000 Lazy resolver
  00090004 -32748(gp) 80000000 Module pointer (GNU extension)

 Global entries:
   Address     Access  Initial Sym.Val. Type    Ndx Name
  00090008 -32744(gp) 0000000d 0000000d FUNC    UND bar
  0009000c -32740(gp) 00000001 00000001 FUNC    UND foo

if assembled to microMIPS code.  Symbol values and GOT entries record
the offset into the inexistent stubs section and the ISA bit rather than
zero, which would be the case if a lazy binding stub was not used for
other reasons, such as the value of the symbol being taken for a purpose
other than making a function call (e.g. an R_MIPS_GOT16 relocation).

Correct the issue by refraining from redirecting symbols to lazy binding
stubs if the stubs section is going to be discarded.

bfd/
* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Don't set
`->needs_lazy_stub' if the stubs output section is the absolute
section.

ld/
* testsuite/ld-mips-elf/stub-dynsym-2.dd: New test.
* testsuite/ld-mips-elf/stub-dynsym-2.gd: New test.
* testsuite/ld-mips-elf/stub-dynsym-2.sd: New test.
* testsuite/ld-mips-elf/stub-dynsym-discard-2.gd: New test.
* testsuite/ld-mips-elf/stub-dynsym-discard-2.sd: New test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-2.dd: New test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-2.gd: New test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-2.sd: New test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.dd: New
test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.gd: New
test.
* testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.sd: New
test.
* testsuite/ld-mips-elf/stub-dynsym-2.ld: New test linker
script.
* testsuite/ld-mips-elf/stub-dynsym-discard-2.ld: New test
linker script.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
18 files changed:
bfd/ChangeLog
bfd/elfxx-mips.c
ld/ChangeLog
ld/testsuite/ld-mips-elf/mips-elf.exp
ld/testsuite/ld-mips-elf/stub-dynsym-2.dd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-2.gd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-2.ld [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-2.s [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-2.sd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-discard-2.gd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-discard-2.ld [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-discard-2.sd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-2.dd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-2.gd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-2.sd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.dd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.gd [new file with mode: 0644]
ld/testsuite/ld-mips-elf/stub-dynsym-micromips-insn32-2.sd [new file with mode: 0644]