+2016-04-05  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * elflink.c (elf_link_add_object_symbols): Always turn hidden
+       and internal symbols which have a dynamic index into local
+       ones.
+
 2016-04-04  Nick Clifton  <nickc@redhat.com>
 
        PR 19872
 
                    goto error_free_vers;
                }
            }
-         else if (dynsym && h->dynindx != -1)
+         else if (h->dynindx != -1)
            /* If the symbol already has a dynamic index, but
               visibility says it should not be visible, turn it into
               a local symbol.  */
 
+2016-04-05  Maciej W. Rozycki  <macro@imgtec.com>
+
+       PR ld/19908
+       * testsuite/ld-cris/tls-e-20.d: Adjust for hidden symbol
+       handling fix.
+       * testsuite/ld-cris/tls-e-20a.d: Likewise.
+       * testsuite/ld-cris/tls-e-21.d: Likewise.
+       * testsuite/ld-cris/tls-e-23.d: Likewise.
+       * testsuite/ld-cris/tls-e-80.d: Likewise.
+       * testsuite/ld-cris/tls-gd-3h.d: Likewise.
+       * testsuite/ld-cris/tls-leie-19.d: Likewise.
+       * testsuite/ld-mips-elf/export-class-ref-lib.sd: New test.
+       * testsuite/ld-mips-elf/export-hidden-ref.sd: New test.
+       * testsuite/ld-mips-elf/export-internal-ref.sd: New test.
+       * testsuite/ld-mips-elf/export-protected-ref.sd: New test.
+       * testsuite/ld-mips-elf/export-class-ref-f0.s: New test source.
+       * testsuite/ld-mips-elf/export-class-ref-f1.s: New test source.
+       * testsuite/ld-mips-elf/export-class-ref-f2.s: New test source.
+       * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
+
 2016-04-05  Cupertino Miranda  <cmiranda@synopsys.com>
 
        * testsuite/ld-discard/extern.d: Removed xfail for ARC.
 
 0+80094 l    d  \.text 0+ \.text
 0+820b0 l    d  \.tdata        0+ \.tdata
 0+820bc l    d  \.got  0+ \.got
+0+ l       \.tdata     0+4 x
 0+820bc l     O \.got  0+ _GLOBAL_OFFSET_TABLE_
-0+ g       \.tdata     0+4 \.hidden x
 0+80098 g     F \.text 0+6 tlsdsofn2
 0+8 g       \.tdata    0+4 \.hidden x2
 0+80094 g       \.text 0+ _start
 
 0+ l    df \*ABS\*     0+ .*
 0+ l       \.tdata     0+80 tls128
 0+ l    df \*ABS\*     0+ .*
+0+80 l       \.tdata   0+4 x
 0+82168 l     O \.got  0+ _GLOBAL_OFFSET_TABLE_
-0+80 g       \.tdata   0+4 \.hidden x
 0+800c4 g     F \.text 0+6 tlsdsofn2
 0+821b4 g     O \.data 0+4 got7var5
 0+88 g       \.tdata   0+4 \.hidden x2
 
 #...
 SYMBOL TABLE:
 #...
-0+80 g       \.tdata   0+4 \.hidden x
+0+80 l       \.tdata   0+4 x
 #...
 Contents of section \.text:
 #...
 
 #...
 SYMBOL TABLE:
 #...
-0+80 g       \.tdata   0+4 \.hidden x
+0+80 l       \.tdata   0+4 x
 #...
 Contents of section \.text:
 #...
 
 0+820c0 l    d  \.tdata        0+ \.tdata
 0+820d0 l    d  \.tbss 0+ \.tbss
 0+820d0 l    d  \.got  0+ \.got
+0+ l       \.tdata     0+4 x
 0+820d0 l     O \.got  0+ _GLOBAL_OFFSET_TABLE_
-0+ g       \.tdata     0+4 \.hidden x
 0+800a0 g     F \.text 0+6 tlsdsofn2
 0+800a8 g     F \.text 0+6 tlsfn12
 0+c g       \.tdata    0+4 \.hidden x2
 
 #...
 SYMBOL TABLE:
 #...
-0+80 g       \.tdata   0+4 \.hidden x
+0+80 l       \.tdata   0+4 x
 #...
 Contents of section \.text:
 #...
 
                   CONTENTS.*
 SYMBOL TABLE:
 #...
-0+88 g       .tdata    0+4 x
+0+84 l       \.tdata   0+4 x2
 #...
-0+84 g       \.tdata   0+4 \.hidden x2
+0+80 l       \.tdata   0+4 x1
 #...
-0+8c g       .tdata    0+4 z
+0+88 g       .tdata    0+4 x
 #...
-0+80 g       \.tdata   0+4 \.hidden x1
+0+8c g       .tdata    0+4 z
 #...
 Contents of section \.text:
 #...
 
--- /dev/null
+       .abicalls
+       .text
+
+       .if     refv == 3
+       .protected f1
+       .elseif refv == 2
+       .hidden f1
+       .elseif refv == 1
+       .internal f1
+       .endif
+
+       .globl  f0
+       .ent    f0
+f0:
+       .frame  $sp, 32, $31
+       .mask   0x80000000, -4
+       .fmask  0x00000000, 0
+       .set    noreorder
+       .cpload $25
+       .set    reorder
+       addiu   $sp, $sp, -32
+       sw      $31, 28($sp)
+       .cprestore 16
+
+       lw      $25, %call16(f1)($28)
+       jalr    $25
+       lw      $28, 16($sp)
+
+       lw      $25, %call16(f2)($28)
+       jalr    $25
+       lw      $28, 16($sp)
+
+       move    $2, $0
+       lw      $31, 28($sp)
+       addiu   $sp, $sp, 32
+       jr      $31
+       .end    f0
 
--- /dev/null
+       .abicalls
+       .text
+
+       .globl  f1
+       .if     defv == 3
+       .protected f1
+       .elseif defv == 2
+       .hidden f1
+       .elseif defv == 1
+       .internal f1
+       .endif
+       .ent    f1
+f1:
+       .frame  $sp, 0, $31
+       .mask   0x00000000, 0
+       .fmask  0x00000000, 0
+       jr      $31
+       .end    f1
 
--- /dev/null
+       .abicalls
+       .text
+
+       .globl  f1
+       .ent    f1
+f1:
+       .frame  $sp, 0, $31
+       .mask   0x00000000, 0
+       .fmask  0x00000000, 0
+       jr      $31
+       .end    f1
+
+       .globl  f2
+       .ent    f2
+f2:
+       .frame  $sp, 0, $31
+       .mask   0x00000000, 0
+       .fmask  0x00000000, 0
+       jr      $31
+       .end    f2
 
--- /dev/null
+# Make sure `f1' is present in the dynamic symbol table, e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      6: 000002d0     8 FUNC    GLOBAL DEFAULT    7 f1
+#...
+ *[0-9]+: +[0-9a-f]+ +[0-9]+ FUNC +GLOBAL +DEFAULT +[0-9]+ f1
+#pass
 
--- /dev/null
+# Make sure no hidden symbol is present in the dynamic symbol table, e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      6: 004003f0     8 FUNC    GLOBAL HIDDEN     8 f1
+#failif
+#...
+.+ +HIDDEN +.+ +f1
+#pass
 
--- /dev/null
+# Make sure no internal symbol is present in the dynamic symbol table, e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      6: 004003f0     8 FUNC    GLOBAL INTERNAL   8 f1
+#failif
+#...
+.+ +INTERNAL +.+ +f1
+#pass
 
--- /dev/null
+# Make sure no local symbol is present in the dynamic symbol table, e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      6: 004003f0     8 FUNC    LOCAL  DEFAULT    8 f1
+#failif
+#...
+.+ +LOCAL +.+ +f1
+#pass
 
--- /dev/null
+# Make sure a protected symbol is present in the dynamic symbol table, e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      6: 004003f0     8 FUNC    GLOBAL PROTECTED    8 f1
+#...
+ *[0-9]+: +[0-9a-f]+ +[0-9]+ FUNC +GLOBAL +PROTECTED +[0-9]+ f1
+#pass
 
            n32 -1 1 umips
     }
 }
+
+# PR ld/19908 export class tests.
+if { $linux_gnu } {
+    run_ld_link_tests [list \
+       [list "Shared library for MIPS export class symbol reference tests" \
+             "$abi_ldflags(o32) -shared" "" \
+             "$abi_asflags(o32)" \
+             { export-class-ref-f2.s } \
+             { { readelf --dyn-syms export-class-ref-lib.sd } } \
+             "export-class-ref-lib.so"]]
+    foreach { class flag } { internal 1 hidden 2 protected 3 } {
+       run_ld_link_tests [list \
+           [list "MIPS $class symbol reference test 1" \
+                 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
+                 "$abi_asflags(o32) --defsym defv=$flag" \
+                 { export-class-ref-f0.s export-class-ref-f1.s } \
+                 [list [list readelf --dyn-syms export-$class-ref.sd] \
+                       [list readelf --dyn-syms export-local-ref.sd]] \
+                 "export-$class-ref"] \
+           [list "MIPS $class symbol reference test 2" \
+                 "$abi_ldflags(o32) -e f0" "tmpdir/export-class-ref-lib.so" \
+                 "$abi_asflags(o32) --defsym defv=$flag --defsym refv=$flag" \
+                 { export-class-ref-f0.s export-class-ref-f1.s } \
+                 [list [list readelf --dyn-syms export-$class-ref.sd] \
+                       [list readelf --dyn-syms export-local-ref.sd]] \
+                 "export-$class-ref"]]
+    }
+}