fail more quickly.  */
        return FALSE;
 
+      /* Set BFD_DECOMPRESS to decompress debug sections.  */
       if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
-         || ! bfd_check_format (debug_bfd, bfd_object)
+         || !(debug_bfd->flags |= BFD_DECOMPRESS,
+              bfd_check_format (debug_bfd, bfd_object))
          || (msec = find_debug_info (debug_bfd,
                                      debug_sections, NULL)) == NULL
          || !bfd_generic_link_read_symbols (debug_bfd))
 
 
     set testname "Convert x32 object to x86-64 (3)"
     convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gnu"
- }
+}
+
+proc test_gnu_debuglink {} {
+    global srcdir
+    global subdir
+    global env
+    global CC_FOR_TARGET
+    global STRIP
+    global OBJCOPY
+    global OBJDUMP
+
+    set test "gnu-debuglink"
+    if {![info exists CC_FOR_TARGET]} {
+       set CC_FOR_TARGET $env(CC)
+    }
+    if { $CC_FOR_TARGET == "" } {
+       unsupported $test
+       return
+    }
+
+    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog exectuable debug] != "" } {
+       fail "$test (build)"
+       return
+    }
+    set got [remote_exec host "$OBJDUMP -S tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.dump"]
+    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+       fail "$test (objcopy dump)"
+       return
+    }
+    if { [binutils_run $STRIP "--strip-debug --remove-section=.comment --remove-section=.note tmpdir/testprog -o tmpdir/testprog.strip"] != "" } {
+       fail "$test (strip)"
+       return
+    }
+    if { [binutils_run $OBJCOPY "--only-keep-debug --decompress-debug-sections tmpdir/testprog tmpdir/testprog.decompress"] != "" } {
+       fail "$test (objcopy decompress)"
+       return
+    }
+    if { [binutils_run $OBJCOPY "--only-keep-debug --compress-debug-sections tmpdir/testprog tmpdir/testprog.compress"] != "" } {
+       fail "$test (objcopy compress)"
+       return
+    }
+    if { [binutils_run $OBJCOPY "--add-gnu-debuglink=tmpdir/testprog.decompress tmpdir/testprog.strip tmpdir/testprog"] != "" } {
+       fail "$test (objcopy link decompress)"
+       return
+    }
+    set got [remote_exec host "$OBJDUMP -S tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.decompress.dump"]
+    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+       fail "$test (objcopy dump decompress)"
+       return
+    }
+    if { [binutils_run $OBJCOPY "--add-gnu-debuglink=tmpdir/testprog.compress tmpdir/testprog.strip tmpdir/testprog"] != "" } {
+       fail "$test (objcopy link compress)"
+       return
+    }
+    set got [remote_exec host "$OBJDUMP -S tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.compress.dump"]
+    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+       fail "$test (objcopy dump compress)"
+       return
+    }
+
+    set src1 tmpdir/testprog.dump
+    set src2 tmpdir/testprog.compress.dump
+    send_log "cmp ${src1} ${src2}\n"
+    verbose "cmp ${src1} ${src2}"
+    set status [remote_exec build cmp "${src1} ${src2}"]
+    set exec_output [lindex $status 1]
+    set exec_output [prune_warnings $exec_output]
+    if ![string match "" $exec_output] then {
+       send_log "$exec_output\n"
+       verbose "$exec_output" 1
+       fail "$test (objdump 1)"
+    } else {
+       pass "$test (objdump 1)"
+    }
+
+    set src1 tmpdir/testprog.decompress.dump
+    set src2 tmpdir/testprog.compress.dump
+    send_log "cmp ${src1} ${src2}\n"
+    verbose "cmp ${src1} ${src2}"
+    set status [remote_exec build cmp "${src1} ${src2}"]
+    set exec_output [lindex $status 1]
+    set exec_output [prune_warnings $exec_output]
+    if ![string match "" $exec_output] then {
+       send_log "$exec_output\n"
+       verbose "$exec_output" 1
+       fail "$test (objdump 2)"
+    } else {
+       pass "$test (objdump 2)"
+    }
+}
+
+if {[isnative] && [is_elf_format]} then {
+    test_gnu_debuglink
+}