diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 02b68814ab4..e7adab2f0d8 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -1857,12 +1857,28 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
 	      /* Compute new symbol location.  */
 	    if (isym.n_scnum > 0)
 	      {
-		isym.n_scnum = (*secpp)->output_section->target_index;
-		isym.n_value += (*secpp)->output_offset;
+		asection *s;
+
+		/* Relocate section symbols for sections that are not going to
+		   be emitted because they are duplicate of another one.  */
+		if (bfd_link_relocatable (flaginfo->info)
+		    && isym.n_sclass == C_STAT
+		    && isym.n_type == T_NULL
+		    && isym.n_numaux > 0
+		    && ((*secpp)->output_section == bfd_abs_section_ptr
+			|| bfd_section_removed_from_list
+			   (output_bfd, (*secpp)->output_section))
+		    && (*secpp)->kept_section)
+		  s = (*secpp)->kept_section;
+		else
+		  s = *secpp;
+
+		isym.n_scnum = s->output_section->target_index;
+		isym.n_value += s->output_offset;
 		if (! obj_pe (input_bfd))
-		  isym.n_value -= (*secpp)->vma;
+		  isym.n_value -= s->vma;
 		if (! obj_pe (flaginfo->output_bfd))
-		  isym.n_value += (*secpp)->output_section->vma;
+		  isym.n_value += s->output_section->vma;
 	      }
 	    break;
 
diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
index f8d7c8ef6e7..a669f279eda 100644
--- a/ld/scripttempl/pe.sc
+++ b/ld/scripttempl/pe.sc
@@ -364,11 +364,11 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame*)
+    *(.debug_frame${RELOCATING+*})
   }
   .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.zdebug_frame*)
+    *(.zdebug_frame${RELOCATING+*})
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
index a5b4679544c..45e785492c5 100644
--- a/ld/scripttempl/pep.sc
+++ b/ld/scripttempl/pep.sc
@@ -373,11 +373,11 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame*)
+    *(.debug_frame${RELOCATING+*})
   }
   .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.zdebug_frame*)
+    *(.zdebug_frame${RELOCATING+*})
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
