Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
Hi Yaakov,
Hi everybody else interested,


I guess you saw the discussion about GetVersionEx and Windows 8.1 on the
main list.

In the meantime I found that the missing manifest files in our
executables apparently have more implications than anticipated.

Windows 8.1's Task Manager has a new column in it's detailed view.  It's
called Operating System Context and it tells the user how executables
are treated by the OS in terms of compatibility.  I switched this on,
and I found that all our executables without manifests are treated as if
they are only Vista-compatible and never made a step beyond that.

This has actual implications.  For instance, up to Vista the
GetOverlappedResult function has a bug in terms of a race condition
related to the usage of the event object.  Applications which are
treated as Vista-only compatible get the Vista behaviour of
GetOverlappedResult, including the race condition!

Given that everything happening is the fault of the Cygwin DLL, not the
fault of the executable, I would like to be able to tell the OS,
whatever version it is, yes, this executable is Windows X.Y compatible.

Obviously this can only work if you build a new executable and know the
OS GUID, but still...

So I was wondering if we could, somehow, tweak cygport to add a manifest
to every created executable, along the lines of the setup manifests,
without having to mention that in the cygport file.  Fully automatic.

The manifests and, as a result, the cygport package would have to be
updated every time Microsoft releases a new OS version, but that's just
adding another GUID to the manifest.

The downside (as of the time of writing) is this:

  I did not manage to add a .rsrc section to an executable using
  objcopy, without the executable being broken afterwards.

  The *only* way I was able to add a mainfest resource to an existing
  executable was a helper application which uses the Win32 function
  UpdateResource, using a crude algorithm, here with tcsh as example:

  - Create a tcsh-manifest.rc manifest (aka steal the setup.exe manifest).
  - Create a tcsh-manifest.o file via windres.
  - Create a dummy.exe executable with just `int main(){}' and link it
with tcsh-manifest.o.
  - Make sure tcsh.exe does not contain any section with long sectionname
(here: .gnu_debuglink).
  - Call the helper application, which basically works like this:

  LoadLibrary(dummy.exe);
  FindResource(CREATEPROCESS_MANIFEST_RESOURCE_ID, RT_MANIFEST);
  LoadResource(...)
  LockResource(...)
  BeginUpdateResource(tcsh.exe)
  UpdateResource(RT_MANIFEST,CREATEPROCESS_MANIFEST_RESOURCE_ID,...)
  EndUpdateResource(...)

   - The resulting executable actually worked and was treated as a
 Windows 8.1 executable.

   If this hack is done after stripping, but before adding the
   .gnu_debuglink section, it could run automatically and all newly
   produced executables would be *finally* compatible with latest
   Windows versions.

Apart from the fact that it would be nice if our linker would do this
automatically and transparently, is that something we should do in
cygport for the time being?


Thanks,
Corinna

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


pgpG4JTbDCTXD.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Charles Wilson

On 11/20/2013 8:28 AM, Corinna Vinschen wrote:

Apart from the fact that it would be nice if our linker would do this
automatically and transparently,


Or libtool, if you use it to link your exe?  PTC...since $new-libtool is 
pretty high on my to-do list.


It'd be better if there was an option to ld/gcc, of course -- but the 
details would be rather complicated.  You wouldn't want to invoke a 
separate executable like windres b/c then your build recipe/makefile 
would have to change.  Best if $LD_FLAGS could be used... maybe 
something hideously ugly like -w32-manifest-compat file [1] where 
file is not a full XML manifest, but rather contains a list of GUIDs 
[2], and ld/gcc autogenerates the manifest with just that stuff.


That way, if you manually create a manifest (for other purposes), you 
could just /not/ use the new flag.


I know, SHTDI...


is that something we should do in
cygport for the time being?


[1] or comma-separated list of GUIDs? That'd get long and ugly, very fast.

[2] not OS names, b/c then (a) ld/gcc would have to know the 
corresponding GUID, and (b) the GUID-OS database would be out of date 
and require a binutils/gcc patch every time Redmond released a new 
service pack.


--
Chuck




Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 09:47, Charles Wilson wrote:
 On 11/20/2013 8:28 AM, Corinna Vinschen wrote:
 Apart from the fact that it would be nice if our linker would do this
 automatically and transparently,
 
 Or libtool, if you use it to link your exe?  PTC...since
 $new-libtool is pretty high on my to-do list.
 
 It'd be better if there was an option to ld/gcc, of course -- but
 the details would be rather complicated.  You wouldn't want to
 invoke a separate executable like windres b/c then your build
 recipe/makefile would have to change.  Best if $LD_FLAGS could be
 used... maybe something hideously ugly like -w32-manifest-compat
 file [1] where file is not a full XML manifest, but rather
 contains a list of GUIDs [2], and ld/gcc autogenerates the manifest
 with just that stuff.
 
 That way, if you manually create a manifest (for other purposes),
 you could just /not/ use the new flag.

The other way around.  If your project does not link in a resource
anyway, which means that your project is WIn32 aware, then ld should
add the manifest resource by default.  Everything else means that
you have to tweak all project configury, which is only barely descibed
by a can of worms...

A simple windres call in cygport would be nice, but unfortunately windres
does not yet have this capability to add a resource to an existing exe.

 I know, SHTDI...

Yes, that's pretty much the problem.  Even my ugly workaround is bad,
because it only works on Windows.  No more cross-building on Linux :-P


Corinna

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


pgp0uHkYOrbcs.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Christopher Faylor
On Wed, Nov 20, 2013 at 04:01:01PM +0100, Corinna Vinschen wrote:
On Nov 20 09:47, Charles Wilson wrote:
 On 11/20/2013 8:28 AM, Corinna Vinschen wrote:
 Apart from the fact that it would be nice if our linker would do this
 automatically and transparently,
 
 Or libtool, if you use it to link your exe?  PTC...since
 $new-libtool is pretty high on my to-do list.
 
 It'd be better if there was an option to ld/gcc, of course -- but
 the details would be rather complicated.  You wouldn't want to
 invoke a separate executable like windres b/c then your build
 recipe/makefile would have to change.  Best if $LD_FLAGS could be
 used... maybe something hideously ugly like -w32-manifest-compat
 file [1] where file is not a full XML manifest, but rather
 contains a list of GUIDs [2], and ld/gcc autogenerates the manifest
 with just that stuff.
 
 That way, if you manually create a manifest (for other purposes),
 you could just /not/ use the new flag.

The other way around.  If your project does not link in a resource
anyway, which means that your project is WIn32 aware, then ld should
add the manifest resource by default.  Everything else means that
you have to tweak all project configury, which is only barely descibed
by a can of worms...

A simple windres call in cygport would be nice, but unfortunately windres
does not yet have this capability to add a resource to an existing exe.

 I know, SHTDI...

Yes, that's pretty much the problem.  Even my ugly workaround is bad,
because it only works on Windows.  No more cross-building on Linux :-P

Some more ugly hacks: Could cygwin itself create the manifests when it
runs a program iff they don't exist?  Or, alternately, setup.exe?  Or
rebase?

cgf


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 16:01, Corinna Vinschen wrote:
 On Nov 20 09:47, Charles Wilson wrote:
  On 11/20/2013 8:28 AM, Corinna Vinschen wrote:
  Apart from the fact that it would be nice if our linker would do this
  automatically and transparently,
  
  Or libtool, if you use it to link your exe?  PTC...since
  $new-libtool is pretty high on my to-do list.
  
  It'd be better if there was an option to ld/gcc, of course -- but
  the details would be rather complicated.  You wouldn't want to
  invoke a separate executable like windres b/c then your build
  recipe/makefile would have to change.  Best if $LD_FLAGS could be
  used... maybe something hideously ugly like -w32-manifest-compat
  file [1] where file is not a full XML manifest, but rather
  contains a list of GUIDs [2], and ld/gcc autogenerates the manifest
  with just that stuff.
  
  That way, if you manually create a manifest (for other purposes),
  you could just /not/ use the new flag.
 
 The other way around.  If your project does not link in a resource
 anyway, which means that your project is WIn32 aware, then ld should
 add the manifest resource by default.  Everything else means that
 you have to tweak all project configury, which is only barely descibed
 by a can of worms...
 
 A simple windres call in cygport would be nice, but unfortunately windres
 does not yet have this capability to add a resource to an existing exe.
 
  I know, SHTDI...
 
 Yes, that's pretty much the problem.  Even my ugly workaround is bad,
 because it only works on Windows.  No more cross-building on Linux :-P

I added the sources for my now radically simplified test to this mail.
It consists of three files:

  add-cygwin-default-manifest.c:  The source code adding the manifest.
  cygwin-default-mainfest.rc: The default resource containing the
  manifest.  It's target-agnostic.
  Makefile:   The Makefile.

To build the executable, just run `make'.  This creates the
add-cygwin-default-manifest executable with the embedded manifest.

To add a manifest to binary foo.exe, run `make doit EXE=foo.exe'
add-cygwin-default-manifest.exe pulls its own manifest and copies it
over to foo.exe.  This is the step which I didn't manage to reproduce
via objcopy.

Note the crude way how `make doit' works.  The UpdateResource
functionality is *extremly* sensitive against having an open handle to
the file still open in the same binary somewhere.  If you try something
like this:

  doit:
strip $(EXE)
objcopy --remove-section=.gnu_debuglink $(EXE)
./add-cygwin-default-manifest $(EXE)

then you'll get an error message EndUpdateResource: Win32 error 5.
Apparently, `make' has an open handle to $(EXE) and this is propagated
somehow to the child processes.  As a side note, trying to call, say,
GetBinaryType before calling BeginUpdateResource, or even stuff like
CreateFile/CloseHandle(!!!) will end up with EndUpdateResource: Win32
error 5.  As I wrote, *extremly* sensitive.  That sounds much better 
than badly written...


Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
#include windows.h
#include stdio.h
#include stdlib.h
#include unistd.h
#include string.h
#include errno.h
#include locale.h
#include sys/cygwin.h

int
main (int argc, char **argv)
{
  PWCHAR wpath;
  HGLOBAL hResLoad;   // handle to loaded resource
  HMODULE hExe;   // handle to existing .EXE file
  HRSRC hRes; // handle/ptr. to res. info. in hExe
  LPVOID lpResLock;   // pointer to resource data
  HANDLE h;

  setlocale (LC_ALL, );

  if (argc != 2)
{
  fprintf (stderr, Usage: %s file\n, argv[0]);
  return 1;
}

  wpath = cygwin_create_path (CCP_POSIX_TO_WIN_W, argv[1]);
  if (!wpath)
{
  fprintf (stderr, cygwin_create_path: %s\n, strerror (errno));
  return 1;
}

  hExe = GetModuleHandle (NULL);
  hRes = FindResourceW(hExe,
   MAKEINTRESOURCEW (CREATEPROCESS_MANIFEST_RESOURCE_ID),
   MAKEINTRESOURCEW (RT_MANIFEST));
  if (!hRes)
{
  fprintf (stderr, FindResourceW: Win32 error %d\n, GetLastError ());
  return 1;
}
  hResLoad = LoadResource(hExe, hRes);
  if (!hResLoad)
{
  fprintf (stderr, LoadResource: Win32 error %d\n, GetLastError ());
  return 1;
}
  lpResLock = LockResource(hResLoad);
  if (!lpResLock)
{
  fprintf (stderr, LockResource: Win32 error %d\n, GetLastError ());
  return 1;
}

  h = BeginUpdateResourceW (wpath, FALSE);
  if (!h)
{
  fprintf (stderr, BeginUpdateResourceW: Win32 error %d\n,
   GetLastError ());
  return 1;
}

  if (!UpdateResourceW (h, MAKEINTRESOURCEW (RT_MANIFEST),
MAKEINTRESOURCEW (CREATEPROCESS_MANIFEST_RESOURCE_ID),
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
lpResLock, SizeofResource(hExe, 

Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 17:02, Corinna Vinschen wrote:
 I added the sources for my now radically simplified test to this mail.
 It consists of three files:
 
   add-cygwin-default-manifest.c:  The source code adding the manifest.
   cygwin-default-mainfest.rc: The default resource containing the
   manifest.  It's target-agnostic.
   Makefile:   The Makefile.
 
 To build the executable, just run `make'.  This creates the
 add-cygwin-default-manifest executable with the embedded manifest.
 
 To add a manifest to binary foo.exe, run `make doit EXE=foo.exe'
 add-cygwin-default-manifest.exe pulls its own manifest and copies it
 over to foo.exe.  This is the step which I didn't manage to reproduce
 via objcopy.
 
 Note the crude way how `make doit' works.  The UpdateResource
 functionality is *extremly* sensitive against having an open handle to
 the file still open in the same binary somewhere.  If you try something
 like this:
 
   doit:
   strip $(EXE)
   objcopy --remove-section=.gnu_debuglink $(EXE)
   ./add-cygwin-default-manifest $(EXE)
 
 then you'll get an error message EndUpdateResource: Win32 error 5.
 Apparently, `make' has an open handle to $(EXE) and this is propagated
 somehow to the child processes.  As a side note, trying to call, say,
 GetBinaryType before calling BeginUpdateResource, or even stuff like
 CreateFile/CloseHandle(!!!) will end up with EndUpdateResource: Win32
 error 5.  As I wrote, *extremly* sensitive.  That sounds much better 
 than badly written...

As an additional datapoint:  If you successfully call the UpdateResource
stuff on a file with long section names, the resulting executable will
actually run, and is cirrectly recognized as Windows 8.1 aware.

The problem is that the sections with long section names will be broken,
because the Windows functions somehow screws up the section strings.
The result is that neither objdump, nor objcopy, nor GDB recognize any
of these sections.  Calling objdump -h either prints empty section
names, or you get something like this:

  $ objdump -h ./foo
  BFD: ./foo: bad string table size 0
  objdump: ./foo: Bad value


Corinna

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


pgpzaxAK7gYGS.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 10:43, Christopher Faylor wrote:
 On Wed, Nov 20, 2013 at 04:01:01PM +0100, Corinna Vinschen wrote:
 On Nov 20 09:47, Charles Wilson wrote:
  On 11/20/2013 8:28 AM, Corinna Vinschen wrote:
  Apart from the fact that it would be nice if our linker would do this
  automatically and transparently,
  
  Or libtool, if you use it to link your exe?  PTC...since
  $new-libtool is pretty high on my to-do list.
  
  It'd be better if there was an option to ld/gcc, of course -- but
  the details would be rather complicated.  You wouldn't want to
  invoke a separate executable like windres b/c then your build
  recipe/makefile would have to change.  Best if $LD_FLAGS could be
  used... maybe something hideously ugly like -w32-manifest-compat
  file [1] where file is not a full XML manifest, but rather
  contains a list of GUIDs [2], and ld/gcc autogenerates the manifest
  with just that stuff.
  
  That way, if you manually create a manifest (for other purposes),
  you could just /not/ use the new flag.
 
 The other way around.  If your project does not link in a resource
 anyway, which means that your project is WIn32 aware, then ld should
 add the manifest resource by default.  Everything else means that
 you have to tweak all project configury, which is only barely descibed
 by a can of worms...
 
 A simple windres call in cygport would be nice, but unfortunately windres
 does not yet have this capability to add a resource to an existing exe.
 
  I know, SHTDI...
 
 Yes, that's pretty much the problem.  Even my ugly workaround is bad,
 because it only works on Windows.  No more cross-building on Linux :-P
 
 Some more ugly hacks: Could cygwin itself create the manifests when it
 runs a program iff they don't exist?  Or, alternately, setup.exe?  Or
 rebase?

Cygwin itself, never I guess.  See my other mail I just sent.
As I said, *extremly* sensitive.  Rinse and repeat.

Setup could do it, but the problem is the existence of sections with
long section names, especially debug sections and the .gnu_debuglink
section.  It's quite the mess and rather complicated to perform since
you need to be sure to filter out the problematic sections, or better,
to perform the action *after* strip, and *before* adding the
.gnu_debuginfo section.

rebase is the wrong tool for this.  It handles DLLs, not executables.


Corinna

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


pgpnsLB9Ck99d.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Achim Gratz
Corinna Vinschen writes:
   - Call the helper application, which basically works like this:

   LoadLibrary(dummy.exe);
   FindResource(CREATEPROCESS_MANIFEST_RESOURCE_ID, RT_MANIFEST);
   LoadResource(...)
   LockResource(...)
   BeginUpdateResource(tcsh.exe)
   UpdateResource(RT_MANIFEST,CREATEPROCESS_MANIFEST_RESOURCE_ID,...)
   EndUpdateResource(...)

- The resulting executable actually worked and was treated as a
  Windows 8.1 executable.

If this hack is done after stripping, but before adding the
.gnu_debuglink section, it could run automatically and all newly
produced executables would be *finally* compatible with latest
Windows versions.

Is that something that could be run during autorebase or bolted on to
peflags perhaps?


Regards,
Achim.
-- 
+[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 17:26, Achim Gratz wrote:
 Corinna Vinschen writes:
- Call the helper application, which basically works like this:
 
LoadLibrary(dummy.exe);
FindResource(CREATEPROCESS_MANIFEST_RESOURCE_ID, RT_MANIFEST);
LoadResource(...)
LockResource(...)
BeginUpdateResource(tcsh.exe)
UpdateResource(RT_MANIFEST,CREATEPROCESS_MANIFEST_RESOURCE_ID,...)
EndUpdateResource(...)
 
 - The resulting executable actually worked and was treated as a
   Windows 8.1 executable.
 
 If this hack is done after stripping, but before adding the
 .gnu_debuglink section, it could run automatically and all newly
 produced executables would be *finally* compatible with latest
 Windows versions.
 
 Is that something that could be run during autorebase or bolted on to
 peflags perhaps?

Well, perhaps.  I'm just not sure it's the right thing to do it at
postinstall time.  I mean, it's not impossible, obviously, but it's
a lot of stuff per executable and running this for a few thousand .exe
files could take some time.

We would also have to make sure that the sections with long section
names are recreated after adding the .rsrc section, which is something
I don't quite see how to accomplish, right now.


Corinna

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


pgpbu9FDDglyd.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Achim Gratz
Corinna Vinschen writes:
 Well, perhaps.  I'm just not sure it's the right thing to do it at
 postinstall time.  I mean, it's not impossible, obviously, but it's
 a lot of stuff per executable and running this for a few thousand .exe
 files could take some time.

Yes, it does... but ever since I've switched to doing incremental
autorebases that time has shrunk a lot.

 We would also have to make sure that the sections with long section
 names are recreated after adding the .rsrc section, which is something
 I don't quite see how to accomplish, right now.

Hmm.  I'm out of my depths on this, but would it be possible to excise
those sections, do whatever changes are necessary to the rest of the
executable and then add them back?


Regards,
Achim.
-- 
+[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]+

SD adaptation for Waldorf Blofeld V1.15B11:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 18:22, Achim Gratz wrote:
 Corinna Vinschen writes:
  Well, perhaps.  I'm just not sure it's the right thing to do it at
  postinstall time.  I mean, it's not impossible, obviously, but it's
  a lot of stuff per executable and running this for a few thousand .exe
  files could take some time.
 
 Yes, it does... but ever since I've switched to doing incremental
 autorebases that time has shrunk a lot.
 
  We would also have to make sure that the sections with long section
  names are recreated after adding the .rsrc section, which is something
  I don't quite see how to accomplish, right now.
 
 Hmm.  I'm out of my depths on this, but would it be possible to excise
 those sections, do whatever changes are necessary to the rest of the
 executable and then add them back?

I don't know.  It's apparently more complicated than just calling
objcopy.  For instance, objcopy can export sections from a file in
whatever format you want, but it can only add back sections if they are
given as binary blobs.  If you add such a binary blob it's missing
relocation information.  Also, you have to make sure all the sections
start at the right address, thanks to the harebrained PE/COFF format.

This is apparently a big deal, otherwise it should have been no problem
to add a resource binary blob into an executable without making Windows
choke on it (ERROR_BAD_EXE_FORMAT).  Maybe I did something wrong, but I
would have no idea what option I missed.


Corinna

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


pgp2u4Fki1dhp.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 18:32, Corinna Vinschen wrote:
 On Nov 20 18:22, Achim Gratz wrote:
  Corinna Vinschen writes:
   Well, perhaps.  I'm just not sure it's the right thing to do it at
   postinstall time.  I mean, it's not impossible, obviously, but it's
   a lot of stuff per executable and running this for a few thousand .exe
   files could take some time.
  
  Yes, it does... but ever since I've switched to doing incremental
  autorebases that time has shrunk a lot.
  
   We would also have to make sure that the sections with long section
   names are recreated after adding the .rsrc section, which is something
   I don't quite see how to accomplish, right now.
  
  Hmm.  I'm out of my depths on this, but would it be possible to excise
  those sections, do whatever changes are necessary to the rest of the
  executable and then add them back?
 
 I don't know.  It's apparently more complicated than just calling
 objcopy.  For instance, objcopy can export sections from a file in
 whatever format you want, but it can only add back sections if they are
 given as binary blobs.  If you add such a binary blob it's missing
 relocation information.  Also, you have to make sure all the sections
 start at the right address, thanks to the harebrained PE/COFF format.
 
 This is apparently a big deal, otherwise it should have been no problem
 to add a resource binary blob into an executable without making Windows
 choke on it (ERROR_BAD_EXE_FORMAT).  Maybe I did something wrong, but I
 would have no idea what option I missed.

I just made a quick test for the sake of creating a generic script to
add the manifests.

Assuming I have a file with just a single section with long section
name, the .gnu_debuglink section.  Fortunately this seems to be the
usual case.

I can extract the section content:

  $ objcopy -j .gnu_debuglink -O binary foo.exe foo.exe.gdl

Then I can drop the .gnu_debuglink from the executable.  Create a copy
of the original so as not to confuse the sensitive UpdateResource:

  $ objcopy -R .gnu_debuglink foo.exe foo.out

Then I can add the manifest:

  $ add-cygwin-default-manifest foo.out

Then it gets weird.  I'd like to create a .gnu_debuglink section
again.  The path is part of the binary foo.exe.gdl file:

  $ awk -F \\0 '{print $1;}' foo.dbgl
  foo.exe.dbg
  $ objcopy --add-gnu-debuglink=$(awk -F \\0 '{print $1;}' foo.dbgl) foo.out
  objcopy:stl7AEHg: cannot fill debug link section `foo.exe.dbg': No such file 
or directory

So the dbg file has to exist to be able to create a new .gnu_debuglink
section:

  $ touch $(awk -F \\0 '{print $1;}' foo.dbgl)
  $ objcopy --add-gnu-debuglink=$(awk -F \\0 '{print $1;}' foo.dbgl) foo.out

Cool.  That worked, and the resulting executable works as well.

But GDB doesn't find the symbol file anymore:

  $ gdb ./tcsh.out
  [...]
  Reading symbols from /home/corinna/manifest/tcsh.out...(no debugging symbols 
found)...done.
  (gdb) Quit
  $ objcopy -j .gnu_debuglink -O binary foo.out foo.out.gdl
  $ cmp foo.exe.gdl foo.out.gdl
  foo.exe.gdl foo.out.gdl differ: byte 17, line 1

Why is that?  And, if the .gnu_debuglink sections contains only a
filename and some flag value or something, why does it suddenly neglect
to search in the /usr/lib/debug directory?  How can this be fixed?


Corinna

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


pgp_6TSiRqOUb.pgp
Description: PGP signature


Re: Cygport and auto-manifestize compatibility manifest

2013-11-20 Thread Corinna Vinschen
On Nov 20 17:06, Corinna Vinschen wrote:
 On Nov 20 10:43, Christopher Faylor wrote:
  On Wed, Nov 20, 2013 at 04:01:01PM +0100, Corinna Vinschen wrote:
  On Nov 20 09:47, Charles Wilson wrote:
   On 11/20/2013 8:28 AM, Corinna Vinschen wrote:
   Apart from the fact that it would be nice if our linker would do this
   automatically and transparently,
   
   Or libtool, if you use it to link your exe?  PTC...since
   $new-libtool is pretty high on my to-do list.
   
   It'd be better if there was an option to ld/gcc, of course -- but
   the details would be rather complicated.  You wouldn't want to
   invoke a separate executable like windres b/c then your build
   recipe/makefile would have to change.  Best if $LD_FLAGS could be
   used... maybe something hideously ugly like -w32-manifest-compat
   file [1] where file is not a full XML manifest, but rather
   contains a list of GUIDs [2], and ld/gcc autogenerates the manifest
   with just that stuff.
   
   That way, if you manually create a manifest (for other purposes),
   you could just /not/ use the new flag.
  
  The other way around.  If your project does not link in a resource
  anyway, which means that your project is WIn32 aware, then ld should
  add the manifest resource by default.  Everything else means that
  you have to tweak all project configury, which is only barely descibed
  by a can of worms...
  
  A simple windres call in cygport would be nice, but unfortunately windres
  does not yet have this capability to add a resource to an existing exe.
  
   I know, SHTDI...
  
  Yes, that's pretty much the problem.  Even my ugly workaround is bad,
  because it only works on Windows.  No more cross-building on Linux :-P
  
  Some more ugly hacks: Could cygwin itself create the manifests when it
  runs a program iff they don't exist?  Or, alternately, setup.exe?  Or
  rebase?
 
 Cygwin itself, never I guess.  See my other mail I just sent.
 As I said, *extremly* sensitive.  Rinse and repeat.
 
 Setup could do it, but the problem is the existence of sections with
 long section names, especially debug sections and the .gnu_debuglink
 section.  It's quite the mess and rather complicated to perform since
 you need to be sure to filter out the problematic sections, or better,
 to perform the action *after* strip, and *before* adding the
 .gnu_debuginfo section.

For the records, here's the most dumb workaround:

  #!/bin/bash
  #
  # Assumes that a default manifest has been stored in /etc/defaults
  #
  cd /bin
  for i in *.exe
  do
if [ ! -f ${i}.manifest ]
then
  cp /etc/defaults/default.manifest ${i}.manifest
  # Enforce updating Activation Context Cache
  touch ${i}
fi
  done

This works, but it's pretty ugly.  1000 exe files, 1000 manifest files.
Hardlinks work, but are restricted to 1024 per file.  And it doesn't
actually make the output of ls /bin better.  Still, if we don't find a
better solution, this might be the way to go.


Corinna

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


pgpUa5xAL2MfB.pgp
Description: PGP signature


[PATCH] crypt: fix for -Wimplicit-function-declaration

2013-11-20 Thread Yaakov (Cygwin/X)

Attached patch is pretty self-explanatory.


Yaakov
2013-11-20  Yaakov Selkowitz  yselkowitz@...

	* crypt.c: #include time.h to fix implicit declaration of time(3).

Index: crypt.c
===
RCS file: /cvs/cygwin-apps/crypt/crypt.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 crypt.c
--- crypt.c	7 May 2012 11:00:13 -	1.1.1.1
+++ crypt.c	21 Nov 2013 00:55:55 -
@@ -1,6 +1,7 @@
 #include stdio.h
 #include stdlib.h
 #include string.h
+#include time.h
 #include encrypt.h
 
 const char *sc = ./