This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch/rebase] Add a rebase database to keep track of DLL addresses


On 7/21/2011 3:38 PM, Charles Wilson wrote:
>> IMHO it would make sense to bump LIB_VERSION and create a new rebase
>> package ASAP, so we can get some more people to test it.
> 
> Give me a day or so to do the mingw/msys gloss, before updating
> LIB_VERSION and cutting a new release, ok?

The attached allows to build on msys, as well as cygwin & mingw, and
appears to work properly on all three platforms.

The changes to config.guess and config.sub are...questionable.
Basically, msys doesn't WANT to put their triple in the upstream repo,
because then people would want to build all manner of tools for the msys
platform -- but that's cygwin's bailiwick (msys=minimal).

So, basically all msys ports have to explicitly patch config.guess and
config.sub: basically, the msys distributor "forks" each upstream
project, even if only to patch config.*.

I can continue to do that, for msys-rebase.

...OR, rebase itself can adopt the "forked" versions of config.*, since
it is such a special purpose tool. (But then, we've got to remember to
re-apply these changes if we update to newer config.*) Jason's call.


Also, I added a quick-n-dirty rebase-dump application. It actually
helped me track down a problem on mingw: the db was not being opened in
binary mode, and for some reason that prevented rebase (and rebase-dump)
from being able to load the strings (it loaded the other bits of the db
fine!)

I don't know why, but when I added O_BINARY everything was copacetic.

When I say quick-n-dirty, I mean: lots of duplicated and only slightly
modified code from rebase.c.  There's room for code consolidation, so
this bit could be put off until later.


	build-aux/config.guess: Add msys support.
	build-aux/config.sub: Add msys support.

	configure.ac: Specify -static-* and -D overrides, on a
	platform-sensitive basis, here rather than hardcoding in
	Makefile.in.
	imagehelper/Makefile.in: Ditto.
	Makefile.in: Ditto. Also, add rebase-dump.
	imagehelper/rebase_main.cc: Fix bug in GetImageInfos64 call.
	Be explicit about CYGWIN vs MSYS.
	imagehelper/sections.h: Fix portability issues with stdint.h
	and uintptr_t.
	rebase.c: Include limits.h for PATH_MAX. Handle missing
	inttypes.h on MSYS. Be explicit about CYGWIN vs MSYS.
	(strtoull) [MSYS]: Add missing function.
	(main) [MSYS]: Allow room for msys-1.0.dll, as with cygwin1.dll.
        (mkstemp) [MINGW]: Fix open flags.
	(load_image_info): Fix open flags (O_BINARY). Use calloc
	instead of malloc when allocating strings.
	(merge_image_info) [MSYS]: Skip msys-1.0.dll, as with
	cygwin1.dll.
	(parse_args) [MINGW]: Use program path to determine location of
	database.
	rebaseall.in: Add platform-specific code to handle msys
	shortcomings.
	peflagsall.in: Ditto.

	rebase-dump.c: New file.

--
Chuck

Index: Makefile.in
===================================================================
RCS file: /cvs/cygwin-apps/rebase/Makefile.in,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile.in
--- Makefile.in	21 Jul 2011 19:10:04 -0000	1.6
+++ Makefile.in	22 Jul 2011 23:59:08 -0000
@@ -58,9 +58,10 @@ ASH = @ASH@
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(srcdir)/imagehelper
 DEFS = @DEFS@ -DVERSION='"$(PACKAGE_VERSION)"' -DLIB_VERSION='"$(LIB_VERSION)"' -DSYSCONFDIR='"$(sysconfdir)"'
 
-override CFLAGS+=-Wall -Werror
-override CXXFLAGS+=-Wall -Werror
-override LDFLAGS+=-static -static-libgcc
+override CFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@
+override CXXFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@
+override LDFLAGS+=-static @EXTRA_LDFLAG_OVERRIDES@
+override CXX_LDFLAGS+=@EXTRA_CXX_LDFLAG_OVERRIDES@
 
 .SUFFIXES:
 .SUFFIXES: .c .cc .$(O)
@@ -76,6 +77,9 @@ LIBIMAGEHELPER = imagehelper/libimagehel
 REBASE_OBJS = rebase.$(O) $(LIBOBJS)
 REBASE_LIBS = $(LIBIMAGEHELPER)
 
+REBASE_DUMP_OBJS = rebase-dump.$(O) $(LIBOBJS)
+REBASE_DUMP_LIBS =
+
 PEFLAGS_OBJS = peflags.$(O) $(LIBOBJS)
 PEFLAGS_LIBS =
 
@@ -85,16 +89,22 @@ SRC_DISTFILES = aclocal.m4 configure.ac 
 	build-aux/config.guess build-aux/config.sub \
 	build-aux/install-sh getopt.h_ getopt_long.c
 
-all: libimagehelper rebase$(EXEEXT) peflags$(EXEEXT) rebaseall peflagsall
+all: libimagehelper rebase$(EXEEXT) rebase-dump$(EXEEXT) \
+  peflags$(EXEEXT) rebaseall peflagsall
 
 libimagehelper:
 	$(MAKE) -C imagehelper imagehelper
 
 rebase$(EXEEXT): $(REBASE_LIBS) $(REBASE_OBJS)
-	$(CXX) $(CXXFLAGS) $(LDFLAGS) -static-libstdc++ -o $@ $(REBASE_OBJS) $(REBASE_LIBS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_LDFLAGS) -o $@ $(REBASE_OBJS) $(REBASE_LIBS)
 
 rebase.$(O):: rebase.c Makefile
 
+rebase-dump$(EXEEXT): $(REBASE_DUMP_OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(REBASE_DUMP_OBJS)
+
+rebase-dump.$(O):: rebase-dump.c Makefile
+
 peflags$(EXEEXT): $(PEFLAGS_OBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(PEFLAGS_OBJS)
 
Index: configure.ac
===================================================================
RCS file: /cvs/cygwin-apps/rebase/configure.ac,v
retrieving revision 1.3
diff -u -p -r1.3 configure.ac
--- configure.ac	28 Jun 2011 19:43:19 -0000	1.3
+++ configure.ac	22 Jul 2011 23:59:08 -0000
@@ -44,6 +44,24 @@ case "$host" in
 esac
 AC_SUBST(DEFAULT_OFFSET_VALUE)
 
+case "$host" in
+ *msys*   )	EXTRA_CFLAG_OVERRIDES=
+		EXTRA_LDFLAG_OVERRIDES="-static-libgcc"
+		EXTRA_CXX_LDFLAG_OVERRIDES=
+   ;;
+ *cygwin* )	EXTRA_CFLAG_OVERRIDES=
+		EXTRA_LDFLAG_OVERRIDES="-static-libgcc"
+		EXTRA_CXX_LDFLAG_OVERRIDES="-static-libstdc++"
+   ;;
+ *mingw*  )	EXTRA_CFLAG_OVERRIDES="-D__USE_MINGW_ANSI_STDIO"
+		EXTRA_LDFLAG_OVERRIDES="-static-libgcc"
+		EXTRA_CXX_LDFLAG_OVERRIDES="-static-libstdc++"
+   ;;
+esac
+AC_SUBST(EXTRA_CFLAG_OVERRIDES)
+AC_SUBST(EXTRA_LDFLAG_OVERRIDES)
+AC_SUBST(EXTRA_CXX_LDFLAG_OVERRIDES)
+
 AC_CONFIG_FILES([Makefile
                  imagehelper/Makefile])
 
Index: peflagsall.in
===================================================================
RCS file: /cvs/cygwin-apps/rebase/peflagsall.in,v
retrieving revision 1.1
diff -u -p -r1.1 peflagsall.in
--- peflagsall.in	20 Jun 2011 23:27:00 -0000	1.1
+++ peflagsall.in	22 Jul 2011 23:59:08 -0000
@@ -131,9 +131,39 @@ ArgDynBase=
 # First see if caller requested help
 check_args_for_help "$@"
 
+# Determine platform
+Platform=`uname -s`
+case $Platform in
+ *MINGW*  | *mingw*  ) Platform=mingw  ;;
+ *CYGWIN* | *cygwin* ) Platform=cygwin ;;
+ *MSYS*   | *msys*   ) Platform=msys   ;;
+ * )
+    echo "Unsupported platform: $Platform" 1>&2
+    exit 1
+    ;;
+esac
+
 # Verify only ash or dash processes are running
-grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename
-if [ $? -eq 0 -a -z "$RebaseDebug" ]
+ProcessResult=0
+case $Platform in
+  mingw|msys )
+    # Also exclude the commands we're using below, which is not ideal
+    /bin/ps -s | /bin/sed -e '1d' | /bin/awk '{print $NF}' |\
+      /bin/sed -e '/\/bin\/ps$/d'   -e '/\/bin\/ps\.exe$/d'  \
+               -e '/\/bin\/sed$/d'  -e '/\/bin\/sed\.exe$/d' \
+	       -e '/\/bin\/awk$/d'  -e '/\/bin\/awk\.exe$/d' \
+	       -e '/\/bin\/sort$/d' -e '/\/bin\/sort\.exe$/d' \
+	       -e '/\/bin\/uniq$/d' -e '/\/bin\/uniq\.exe$/d' \
+               -e '/\/bin\/dash$/d' -e '/\/bin\/dash\.exe$/d' |\
+	       sort | uniq | grep -E '.'
+    ProcessResult=$?
+    ;;
+  cygwin )
+    grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename
+    ProcessResult=$?
+    ;;
+esac
+if [ $ProcessResult -eq 0 -a -z "$RebaseDebug" ]
 then
     echo "$ProgramName: only ash or dash processes are allowed during this process."
     echo "    Exit all Cygwin processes and stop all Cygwin services."
@@ -209,10 +239,26 @@ ExeFile="$TmpDir/peflags_exe.lst"
 DllFile="$TmpDir/peflags_dll.lst"
 
 # Create file list
-find /etc/setup -name '*.lst.gz' | xargs gzip -d -c |
-    grep -E "\.($Suffixes)\$" |
-    sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \
-	-e 's/^/\//' -e '/d?ash\.exe$/d' -e '/peflags\.exe$/d' >"$TmpFile"
+case $Platform in
+  cygwin)
+    find /etc/setup -name '*.lst.gz' | xargs gzip -d -c |
+      grep -E "\.($Suffixes)\$" |
+      sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \
+          -e '/sys-root\/mingw/d' -e 's/^/\//' \
+          -e '/d?ash\.exe$/d' -e '/peflags\.exe$/d' >"${TmpFile}"
+    ;;
+  msys)
+    for f in /bin /lib
+    do
+      find $f -type f |
+        grep -E "\.($Suffixes)\$" |
+        sed -e '/msys-1\.0.*\.dll$/d' -e '/cygwin1\.dll$/d' \
+            -e '/cyglsa.*\.dll$/d' -e '/d?ash\.exe$/d' \
+            -e '/peflags\.exe$/d' >>"$TmpFile"
+    done
+    ;;
+  mingw) ;; # no automatic files; only command line
+esac
 
 # Append user supplied file list, if any
 if [ -n "$FileList" ]
Index: rebase.c
===================================================================
RCS file: /cvs/cygwin-apps/rebase/rebase.c,v
retrieving revision 1.6
diff -u -p -r1.6 rebase.c
--- rebase.c	21 Jul 2011 19:10:04 -0000	1.6
+++ rebase.c	22 Jul 2011 23:59:09 -0000
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <time.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #if defined(__CYGWIN__) || defined(__MSYS__)
@@ -28,7 +29,12 @@
 #include <locale.h>
 #include <getopt.h>
 #include <string.h>
-#include <inttypes.h>
+#if defined(__MSYS__)
+/* MSYS has no inttypes.h */
+# define PRIx64 "llx"
+#else
+# include <inttypes.h>
+#endif
 #include <errno.h>
 #include "imagehelper.h"
 
@@ -50,6 +56,10 @@ FILE *file_list_fopen (const char *file_
 char *file_list_fgets (char *buf, int size, FILE *file);
 int file_list_fclose (FILE *file);
 void version ();
+#if defined(__MSYS__)
+/* MSYS has no strtoull */
+unsigned long long strtoull(const char *, char **, int);
+#endif
 
 #ifdef __x86_64__
 WORD machine = IMAGE_FILE_MACHINE_AMD64;
@@ -122,10 +132,12 @@ unsigned int img_info_max_size = 0;
 #else
 #define IMG_INFO_FILE IMG_INFO_FILE_I386
 #endif
-char *db_file = IMG_INFO_FILE;
-char tmp_file[] =     SYSCONFDIR "/rebase.db.XXXXXX";
+char *DB_FILE = IMG_INFO_FILE;
+char TMP_FILE[] = SYSCONFDIR "/rebase.db.XXXXXX";
+char *db_file = NULL;
+char *tmp_file = NULL;
 
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
 ULONG64 cygwin_dll_image_base = 0;
 ULONG cygwin_dll_image_size = 0;
 #endif
@@ -160,11 +172,20 @@ main (int argc, char *argv[])
   if (image_storage_flag)
     {
       if (load_image_info () < 0)
-      	return 2;
+	return 2;
       img_info_rebase_start = img_info_size;
     }
 
-#ifdef __CYGWIN__
+#if defined(__MSYS__)
+  if (machine == IMAGE_FILE_MACHINE_I386)
+    {
+      GetImageInfos64 ("/bin/msys-1.0.dll", NULL,
+	               &cygwin_dll_image_base, &cygwin_dll_image_size);
+      /* See cygwin code, below */
+      cygwin_dll_image_base -= 3 * ALLOCATION_SLOT;
+      cygwin_dll_image_size += 3 * ALLOCATION_SLOT + 8 * ALLOCATION_SLOT;
+    }
+#elif defined(__CYGWIN__)
   if (machine == IMAGE_FILE_MACHINE_I386)
     {
       /* Fetch the Cygwin DLLs data to make sure that DLLs aren't rebased
@@ -271,11 +292,13 @@ img_info_name_cmp (const void *a, const 
   return strcmp (((img_info_t *) a)->name, ((img_info_t *) b)->name);
 }
 
-#ifndef __CYGWIN__
+#if !defined(__CYGWIN__) && !defined(__MSYS__)
 int
 mkstemp (char *name)
 {
-  return open (mktemp (name), O_CREAT | O_TRUNC | O_EXCL, 0600);
+  return _open (mktemp (name),
+      O_RDWR | O_BINARY | O_CREAT | O_EXCL | O_TRUNC | _O_SHORT_LIVED,
+      _S_IREAD|_S_IWRITE);
 }
 #endif
 
@@ -308,7 +331,8 @@ save_image_info ()
   hdr.offset = offset;
   hdr.down_flag = down_flag;
   hdr.count = img_info_size;
-  if (write (fd, &hdr, sizeof hdr) < 0)
+  errno = 0;
+  if (write (fd, &hdr, sizeof (hdr)) < 0)
     {
       fprintf (stderr, "%s: failed to write rebase database: %s\n",
 	       progname, strerror (errno));
@@ -336,7 +360,8 @@ save_image_info ()
 	    break;
 	  }
     }
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) && !defined(__MSYS__)
+  /* fchmod is broken on msys */
   fchmod (fd, 0660);
 #else
   chmod (tmp_file, 0660);
@@ -384,13 +409,13 @@ load_image_info ()
   int i;
   img_info_hdr_t hdr;
 
-  fd = open (db_file, O_RDONLY);
+  fd = open (db_file, O_RDONLY | O_BINARY);
   if (fd < 0)
     {
       /* It's no error if the file doesn't exist.  However, in this case
 	 the -b option is mandatory. */
       if (errno == ENOENT && image_base)
-      	return 0;
+	return 0;
       fprintf (stderr, "%s: failed to open rebase database \"%s\":\n%s\n",
 	       progname, db_file, strerror (errno));
       return -1;
@@ -480,7 +505,7 @@ load_image_info ()
       for (i = 0; i < img_info_size; ++i)
 	{
 	  img_info_list[i].name = (char *)
-				  malloc (img_info_list[i].name_size);
+				  calloc (img_info_list[i].name_size, sizeof(char));
 	  if (!img_info_list[i].name)
 	    {
 	      fprintf (stderr, "%s: Out of memory.\n", progname);
@@ -526,13 +551,15 @@ merge_image_info ()
   for (i = img_info_rebase_start; i + 1 < img_info_size; ++i)
     if ((img_info_list[i].name_size == img_info_list[i + 1].name_size
 	 && !strcmp (img_info_list[i].name, img_info_list[i + 1].name))
-#ifdef __CYGWIN__
+#if defined(__MSYS__)
+	|| !strcmp (img_info_list[i].name, "/usr/bin/msys-1.0.dll")
+#elif defined(__CYGWIN__)
 	|| !strcmp (img_info_list[i].name, "/usr/bin/cygwin1.dll")
 #endif
        )
       {
 	free (img_info_list[i].name);
-	memmove (img_info_list + i, img_info_list + i + 1, 
+	memmove (img_info_list + i, img_info_list + i + 1,
 		 (img_info_size - i - 1) * sizeof (img_info_t));
 	--img_info_size;
 	--i;
@@ -606,7 +633,7 @@ merge_image_info ()
       if (access (img_info_list[i].name, F_OK) == -1
 	  || !GetImageInfos64 (img_info_list[i].name, NULL,
 			       &cur_base, &cur_size))
-      	{
+	{
 	  free (img_info_list[i].name);
 	  memmove (img_info_list + i, img_info_list + i + 1,
 		   (img_info_size - i - 1) * sizeof (img_info_t));
@@ -671,8 +698,8 @@ merge_image_info ()
 	  new_base = floating_image_base - img_info_list[i].slot_size - offset;
 	  if (new_base >= img_info_list[end].base
 			  + img_info_list[end].slot_size
-#ifdef __CYGWIN__
-	      /* Don't overlap the Cygwin DLL. */
+#if defined(__CYGWIN__) || defined(__MSYS__)
+	      /* Don't overlap the Cygwin/MSYS DLL. */
 	      && (new_base >= cygwin_dll_image_base + cygwin_dll_image_size
 		  || new_base + img_info_list[i].slot_size
 		     <= cygwin_dll_image_base)
@@ -692,7 +719,7 @@ merge_image_info ()
 	}
       /* Nothing matches.  Set floating_image_base to the start of the
 	 uppermost DLL at this point and try again. */
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
       if (floating_image_base >= cygwin_dll_image_base + cygwin_dll_image_size
 	  && img_info_list[end].base < cygwin_dll_image_base)
 	floating_image_base = cygwin_dll_image_base;
@@ -836,14 +863,14 @@ print_image_info ()
 	if (img_info_list[i].flag.needs_rebasing == 0)
 	  {
 	    free (img_info_list[i].name);
-	    memmove (img_info_list + i, img_info_list + i + 1, 
+	    memmove (img_info_list + i, img_info_list + i + 1,
 		     (img_info_size - i - 1) * sizeof (img_info_t));
 	  }
 	else
 	  {
 	    free (img_info_list[i + 1].name);
 	    if (i + 2 < img_info_size)
-	      memmove (img_info_list + i + 1, img_info_list + i + 2, 
+	      memmove (img_info_list + i + 1, img_info_list + i + 2,
 		       (img_info_size - i - 2) * sizeof (img_info_t));
 	  }
 	--img_info_size;
@@ -913,7 +940,7 @@ rebase (const char *pathname, ULONG64 *n
   if (down_flag)
     *new_image_base -= offset;
 
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
 retry:
 #endif
 
@@ -972,7 +999,7 @@ retry:
       return FALSE;
     }
 
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
   /* Avoid the case that a DLL is rebased into the address space taken
      by the Cygwin DLL.  Only test in down_flag == TRUE case, otherwise
      the return value in new_image_base is not meaningful */
@@ -1033,11 +1060,11 @@ parse_args (int argc, char *argv[])
 	{
 	case '4':
 	  machine = IMAGE_FILE_MACHINE_I386;
-	  db_file = IMG_INFO_FILE_I386;
+	  DB_FILE = IMG_INFO_FILE_I386;
 	  break;
 	case '8':
 	  machine = IMAGE_FILE_MACHINE_AMD64;
-	  db_file = IMG_INFO_FILE_AMD64;
+	  DB_FILE = IMG_INFO_FILE_AMD64;
 	  break;
 	case 'b':
 	  image_base = string_to_ulonglong (optarg);
@@ -1090,6 +1117,85 @@ parse_args (int argc, char *argv[])
     }
 
   args_index = optind;
+
+  /* Initialize db_file and tmp_file from pattern */
+#if defined(__CYGWIN__) || defined(__MSYS__)
+  /* We don't explicitly free these, but (a) this function is only
+   * called once, and (b) we wouldn't free until exit() anyway, and
+   * that will happen automatically upon process cleanup.
+   */
+  db_file = strdup(DB_FILE);
+  tmp_file = strdup(TMP_FILE);
+#else
+  {
+    /* Borrow cygwin code for extracting module path, but use ANSI */
+    char exepath[PATH_MAX];
+    char* p = NULL;
+    char* p2 = NULL;
+    size_t sz = 0;
+
+    if (!GetModuleFileNameA (NULL, exepath, PATH_MAX))
+      fprintf (stderr, "%s: can't determine rebase installation path\n",
+	       progname);
+    p = exepath;
+    if (strncmp (p, "\\\\?\\", 4))   /* No long path prefix. */
+      {
+        if (!strncasecmp (p, "\\\\", 2))     /* UNC */
+          {
+            p = strcpy (p, "\\??\\UN");
+            GetModuleFileNameA (NULL, p, PATH_MAX - 6);
+            *p = 'C';
+          }
+        else
+          {
+            p = strcpy (p, "\\??\\");
+            GetModuleFileNameA (NULL, p, PATH_MAX - 4);
+          }
+      }
+
+    /* strip off exename and trailing slash */
+    sz = strlen (exepath);
+    p = exepath + sz - 1;
+    while (p && (p > exepath) && (*p == '/' || *p == '\\'))
+      {
+        *p = '\0';
+        p--;
+      }
+    p = strrchr(exepath, '/');
+    p2 = strrchr(exepath, '\\');
+    if (p || p2)
+      {
+        if (p2 > p)
+          p = p2;
+        if (p > exepath)
+          *p = '\0';
+        else
+          {
+            p++;
+            *p = '\0';
+          }
+      }
+    sz = strlen (exepath);
+
+    /* We don't explicitly free these, but (a) this function is only
+     * called once, and (b) we wouldn't free until exit() anyway, and
+     * that will happen automatically upon process cleanup.
+     */
+    db_file = (char *) calloc(sz + strlen(DB_FILE) + 1, sizeof(char));
+    tmp_file = (char *) calloc(sz + strlen(TMP_FILE) + 1, sizeof(char));
+    strcpy(db_file, exepath);
+    strcpy(&db_file[sz], DB_FILE);
+    strcpy(tmp_file, exepath);
+    strcpy(&tmp_file[sz], TMP_FILE);
+
+    for (p = db_file; *p != '\0'; p++)
+      if (*p == '/')
+        *p = '\\';
+    for (p = tmp_file; *p != '\0'; p++)
+      if (*p == '/')
+        *p = '\\';
+  }
+#endif
 }
 
 unsigned long long
@@ -1252,3 +1358,131 @@ version ()
   fprintf (stderr, "Copyright (c) 2001, 2002, 2003, 2004, 2008, 2011 "
 	   "Ralf Habacker, Jason Tishler, et al.\n");
 }
+
+#if defined(__MSYS__)
+/* implementation adapted from google andriod bionic libc's
+ * strntoumax and strntoimax (removing the dependency on 'n')
+ */
+
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+
+static inline int digitval(int ch)
+{
+  unsigned  d;
+
+  d = (unsigned)(ch - '0');
+  if (d < 10) return (int)d;
+
+  d = (unsigned)(ch - 'a');
+  if (d < 6) return (int)(d+10);
+
+  d = (unsigned)(ch - 'A');
+  if (d < 6) return (int)(d+10);
+
+  return -1;
+}
+
+/*
+ * Convert a string to an unsigned long long.
+ *
+ * Ignores `locale' stuff.  Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long long
+strtoull(const char *nptr, char **endptr, int base)
+{
+  const unsigned char*  p   = nptr;
+  const unsigned char*  end;
+  int                   minus = 0;
+  unsigned long long    v = 0;
+  int                   d;
+  end = p + strlen(nptr);
+
+  /* skip leading space */
+  while (p < end && isspace(*p))
+    p++;
+
+  /* Single optional + or - */
+  if (p < end)
+    {
+      char c = p[0];
+      if ( c == '-' || c == '+' )
+        {
+          minus = (c == '-');
+          p++;
+        }
+    }
+
+  if ( base == 0 )
+    {
+      if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') )
+        {
+          p += 2;
+          base = 16;
+        }
+      else if ( p+1 < end && p[0] == '0' )
+        {
+          p   += 1;
+          base = 8;
+        }
+      else
+        {
+          base = 10;
+        }
+    }
+  else if ( base == 16 )
+    {
+      if ( p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X') )
+        {
+          p += 2;
+        }
+    }
+
+  while ( p < end && (d = digitval(*p)) >= 0 && d < base )
+    {
+      v = v*base + d;
+      p += 1;
+    }
+
+  if ( endptr )
+    *endptr = (char *)p;
+
+  return minus ? -v : v;
+}
+#endif
+
Index: rebaseall.in
===================================================================
RCS file: /cvs/cygwin-apps/rebase/rebaseall.in,v
retrieving revision 1.4
diff -u -p -r1.4 rebaseall.in
--- rebaseall.in	21 Jul 2011 19:10:04 -0000	1.4
+++ rebaseall.in	22 Jul 2011 23:59:09 -0000
@@ -64,9 +64,39 @@ case `uname -m` in
 	;;
 esac
 
+# Determine platform
+Platform=`uname -s`
+case $Platform in
+ *MINGW*  | *mingw*  ) Platform=mingw  ;;
+ *CYGWIN* | *cygwin* ) Platform=cygwin ;;
+ *MSYS*   | *msys*   ) Platform=msys   ;;
+ * )
+    echo "Unsupported platform: $Platform" 1>&2
+    exit 1
+    ;;
+esac
+
 # Verify only ash or dash processes are running
-grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename
-if [ $? -eq 0 -a -z "${RebaseDebug}" ]
+ProcessResult=0
+case $Platform in
+  mingw|msys )
+    # Also exclude the commands we're using below, which is not ideal
+    /bin/ps -s | /bin/sed -e '1d' | /bin/awk '{print $NF}' |\
+      /bin/sed -e '/\/bin\/ps$/d'   -e '/\/bin\/ps\.exe$/d'  \
+               -e '/\/bin\/sed$/d'  -e '/\/bin\/sed\.exe$/d' \
+               -e '/\/bin\/awk$/d'  -e '/\/bin\/awk\.exe$/d' \
+               -e '/\/bin\/sort$/d' -e '/\/bin\/sort\.exe$/d' \
+               -e '/\/bin\/uniq$/d' -e '/\/bin\/uniq\.exe$/d' \
+               -e '/\/bin\/dash$/d' -e '/\/bin\/dash\.exe$/d' |\
+               sort | uniq | grep -E '.'
+    ProcessResult=$?
+    ;;
+  cygwin )
+    grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename
+    ProcessResult=$?
+    ;;
+esac
+if [ $ProcessResult -eq 0 -a -z "${RebaseDebug}" ]
 then
     echo "${ProgramName}: only ash or dash processes are allowed during rebasing"
     echo "    Exit all Cygwin processes and stop all Cygwin services."
@@ -139,11 +169,25 @@ fi
 TmpFile="$TmpDir/rebase.lst"
 
 # Create rebase list
-find /etc/setup -name '*.lst.gz' | xargs gzip -d -c |
-    grep -E "\.($Suffixes)\$" |
-    sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \
-	-e '/sys-root\/mingw/d' \
-	-e 's/^/\//' -e '/d?ash\.exe$/d' -e '/rebase\.exe$/d' >"${TmpFile}"
+case $Platform in
+  cygwin)
+    find /etc/setup -name '*.lst.gz' | xargs gzip -d -c |
+      grep -E "\.($Suffixes)\$" |
+      sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \
+          -e '/sys-root\/mingw/d' -e 's/^/\//' \
+          -e '/d?ash\.exe$/d' -e '/rebase\.exe$/d' >"${TmpFile}"
+    ;;
+  mingw|msys)
+    for f in /bin /lib
+    do
+      find $f -type f |
+        grep -E "\.($Suffixes)\$" |
+	sed -e '/msys-1\.0.*\.dll$/d' -e '/cygwin1\.dll$/d' \
+	    -e '/cyglsa.*\.dll$/d' -e '/d?ash\.exe$/d' \
+	    -e '/rebase\.exe$/d' >>"$TmpFile"
+    done
+    ;;
+esac
 
 # Append user supplied file list, if any
 if [ -n "${FileList}" ]
Index: build-aux/config.guess
===================================================================
RCS file: /cvs/cygwin-apps/rebase/build-aux/config.guess,v
retrieving revision 1.1
diff -u -p -r1.1 config.guess
--- build-aux/config.guess	20 Jun 2011 23:27:01 -0000	1.1
+++ build-aux/config.guess	22 Jul 2011 23:59:09 -0000
@@ -803,6 +803,9 @@ EOF
     *:MINGW*:*)
 	echo ${UNAME_MACHINE}-pc-mingw32
 	exit ;;
+    i*:MSYS*:*)
+	echo ${UNAME_MACHINE}-pc-msys
+	exit ;;
     i*:windows32*:*)
     	# uname -m includes "-pc" on this system.
     	echo ${UNAME_MACHINE}-mingw32
Index: build-aux/config.sub
===================================================================
RCS file: /cvs/cygwin-apps/rebase/build-aux/config.sub,v
retrieving revision 1.1
diff -u -p -r1.1 config.sub
--- build-aux/config.sub	20 Jun 2011 23:27:01 -0000	1.1
+++ build-aux/config.sub	22 Jul 2011 23:59:09 -0000
@@ -771,6 +771,10 @@ case $basic_machine in
 	ms1-*)
 		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
 		;;
+	msys)
+		basic_machine=i386-pc
+		os=-msys
+		;;
 	mvs)
 		basic_machine=i370-ibm
 		os=-mvs
@@ -1293,7 +1297,7 @@ case $os in
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* | -cegcc* \
-	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
 	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
 	      | -uxpv* | -beos* | -mpeix* | -udk* \
 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
Index: imagehelper/Makefile.in
===================================================================
RCS file: /cvs/cygwin-apps/rebase/imagehelper/Makefile.in,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile.in
--- imagehelper/Makefile.in	21 Jun 2011 15:33:15 -0000	1.4
+++ imagehelper/Makefile.in	22 Jul 2011 23:59:09 -0000
@@ -54,8 +54,10 @@ FGREP = @FGREP@
 DEFAULT_INCLUDES = -I. -I$(srcdir)
 DEFS = @DEFS@
 
-override CFLAGS+=-Wall -Werror
-override CXXFLAGS+=-Wall -Werror
+override CFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@
+override CXXFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@
+override LDFLAGS+=-static @EXTRA_LDFLAG_OVERRIDES@
+override CXX_LDFLAGS+=@EXTRA_CXX_LDFLAG_OVERRIDES@
 
 .SUFFIXES:
 .SUFFIXES: .c .cc .$(O)
Index: imagehelper/rebase_main.cc
===================================================================
RCS file: /cvs/cygwin-apps/rebase/imagehelper/rebase_main.cc,v
retrieving revision 1.3
diff -u -p -r1.3 rebase_main.cc
--- imagehelper/rebase_main.cc	8 Jul 2011 07:18:55 -0000	1.3
+++ imagehelper/rebase_main.cc	22 Jul 2011 23:59:09 -0000
@@ -25,7 +25,7 @@
 #include <time.h>
 #include <stdlib.h>
 #include <getopt.h>
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
 #include <sys/cygwin.h>
 #endif
 #include <windows.h>
@@ -34,7 +34,7 @@
 
 using namespace std;
 
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MSYS__)
 string PosixToWin32(const string& aPosixPath);
 #else
 #define PosixToWin32(aPosixPath) aPosixPath
@@ -67,7 +67,7 @@ main(int argc, char* argv[])
         {
           ULONG64 ImageBase;
           ULONG ImageSize;
-          GetImageInfos64(const_cast<LPSTR>(aFile.c_str()),&ImageBase,&ImageSize);
+          GetImageInfos64(const_cast<LPSTR>(aFile.c_str()),NULL,&ImageBase,&ImageSize);
           cout << aFile << ": " << "ImageBase: 0x" << hex << ImageBase << " ImageSize: 0x" << hex << ImageSize << endl;
         }
       else if (theCheckFlag)
Index: imagehelper/sections.h
===================================================================
RCS file: /cvs/cygwin-apps/rebase/imagehelper/sections.h,v
retrieving revision 1.4
diff -u -p -r1.4 sections.h
--- imagehelper/sections.h	8 Jul 2011 07:18:55 -0000	1.4
+++ imagehelper/sections.h	22 Jul 2011 23:59:09 -0000
@@ -23,6 +23,21 @@
 
 #include <windows.h>
 
+#if !defined(__CYGWIN__) || defined(__MSYS__)
+/* MinGW|MSYS: mingw only defines uintptr_t for        */
+/* MSVC 2005 or better, and MSYS doesn't have stdint.h */
+# ifndef _UINTPTR_T_DEFINED
+#  define _UINTPTR_T_DEFINED
+#  ifdef _WIN64
+     typedef unsigned __int64 uintptr_t;
+#  else
+     typedef unsigned int uintptr_t;
+#  endif
+# endif
+#else
+# include <stdint.h>
+#endif
+
 typedef unsigned int uint;
 typedef unsigned short ushort;
 

Attachment: rebase-dump.c
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]