* Handle linker scripts for which dlopen returns "file too short" (for
  example libncurses.so). Also support INPUT commands in linker scripts.

  Taken from upstream commits 44315e136cf9bc994185e689babec649c127e045 and
  a8c51c335cfa5201acf80a8d57d0d19b2779d5bc

Iain Lane <laney@debian.org>

Index: ghc-7.0.3/rts/Linker.c
===================================================================
--- ghc-7.0.3.orig/rts/Linker.c	2011-09-06 00:09:58.486412360 +0100
+++ ghc-7.0.3/rts/Linker.c	2011-09-06 00:10:10.721919762 +0100
@@ -1182,11 +1182,11 @@
 #   endif /* RTLD_DEFAULT */
 
     compileResult = regcomp(&re_invalid,
-           "(([^ \t()])+\\.so([^ \t:()])*):([ \t])*invalid ELF header",
+           "(([^ \t()])+\\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short)",
            REG_EXTENDED);
     ASSERT( compileResult == 0 );
     compileResult = regcomp(&re_realso,
-           "GROUP *\\( *(([^ )])+)",
+           "(GROUP|INPUT) *\\( *(([^ )])+)",
            REG_EXTENDED);
     ASSERT( compileResult == 0 );
 #   endif
@@ -1357,8 +1357,8 @@
          if (regexec(&re_realso, line, (size_t) NMATCH, match, 0) == 0) {
             // success -- try to dlopen the first named file
             IF_DEBUG(linker, debugBelch("match%s\n",""));
-            line[match[1].rm_eo] = '\0';
-            errmsg = internal_dlopen(line+match[1].rm_so);
+            line[match[2].rm_eo] = '\0';
+            errmsg = internal_dlopen(line+match[2].rm_so);
             break;
          }
          // if control reaches here, no GROUP ( ... ) directive was found
