Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mkimport « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70c81048f2699108cd640a684dbed5fde0ad471a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
use strict;
use File::Temp qw'tempdir';
use File::Spec;
use Getopt::Long;
my $dir = tempdir(CLEANUP => 1);

my ($ar, $as, $nm, $objcopy, %replace);
GetOptions('ar=s'=>\$ar, 'as=s'=>\$as,'nm=s'=>\$nm, 'objcopy=s'=>\$objcopy, 'replace=s'=>\%replace);

# Args::
#   1) import lib to create
#   2) input dll
#   3...) extra objects to add

$_ = File::Spec->rel2abs($_) for @ARGV;

my $libdll = shift;
my $inpdll = shift;

open my $nm_fd, '-|', $nm, '-Apg', '--defined-only', $inpdll;
my %text = ();
my %import = ();
my %symfile = ();
while (<$nm_fd>) {
    chomp;
    my ($fn, $type, $sym) = /^$inpdll:(.*?):\S+\s+(\S)\s+(\S+)$/o;
    next unless $fn;
    $text{$fn} = $sym if $type eq 'T';
    $import{$fn} = $sym if $type eq 'I';
    $symfile{$sym} = $fn;
}
close $nm_fd or exit 1;

for my $sym (keys %replace) {
    my $fn;
    my $_sym = '_' . $sym;
    if (!defined($fn = $symfile{$_sym})) {
	$fn = "$sym.o";
	$text{$fn} = $_sym;
    }
    my $imp_sym = '__imp__' . $replace{$sym};
    $import{$fn} = $imp_sym;
}

for my $f (keys %text) {
    my $imp_sym = delete $import{$f};
    my $glob_sym = $text{$f};
    if (!defined $imp_sym) {
	delete $text{$f};
    } elsif ($imp_sym eq '__imp__') {
	$text{$f} = 0;
    } else {
	$text{$f} = 1;
	open my $as_fd, '|-', $as, '-o', "$dir/t-$f", "-";
	print $as_fd <<EOF;
	.text
	.extern	$imp_sym
	.global	$glob_sym
$glob_sym:
	jmp	*$imp_sym
EOF
	close $as_fd or exit 1;
    }
}

chdir $dir or die "$0: couldn't cd to $dir - $!\n";
system $ar, 'x', $inpdll;
exit 1 if $?;

for my $f (keys %text) {
    if (!$text{$f}) {
	unlink $f;
    } else {
	system $objcopy, '-R', '.text', $f and exit 1;
	system $objcopy, '-R', '.bss', '-R', '.data', "t-$f" and exit 1;
    }
}

unlink $libdll;
system $ar, 'crus', $libdll, glob('*.o'), @ARGV;
unlink glob('*.o');
chdir '/tmp';	# Allow $dir directory removal on Windows
exit 1 if $?;