458
|
1 #!/usr/bin/perl
|
|
2 # // from readelf -all spu/spe_main
|
|
3 # // [12] .data PROGBITS 00000f20 0011a0 000384 00 WA 0 0 16
|
|
4 # // 109: 00001260 64 OBJECT GLOBAL DEFAULT 12 _ovly_table
|
|
5
|
|
6 use strict;
|
|
7
|
459
|
8 package ReadElf;
|
|
9
|
|
10 sub new { bless {} }
|
|
11
|
|
12 sub readelf {
|
|
13 my ($self,$elf)= @_;
|
|
14
|
|
15 my $debug = 0;
|
|
16 my $section_header;
|
|
17 my $symbol_table;
|
|
18 my %section;
|
|
19 my %symbol;
|
|
20
|
|
21 $self->{section} = \%section;
|
|
22 $self->{symbol} = \%symbol;
|
|
23
|
|
24 open(ELF, "readelf -all $elf |");
|
|
25 while(<ELF>) {
|
|
26 if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; }
|
|
27 elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; }
|
|
28 elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; }
|
|
29 if ($section_header) {
|
|
30 if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) {
|
|
31 $section{$2} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6};
|
|
32 }
|
|
33 }
|
|
34 if ($symbol_table) {
|
|
35 if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) {
|
|
36 $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8};
|
|
37 }
|
|
38 }
|
|
39
|
|
40 }
|
458
|
41
|
|
42
|
459
|
43 if ($debug) {
|
|
44 print "seciton:\n";
|
|
45 foreach my $key ( keys %section) {
|
|
46 foreach my $i ( keys %{$section{$key}}) {
|
|
47 print "$i=>$section{$key}->{$i} ";
|
458
|
48 }
|
459
|
49 print "\n";
|
|
50 }
|
|
51
|
|
52 print "symbol:\n";
|
|
53 foreach my $key ( keys %symbol) {
|
|
54 foreach my $i ( keys %{$symbol{$key}}) {
|
|
55 print "$i=>$symbol{$key}->{$i} ";
|
458
|
56 }
|
459
|
57 print "\n";
|
|
58 }
|
|
59 }
|
|
60 $self;
|
458
|
61 }
|
|
62
|
459
|
63 sub symbol {
|
|
64 my ($self, $name) = @_;
|
|
65 $self->{symbol}->{$name};
|
|
66 }
|
458
|
67
|
459
|
68 sub segment {
|
|
69 my ($self, $name) = @_;
|
|
70 $self->{section}->{$name};
|
458
|
71 }
|
|
72
|
459
|
73
|
|
74 package Main;
|
|
75
|
|
76 my $elf = ReadElf->new;
|
458
|
77
|
459
|
78 my $file = shift;
|
|
79 if (! -e $file) {
|
465
|
80 open(H,">runTask_offset.h");
|
459
|
81 for my $header (@ARGV) {
|
|
82 open(HD,"<$header") or die("Can't open $header");
|
|
83 my $class = $header;
|
|
84 my $entry = 0;
|
|
85 $class =~ s/\.cc//;
|
|
86 while(<HD>) {
|
|
87 if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
|
465
|
88 print H "#define runTask_${class}_offset 0x$entry\n";
|
459
|
89 last;
|
|
90 }
|
|
91 }
|
|
92 }
|
|
93 exit(0);
|
|
94 }
|
458
|
95
|
459
|
96 $elf->readelf($file) ;
|
458
|
97
|
459
|
98 my $base = $elf->segment(".segment0")->{addr};
|
|
99
|
461
|
100 my @ldfiles;
|
|
101 my $ldsegment = "";
|
|
102
|
465
|
103 open(H,">runTask_offset.h");
|
|
104 print H "#ifndef RUNTASK_OFFSET_H\n";
|
|
105 print H "#define RUNTASK_OFFSET_H\n";
|
459
|
106 for my $header (@ARGV) {
|
|
107 open(HD,"<$header") or die("Can't open $header");
|
|
108 while(<HD>) {
|
|
109 if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
|
|
110 my $class = $1;
|
|
111 my $segment = $2;
|
465
|
112 my $entry = $elf->symbol("runTask_$class")->{value};
|
|
113 print H "#define runTask_${class}_offset (0x$entry-0x$base)\n";
|
461
|
114 my $ofile = $header;
|
|
115 $ofile =~ s/\.cc/.o/;
|
|
116 push(@ldfiles,$ofile);
|
|
117 $ldsegment .= " .segment$segment { $ofile(.text) }\n";
|
459
|
118 last;
|
|
119 }
|
|
120 }
|
|
121 }
|
465
|
122 print H "#endif\n";
|
459
|
123
|
461
|
124 my $ld_script = <<"EOFEOF";
|
|
125 / \\.text /
|
|
126 /\\\*\(\\.text/
|
|
127 s/\\\*\(\\.text/\*\( EXCLUDE_FILE(@ldfiles) .text/
|
|
128 /} =0/
|
|
129 a
|
|
130 OVERLAY :
|
|
131 {
|
|
132 $ldsegment
|
|
133 }
|
|
134 .
|
|
135 w
|
|
136 EOFEOF
|
|
137
|
|
138 open(H,">ldscript.ed");
|
|
139 print H $ld_script;
|
|
140
|
459
|
141 # end
|