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: MingW-related setup.exe crash w/ DEP enabled


On Mar 17 17:12, Kai Tietz wrote:
> 2010/3/17 Corinna Vinschen <corinna-cygwin@cygwin.com>:
> > UPX is only the second problem. ?The really serious problem is that
> > the executable crashes under DEP.
> >
> >
> > Corinna
> 
> Neither in .CRT, nor in .TLS is executable for sure. They are
> containing function pointers (and for .TLS additional TLS data).
> 
> So by this for sure no DEP is reasoned.

I just debugged setup and found the reason. 

It looks like this has nothing to do with MingW, rather UPX covered the
original problem.

What crashes is the autoload code in setup.  In contrast to the Cygwin
DLL, which puts the autoload code into a special CODE section called
.autoload_text, the setup.exe autoload code is in the .data segment,
which is non-executable by default.

Using objcopy to mark the .data segment as a CODE segment lets setup
run under DEP just fine.

The way UPX works, the entire file is in a CODE section.  So it looks
like UPX fools DEP.

OTOH, uncompressing cgf's executable on cygwin.com (upx -d) and trying
to run it shows the exact same problem with DEP.

That could also explain that some people report trouble using setup.exe
on 64 bit Windows.  the x86_64 CPUs have hardware DEP, which perhaps
isn't fooled by the UPX trick.

For a patch I tried this:

Index: autoload.c
===================================================================
RCS file: /cvs/cygwin-apps/setup/autoload.c,v
retrieving revision 2.8
diff -u -p -r2.8 autoload.c
--- autoload.c	11 May 2009 10:49:14 -0000	2.8
+++ autoload.c	17 Mar 2010 16:49:48 -0000
@@ -27,7 +27,7 @@ typedef struct {
 #define DLL(n) __attribute__ ((used)) static DllInfo n ## _info __asm__ (#n "_info") = { #n, 0}
 
 #define Auto(dll, func, size) \
-	__asm__ ("\t.data"); \
+	__asm__ ("\t.section .autoload_text,\"wx\""); \
 	__asm__ ("\t.global\t_" #func "@" #size); \
 	__asm__ ("_" #func "@" #size ":"); \
 	__asm__ ("\tcall\tautoload_common"); \

The resulting setup.exe runs fine under DEP.

Is that patch ok, or is there a better way?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


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