diff --git a/Makefile.am b/Makefile.am
index 98b2f20..2060b96 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,7 +32,8 @@ CLEANFILES = $(bin_SCRIPTS)
 
 # Some standard substitutions for scripts
 do_subst = ($(SED) -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
-		   -e 's,[@]VERSION[@],$(VERSION),g')
+		   -e 's,[@]VERSION[@],$(VERSION),g' \
+		   -e 's,[@]READELF[@],$(READELF),g')
 
 find-debuginfo: $(top_srcdir)/scripts/find-debuginfo.in Makefile
 	$(do_subst) < "$(top_srcdir)/scripts/$@.in" > "$@"
diff --git a/configure.ac b/configure.ac
index 85f2c4f..6a53365 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ AC_PROG_SED
 AC_PROG_CC_C99
 AC_PROG_LN_S
 AC_CHECK_TOOL([LD], [ld])
+AC_CHECK_TOOL([READELF], [readelf])
 AM_MISSING_PROG(HELP2MAN, help2man)
 
 # Only really an issue on 32bit platforms. Makes sure we'll get large off_t.
@@ -86,6 +87,20 @@ CFLAGS="$save_CFLAGS"
 GDWARF_5_FLAG=$ac_cv_gdwarf_5
 AC_SUBST([GDWARF_5_FLAG])
 
+AC_CACHE_CHECK([whether -gdwarf-5 produced DWARF5 .debug_line], ac_cv_dwarf_5_debugline, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="-gdwarf-5"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i=0;]],[[/* empty main */]])],
+  [if $READELF --debug-dump=line conftest.o 2>&1 | \
+   grep "DWARF Version:" 2>&1 | grep "5" > /dev/null 2>&1; \
+     then ac_cv_dwarf_5_debugline=yes; \
+     else ac_cv_dwarf_5_debugline=no; fi],
+  ac_cv_dwarf_5_debugline=no)
+CFLAGS="$save_CFLAGS"
+])
+DWARF_5_DEBUGLINE=$ac_cv_dwarf_5_debugline
+AC_SUBST([DWARF_5_DEBUGLINE])
+
 AC_CACHE_CHECK([whether gcc supports -gz=none], ac_cv_gz_none, [dnl
 save_CFLAGS="$CFLAGS"
 CFLAGS="-gz=none"
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index 8b9ce77..b07a52f 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -168,7 +168,6 @@ while [ $# -gt 0 ]; do
     ;;
   --dwz-single-file-mode)
     dwz_single_file_mode=true
-    shift
     ;;
   --build-id-seed)
     build_id_seed=$2
@@ -338,7 +337,7 @@ add_minidebug()
   # symbol and NOBITS sections so cannot use --keep-only because that is
   # too aggressive. Field $2 is the section name, $3 is the section type
   # and $8 are the section flags.
-  local remove_sections=`readelf -W -S "$debuginfo" \
+  local remove_sections=`@READELF@ -W -S "$debuginfo" \
 	| awk '{ if (index($2,".debug_") != 1 \
 		     && ($3 == "PROGBITS" || $3 == "NOTE" || $3 == "NOBITS") \
 		     && index($8,"A") == 0) \
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 0eec351..d916301 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -9,6 +9,8 @@ CC="@CC@"
 CFLAGS=""
 LD="@LD@"
 LDFLAGS=""
+READELF="@READELF@"
 
 GDWARF_5_FLAG=@GDWARF_5_FLAG@
 GZ_NONE_FLAG=@GZ_NONE_FLAG@
+DWARF_5_DEBUGLINE=@DWARF_5_DEBUGLINE@
diff --git a/tests/debugedit.at b/tests/debugedit.at
index 608b1d0..725e68e 100644
--- a/tests/debugedit.at
+++ b/tests/debugedit.at
@@ -93,7 +93,7 @@ DEBUGEDIT_SETUP([-gdwarf-4])
 
 # Capture strings that start with the testdir (pwd) directory path
 # (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
+$READELF -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
         | grep ^$(pwd) | sort \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
 
@@ -108,7 +108,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
+$READELF -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
         | grep ^/foo/bar/baz | sort
 ]],[0],[expout])
 
@@ -125,7 +125,7 @@ DEBUGEDIT_SETUP([-gdwarf-5])
 
 # Capture strings that start with the testdir (pwd) directory path
 # (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
+$READELF -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
         | cut -c13- \
         | grep ^$(pwd) | sort | uniq \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -141,7 +141,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
+$READELF -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
         | cut -c13- \
         | grep ^/foo/bar/baz | sort | uniq
 ]],[0],[expout],[ignore])
@@ -160,7 +160,7 @@ DEBUGEDIT_SETUP([-gdwarf-4])
 # (and replace that textually with /foo/bar/baz)
 # Note that partially linked files, might have multiple duplicate
 # strings, but debugedit will merge them. So use sort -u.
-readelf -p.debug_str ./foobarbaz.part.o | cut -c13- \
+$READELF -p.debug_str ./foobarbaz.part.o | cut -c13- \
         | grep ^$(pwd) | sort -u \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
 
@@ -173,7 +173,7 @@ fi
 # Check the replaced strings are all there.
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf -p.debug_str ./foobarbaz.part.o | cut -c13- \
+$READELF -p.debug_str ./foobarbaz.part.o | cut -c13- \
         | grep ^/foo/bar/baz | sort
 ]],[0],[expout])
 
@@ -192,7 +192,7 @@ DEBUGEDIT_SETUP([-gdwarf-5])
 # (and replace that textually with /foo/bar/baz)
 # Note that partially linked files, might have multiple duplicate
 # strings, but debugedit will merge them. So use sort -u.
-readelf -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
+$READELF -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
         | grep ^$(pwd) | sort -u | uniq \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
 
@@ -205,7 +205,7 @@ fi
 # Check the replaced strings are all there.
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
+$READELF -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
         | grep ^/foo/bar/baz | sort | uniq
 ]],[0],[expout],[ignore])
 
@@ -221,7 +221,7 @@ DEBUGEDIT_SETUP([-gdwarf-4])
 
 # Capture strings that start with the testdir (pwd) directory path
 # (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str foobarbaz.exe | cut -c13- \
+$READELF -p.debug_str foobarbaz.exe | cut -c13- \
         | grep ^$(pwd) | sort \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
 
@@ -235,7 +235,7 @@ fi
 # Check the replaced strings are all there.
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf -p.debug_str foobarbaz.exe | cut -c13- \
+$READELF -p.debug_str foobarbaz.exe | cut -c13- \
         | grep ^/foo/bar/baz | sort
 ]],[0],[expout])
 
@@ -252,7 +252,7 @@ DEBUGEDIT_SETUP([-gdwarf-5])
 
 # Capture strings that start with the testdir (pwd) directory path
 # (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
+$READELF -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
         | grep ^$(pwd) | sort | uniq \
         | sed -e "s@$(pwd)@/foo/bar/baz@" > expout
 
@@ -266,7 +266,7 @@ fi
 # Check the replaced strings are all there.
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
+$READELF -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
         | grep ^/foo/bar/baz | sort | uniq
 ]],[0],[expout],[ignore])
 
@@ -305,7 +305,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf --debug-dump=info foo.o subdir_bar/bar.o baz.o \
+$READELF --debug-dump=info foo.o subdir_bar/bar.o baz.o \
         | grep -E 'DW_AT_(name|comp_dir)' \
         | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
 ]],[0],[expout])
@@ -328,7 +328,7 @@ AT_DATA([expout],
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf --debug-dump=info ./foobarbaz.part.o \
+$READELF --debug-dump=info ./foobarbaz.part.o \
         | grep -E 'DW_AT_(name|comp_dir)' \
         | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
 ]],[0],[expout])
@@ -351,7 +351,7 @@ AT_DATA([expout],
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf --debug-dump=info ./foobarbaz.exe | grep -E 'DW_AT_(name|comp_dir)' \
+$READELF --debug-dump=info ./foobarbaz.exe | grep -E 'DW_AT_(name|comp_dir)' \
         | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
 ]],[0],[expout])
 
@@ -385,7 +385,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
 for i in ./foo.o ./subdir_bar/bar.o ./baz.o;do \
-  readelf --debug-dump=info $i \
+  $READELF --debug-dump=info $i \
           | awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
           | sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
           | sort;
@@ -415,7 +415,7 @@ stz
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf --debug-dump=info ./foobarbaz.part.o \
+$READELF --debug-dump=info ./foobarbaz.part.o \
         | awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
         | sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
         | sort
@@ -444,7 +444,7 @@ stz
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf --debug-dump=info ./foobarbaz.exe \
+$READELF --debug-dump=info ./foobarbaz.exe \
         | awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
         | sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
         | sort
@@ -474,7 +474,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf --debug-dump=line foo.o subdir_bar/bar.o baz.o \
+$READELF --debug-dump=line foo.o subdir_bar/bar.o baz.o \
         | grep -A3 "The Directory Table" | grep "^  [123]" \
 	| grep /foo/ | cut -c5- | sort
 ]],[0],[expout])
@@ -488,10 +488,12 @@ AT_CLEANUP
 AT_SETUP([debugedit .debug_line objects DWARF5])
 AT_KEYWORDS([debuginfo] [debugedit])
 AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
 DEBUGEDIT_SETUP([-gdwarf-5])
 
 AT_DATA([expout],
 [foo/bar/baz
+foo/bar/baz/subdir_bar
 foo/bar/baz/subdir_headers
 ])
 
@@ -499,9 +501,9 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf --debug-dump=line foo.o subdir_bar/bar.o baz.o \
-        | grep -A5 "The Directory Table" | grep "^  [123]" \
-	| cut -f2- -d/ | grep ^foo/ | sort
+$READELF --debug-dump=line foo.o subdir_bar/bar.o baz.o \
+	| grep -A5 "The Directory Table" | grep "^  [0123]" \
+	| cut -f2- -d/ | grep ^foo/ | sort -u
 ]],[0],[expout])
 
 AT_CLEANUP
@@ -521,7 +523,7 @@ AT_DATA([expout],
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf --debug-dump=line ./foobarbaz.part.o \
+$READELF --debug-dump=line ./foobarbaz.part.o \
         | grep -A3 "The Directory Table" | grep "^  [123]" \
 	| grep /foo/ | cut -c5- | sort
 ]],[0],[expout])
@@ -535,18 +537,20 @@ AT_CLEANUP
 AT_SETUP([debugedit .debug_line partial DWARF5])
 AT_KEYWORDS([debuginfo] [debugedit])
 AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
 DEBUGEDIT_SETUP([-gdwarf-5])
 
 AT_DATA([expout],
 [foo/bar/baz
+foo/bar/baz/subdir_bar
 foo/bar/baz/subdir_headers
 ])
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf --debug-dump=line ./foobarbaz.part.o \
-        | grep -A5 "The Directory Table" | grep "^  [123]" \
-	| cut -f2- -d/ | grep ^foo/ | sort
+$READELF --debug-dump=line ./foobarbaz.part.o \
+	| grep -A5 "The Directory Table" | grep "^  [0123]" \
+	| cut -f2- -d/ | grep ^foo/ | sort -u
 ]],[0],[expout])
 
 AT_CLEANUP
@@ -566,7 +570,7 @@ AT_DATA([expout],
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf --debug-dump=line ./foobarbaz.exe \
+$READELF --debug-dump=line ./foobarbaz.exe \
         | grep -A3 "The Directory Table" | grep "^  [123]" \
 	| grep /foo/ | cut -c5- | sort
 ]],[0],[expout])
@@ -580,18 +584,20 @@ AT_CLEANUP
 AT_SETUP([debugedit .debug_line exe DWARF5])
 AT_KEYWORDS([debuginfo] [debugedit])
 AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
 DEBUGEDIT_SETUP([-gdwarf-5])
 
 AT_DATA([expout],
 [foo/bar/baz
+foo/bar/baz/subdir_bar
 foo/bar/baz/subdir_headers
 ])
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf --debug-dump=line ./foobarbaz.exe \
-        | grep -A5 "The Directory Table" | grep "^  [123]" \
-	| cut -f2- -d/ | grep ^foo/ | sort
+$READELF --debug-dump=line ./foobarbaz.exe \
+	| grep -A5 "The Directory Table" | grep "^  [0123]" \
+	| cut -f2- -d/ | grep ^foo/ | sort -u
 ]],[0],[expout])
 
 AT_CLEANUP
@@ -615,7 +621,7 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
 AT_CHECK([[
-readelf --debug-dump=macro foo.o subdir_bar/bar.o baz.o \
+$READELF --debug-dump=macro foo.o subdir_bar/bar.o baz.o \
         | grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
 ]],[0],[expout])
 
@@ -638,7 +644,7 @@ NUMBER 42
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
 AT_CHECK([[
-readelf --debug-dump=macro ./foobarbaz.part.o \
+$READELF --debug-dump=macro ./foobarbaz.part.o \
         | grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
 ]],[0],[expout])
 
@@ -661,7 +667,7 @@ NUMBER 42
 
 AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
 AT_CHECK([[
-readelf --debug-dump=macro ./foobarbaz.exe \
+$READELF --debug-dump=macro ./foobarbaz.exe \
         | grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
 ]],[0],[expout])
 
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 668777a..d82ae5a 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -1,4 +1,5 @@
 /* Copyright (C) 2001-2003, 2005, 2007, 2009-2011, 2016, 2017 Red Hat, Inc.
+   Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
    Written by Alexander Larsson <alexl@redhat.com>, 2002
    Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
    String/Line table rewriting by Mark Wielaard <mjw@redhat.com>, 2017.
@@ -295,25 +296,9 @@ buf_read_ube32 (unsigned char *data)
 }
 
 static const char *
-strptr (DSO *dso, int sec, off_t offset)
+strptr (DSO *dso, size_t sec, size_t offset)
 {
-  Elf_Scn *scn;
-  Elf_Data *data;
-
-  scn = dso->scn[sec];
-  if (offset >= 0 && (GElf_Addr) offset < dso->shdr[sec].sh_size)
-    {
-      data = NULL;
-      while ((data = elf_getdata (scn, data)) != NULL)
-	{
-	  if (data->d_buf
-	      && offset >= data->d_off
-	      && offset < data->d_off + data->d_size)
-	    return (const char *) data->d_buf + (offset - data->d_off);
-	}
-    }
-
-  return NULL;
+  return elf_strptr (dso->elf, sec, offset);
 }
 
 
@@ -590,6 +575,10 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
 	  if (rtype != R_390_32)
 	    goto fail;
 	  break;
+	case EM_PARISC:
+	  if (rtype != R_PARISC_DIR32)
+	    goto fail;
+	  break;
 	case EM_IA_64:
 	  if (rtype != R_IA64_SECREL32LSB)
 	    goto fail;
@@ -2582,7 +2571,8 @@ edit_dwarf2 (DSO *dso)
         const char *name = strptr (dso, dso->ehdr.e_shstrndx,
 				   dso->shdr[i].sh_name);
 
-	if (strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0)
+	if (name != NULL
+	    && strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0)
 	  {
 	    for (j = 0; debug_sections[j].name; ++j)
 	      if (strcmp (name, debug_sections[j].name) == 0)
@@ -2638,9 +2628,11 @@ edit_dwarf2 (DSO *dso)
 	  }
 	else if (dso->ehdr.e_type == ET_REL
 		 && ((dso->shdr[i].sh_type == SHT_REL
+		      && name != NULL
 		      && strncmp (name, ".rel.debug_",
 				  sizeof (".rel.debug_") - 1) == 0)
 		     || (dso->shdr[i].sh_type == SHT_RELA
+			 && name != NULL
 			 && strncmp (name, ".rela.debug_",
 				     sizeof (".rela.debug_") - 1) == 0)))
 	  {
@@ -3043,7 +3035,7 @@ static struct option optionsTable[] =
     { NULL, 0, 0, 0 }
   };
 
-static const char *optionsChars = "b:d:l:is:nV?";
+static const char *optionsChars = "b:d:l:is:nV?u";
 
 static const char *helpText =
   "Usage: %s [OPTION...] FILE\n"
@@ -3273,7 +3265,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
 	  else
 	    sha1_process_bytes (x.d_buf, x.d_size, &sha1_ctx);
 
-	  if (u.shdr.sh_type != SHT_NOBITS)
+	  if (dso->shdr[i].sh_type != SHT_NOBITS)
 	    {
 	      Elf_Data *d = elf_getdata (dso->scn[i], NULL);
 	      if (d == NULL)
@@ -3463,13 +3455,13 @@ main (int argc, char *argv[])
 	case SHT_PROGBITS:
 	  name = strptr (dso, dso->ehdr.e_shstrndx, dso->shdr[i].sh_name);
 	  /* TODO: Handle stabs */
-	  if (strcmp (name, ".stab") == 0)
+	  if (name != NULL && strcmp (name, ".stab") == 0)
 	    {
 	      error (0, 0, "Stabs debuginfo not supported: %s", file);
 	      break;
 	    }
 	  if (!(do_build_id && no_recompute_build_id && !base_dir && !dest_dir)
-	      && strcmp (name, ".debug_info") == 0)
+	      && name != NULL && strcmp (name, ".debug_info") == 0)
 	    edit_dwarf2 (dso);
 
 	  break;
