diff --git a/ld/pdb.c b/ld/pdb.c
index f906e5f9142..46236fcbd4f 100644
--- a/ld/pdb.c
+++ b/ld/pdb.c
@@ -4356,7 +4356,7 @@ create_source_info_substream (void **data, uint32_t *size,
 			      struct source_files_info *source)
 {
   uint16_t dedupe_source_files_count = 0;
-  uint16_t source_files_count = 0;
+  unsigned int source_files_count = 0;
   uint32_t strings_len = 0;
   uint8_t *ptr;
 
diff --git a/ld/testsuite/ld-pe/pdb.exp b/ld/testsuite/ld-pe/pdb.exp
index 1439baa4bf8..48b0f517ec7 100644
--- a/ld/testsuite/ld-pe/pdb.exp
+++ b/ld/testsuite/ld-pe/pdb.exp
@@ -1837,6 +1837,28 @@ proc test10 { } {
     }
 }
 
+# Check that a PDB file with more than 65535 source file references can be
+# created.
+
+proc test11 { } {
+    global as
+    global ld
+    global srcdir
+    global subdir
+
+    if { ![ld_assemble $as $srcdir/$subdir/pdb4a.s tmpdir/pdb4a.o]
+	 || ![ld_assemble $as $srcdir/$subdir/pdb4b.s tmpdir/pdb4b.o] } {
+	unsupported "Build pdb4a.o and pdb4b.o"
+	return
+    }
+
+    if ![ld_link $ld "tmpdir/pdb4.exe" "--pdb=tmpdir/pdb4.pdb -e main tmpdir/pdb4a.o tmpdir/pdb4b.o"] {
+	fail "Create PDB file with more than 65535 source file references"
+    } else {
+	pass "Create PDB file with more than 65535 source file references"
+    }
+}
+
 test1
 test2
 test3
@@ -1847,3 +1869,4 @@ test7
 test8
 test9
 test10
+test11
diff --git a/ld/testsuite/ld-pe/pdb4a.s b/ld/testsuite/ld-pe/pdb4a.s
new file mode 100644
index 00000000000..d4693b69a23
--- /dev/null
+++ b/ld/testsuite/ld-pe/pdb4a.s
@@ -0,0 +1,45 @@
+/* Two modules with 32768 source file references each, so that the total
+   number of references in the DBI source-info substream exceeds 65535.  */
+
+	.equ CV_SIGNATURE_C13, 4
+	.equ DEBUG_S_STRINGTABLE, 0xf3
+	.equ DEBUG_S_FILECHKSMS, 0xf4
+	.equ CHKSUM_TYPE_NONE, 0
+
+	.equ NUM_CHKSMS, 32768
+
+	.section ".debug$S", "rn"
+	.long CV_SIGNATURE_C13
+	.long DEBUG_S_STRINGTABLE
+	.long .strings_end - .strings_start
+
+.strings_start:
+
+	.asciz ""
+
+.src1:
+	.asciz "foo"
+
+.strings_end:
+
+	.balign 4
+
+	.long DEBUG_S_FILECHKSMS
+	.long .chksms_end - .chksms_start
+
+.chksms_start:
+
+	.rept NUM_CHKSMS
+	.long .src1 - .strings_start
+	.byte 0 /* checksum length */
+	.byte CHKSUM_TYPE_NONE
+	.short 0 /* padding */
+	.endr
+
+.chksms_end:
+
+	.text
+
+	.global main
+main:
+	.long 0x12345678
diff --git a/ld/testsuite/ld-pe/pdb4b.s b/ld/testsuite/ld-pe/pdb4b.s
new file mode 100644
index 00000000000..029d7703897
--- /dev/null
+++ b/ld/testsuite/ld-pe/pdb4b.s
@@ -0,0 +1,38 @@
+/* See pdb4a.s.  */
+
+	.equ CV_SIGNATURE_C13, 4
+	.equ DEBUG_S_STRINGTABLE, 0xf3
+	.equ DEBUG_S_FILECHKSMS, 0xf4
+	.equ CHKSUM_TYPE_NONE, 0
+
+	.equ NUM_CHKSMS, 32768
+
+	.section ".debug$S", "rn"
+	.long CV_SIGNATURE_C13
+	.long DEBUG_S_STRINGTABLE
+	.long .strings_end - .strings_start
+
+.strings_start:
+
+	.asciz ""
+
+.src1:
+	.asciz "bar"
+
+.strings_end:
+
+	.balign 4
+
+	.long DEBUG_S_FILECHKSMS
+	.long .chksms_end - .chksms_start
+
+.chksms_start:
+
+	.rept NUM_CHKSMS
+	.long .src1 - .strings_start
+	.byte 0 /* checksum length */
+	.byte CHKSUM_TYPE_NONE
+	.short 0 /* padding */
+	.endr
+
+.chksms_end:
