#!/usr/bin/perl use Getopt::Long; use File::Temp qw'tempdir'; use File::Basename; use File::Spec; use strict; sub dllname($;$); my $static; my $exclude; GetOptions('static!'=>\$static, 'v|exclude!'=>\$exclude); my $nm = shift; my $ar = shift; my $libdll = File::Spec->rel2abs(shift @ARGV); my $lib = File::Spec->rel2abs(pop @ARGV); open my $nm_fd, '-|', $nm, '-Ap', '--defined-only', @ARGV, $libdll or die "$0: execution of $nm for object files failed - $!\n"; my %match_syms = (); my $symfiles = (); my $lastfn; my %extract = (); while (<$nm_fd>) { study; m%^\Q$libdll\E:([^:]*):\d+ i \.idata\$([56])% and do { next; }; m%^\Q$libdll\E:[^:]*:\d+ I (__head_.*)$% and do { next; }; next unless m%^([^:]*):([^:]*(?=:))?.* [DTI] (.*)%o; if ($1 ne $libdll) { $match_syms{$3} = 1; } elsif ($match_syms{$3} ? !$exclude : $exclude) { $extract{$2} = 1; } } close $nm_fd; %extract or die "$0: couldn't find symbols for $lib\n"; my $dir = tempdir(CLEANUP => 1); chdir $dir; # print join(' ', '+', $ar, 'x', sort keys %extract), "\n"; my $res = system $ar, 'x', $libdll, sort keys %extract; die "$0: $ar extraction exited with non-zero status\n" if $res; unlink $lib; exec $ar, 'crus', $lib, sort keys %extract;