summaryrefslogtreecommitdiff
path: root/symbian/find_writeable_data.pl
blob: bdb579086d4b6fff687fdcf1c174fc66e37bd555 (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
#!/usr/bin/perl -w

#
# find_writeable_data - find non-const data in Symbian object files
#
# Use this when PETRAN tells you "dll has (un)initialised data".
# Expects to find the Symbian (GNU) nm in the executable path.
#
# Copyright (c) 2004-2005 Nokia.  All rights reserved.
#
# This utility is licensed under the same terms as Perl itself.
#

use strict;

BEGIN {
  unless (exists $ENV{EPOCROOT}) {
    die "$0: EPOCROOT unset\n";
  }
  if (open(my $fh, "nm --version |")) {
    unless (<$fh> =~ /^GNU nm .*-psion-.*/) {
      die "$0: Cannot find the GNU nm from Symbian\n";
    }
    close($fh);
  } else {
      die "$0: Cannot find any nm in the executable path: $!\n";
  }
  unless (@ARGV && $ARGV[0] =~ /\.mmp$/i) {
    die "$0: Must specify target mmp as the first argument\n";
  }
}

use Cwd;
use File::Basename;

my $dir = lc(getcwd());
my $tgt = basename(shift(@ARGV), ".mmp");

$dir =~ s!/!\\!g;
$dir =~ s!^c:!c:$ENV{EPOCROOT}epoc32\\build!;
$dir .= "\\$tgt\\thumb\\urel";

print $dir, "\n";

unless (-d $dir) {
  die "$0: No directory $dir\n";
}

my @o = glob("$dir\\*.o");

unless (@o) {
  die "$0: No objects in $dir\n";
}

for my $o (@o) {
  if (open(my $fh, "nm $o |")) {
    my @d;
    while (<$fh>) {
      next if / [TURtr] /;
      push @d, $_;
    }
    close($fh);
    if (@d) {
      $o =~ s!^\Q$dir\E\\!!;
      print "$o:\n";
      print @d;
    }
  } else {
    warn "$0: nm $o failed: $!\n";
  }
} 

exit(0);