[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

executable wrapper on mingw mangles arguments

From: Bruno Haible
Subject: executable wrapper on mingw mangles arguments
Date: Sun, 28 Sep 2008 23:55:27 +0200
User-agent: KMail/1.5.4


This is a severe regression in libtool 2.x w.r.t. 1.5.26. On mingw, several
of the gettext tests fail because the executable wrapper created by the
libtool script does two bad things:
1) It converts argv[0] from a filename with backslashes to a filename with
2) It does word splitting on arguments that contain spaces.

To reproduce:
Find in http://www.haible.de/bruno/gnu/ltargsbug.tar.gz a sample project
with a program 'argslinked' which prints its arguments. Once created in
a directory that does not use libtool, and once in a directory that uses

$ cd ltargsbug
$ ./configure CPPFLAGS=-Wall
$ make
$ without-libtool/argsgood abc 'def ghi' jkl
argv[0] = |.....\without-libtool\argsgood.exe|
argv[1] = |abc|
argv[2] = |def ghi|
argv[3] = |jkl|
$ without-libtool/argslinked abc 'def ghi' jkl
argv[0] = |.....\without-libtool\argslinked.exe|
argv[1] = |abc|
argv[2] = |def ghi|
argv[3] = |jkl|
$ with-libtool/argslinked abc 'def ghi' jkl
argv[0] = |...../with-libtool/.libs/argslinked.exe|
argv[1] = |abc|
argv[2] = |def|
argv[3] = |ghi|
argv[4] = |jkl|

Both are bugs. There should be a minimum of user-visible differences between
programs linked with libtool and statically linked programs.

Number 2) is the more severe for me, so let me explain and fix that one.
In Unix you pass an array argv[] from one program to another. It's copied
to a particular memory region during execve(), that's all. On Windows,
  - _spawnv converts the argv[] to a single "command line" string, by
    joining the arguments together, separated with spaces. Then it calls
  - CreateProcess takes a single "command line" string and splits it at
    spaces and tabs that are not enclosed in double-quotes, and also does
    complicated processing of backslashes and double-quotes.
The dumb thing is that the transformation done by _spawnv is by no means
the inverse of the transformation done by CreateProcess!

Find attached a patch that fixes it. The function prepare_spawn is taken
from gnulib. It neutralizes the string manipulations done by the MSVCRT
_spawnv runtime function and the Win32 CreateProcess function. So that

  argv[] -> (prepare_spawn) -> (_spawnv) command line -> (CreateProcess) argv[]

becomes an identity transformation.

With this patch, I get:

$ with-libtool/argslinked abc 'def ghi' jkl
argv[0] = |...../with-libtool/.libs/argslinked.exe|
argv[1] = |abc|
argv[2] = |def ghi|
argv[3] = |jkl|


Attachment: ltargsbug-fix.diff
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]