Skip to content

Commit

Permalink
wrappers: Convert dlltool-wrapper to a native executable
Browse files Browse the repository at this point in the history
This allows running it on windows from processes other than msys
based ones.
  • Loading branch information
mstorsjo committed Jun 14, 2021
1 parent 657d12c commit 459e37f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 36 deletions.
8 changes: 5 additions & 3 deletions install-wrappers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if [ -n "$HOST" ]; then
done
fi
$CC wrappers/clang-target-wrapper.c -o "$PREFIX/bin/clang-target-wrapper$EXEEXT" -O2 -Wl,-s $WRAPPER_FLAGS
$CC wrappers/dlltool-wrapper.c -o "$PREFIX/bin/dlltool-wrapper$EXEEXT" -O2 -Wl,-s $WRAPPER_FLAGS
$CC wrappers/windres-wrapper.c -o "$PREFIX/bin/windres-wrapper$EXEEXT" -O2 -Wl,-s $WRAPPER_FLAGS
$CC wrappers/llvm-wrapper.c -o "$PREFIX/bin/llvm-wrapper$EXEEXT" -O2 -Wl,-s $WRAPPER_FLAGS
if [ -n "$EXEEXT" ]; then
Expand Down Expand Up @@ -100,7 +101,8 @@ for arch in $ARCHS; do
else
ln -sf windres-wrapper$EXEEXT $arch-w64-$target_os-windres$EXEEXT
fi
for exec in ld objdump dlltool; do
ln -sf dlltool-wrapper$EXEEXT $arch-w64-$target_os-dlltool$EXEEXT
for exec in ld objdump; do
ln -sf $exec-wrapper.sh $arch-w64-$target_os-$exec
done
done
Expand All @@ -117,10 +119,10 @@ if [ -n "$EXEEXT" ]; then
# we are installing wrappers for.
case $ARCHS in
*$HOST_ARCH*)
for exec in clang clang++ gcc g++ cc c99 c11 c++ addr2line ar ranlib nm objcopy strings strip windres; do
for exec in clang clang++ gcc g++ cc c99 c11 c++ addr2line ar dlltool ranlib nm objcopy strings strip windres; do
ln -sf $HOST-$exec$EXEEXT $exec$EXEEXT
done
for exec in ld objdump dlltool; do
for exec in ld objdump; do
ln -sf $HOST-$exec $exec
done
;;
Expand Down
68 changes: 68 additions & 0 deletions wrappers/dlltool-wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018 Martin Storsjo
*
* This file is part of llvm-mingw.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "native-wrapper.h"

#ifndef DEFAULT_TARGET
#define DEFAULT_TARGET "x86_64-w64-mingw32"
#endif

int _tmain(int argc, TCHAR* argv[]) {
const TCHAR *dir;
const TCHAR *target;
split_argv(argv[0], &dir, NULL, &target, NULL);
if (!target)
target = _T(DEFAULT_TARGET);
TCHAR *arch = _tcsdup(target);
TCHAR *dash = _tcschr(arch, '-');
if (dash)
*dash = '\0';

int max_arg = argc + 2;
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
exec_argv[arg++] = concat(dir, _T("llvm-dlltool"));

if (!_tcscmp(arch, _T("i686"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("i386");
} else if (!_tcscmp(arch, _T("x86_64"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("i386:x86-64");
} else if (!_tcscmp(arch, _T("armv7"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("arm");
} else if (!_tcscmp(arch, _T("aarch64"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("arm64");
} else {
_ftprintf(stderr, _T("Arch "TS" unsupported\n"), arch);
return 1;
}

for (int i = 1; i < argc; i++)
exec_argv[arg++] = argv[i];

exec_argv[arg] = NULL;
if (arg > max_arg) {
fprintf(stderr, "Too many options added\n");
abort();
}

return run_final(exec_argv[0], exec_argv);
}
33 changes: 0 additions & 33 deletions wrappers/dlltool-wrapper.sh

This file was deleted.

0 comments on commit 459e37f

Please sign in to comment.