471
|
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
|
|
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 }
|
|
41
|
|
42
|
|
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} ";
|
|
48 }
|
|
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} ";
|
|
56 }
|
|
57 print "\n";
|
|
58 }
|
|
59 }
|
|
60 $self;
|
|
61 }
|
|
62
|
|
63 sub symbol {
|
|
64 my ($self, $name) = @_;
|
|
65 $self->{symbol}->{$name};
|
|
66 }
|
|
67
|
|
68 sub segment {
|
|
69 my ($self, $name) = @_;
|
|
70 $self->{section}->{$name};
|
|
71 }
|
|
72
|
|
73
|
|
74 package Main;
|
|
75
|
|
76 my $elf = ReadElf->new;
|
|
77
|
|
78 my $file = shift;
|
|
79 if (! -e $file) {
|
|
80 open(H,">runTask_offset.h");
|
|
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*\)/) {
|
|
88 print H "#define runTask_${class}_offset 0x$entry\n";
|
|
89 last;
|
|
90 }
|
|
91 }
|
|
92 }
|
|
93 open(H,">ld.script.ed");
|
|
94 exit(0);
|
|
95 }
|
|
96
|
|
97 $elf->readelf($file) ;
|
|
98
|
|
99 my $base = $elf->segment(".segment0")->{addr};
|
|
100
|
|
101 my @ldfiles;
|
|
102 my $ldsegment = "";
|
|
103
|
|
104 open(H,">runTask_offset.h");
|
|
105 print H "#ifndef RUNTASK_OFFSET_H\n";
|
|
106 print H "#define RUNTASK_OFFSET_H\n";
|
|
107 for my $header (@ARGV) {
|
|
108 open(HD,"<$header") or die("Can't open $header");
|
|
109 while(<HD>) {
|
|
110 if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) {
|
|
111 my $class = $1;
|
|
112 my $segment = $2;
|
|
113 my $entry = $elf->symbol("runTask_$class")->{value};
|
|
114 print H "#define runTask_${class}_offset (0x$entry-0x$base)\n";
|
|
115 my $ofile = $header;
|
|
116 $ofile =~ s/\.cc/.o/;
|
|
117 push(@ldfiles,$ofile);
|
|
118 $ldsegment .= " .segment$segment { $ofile(.text) }\n";
|
|
119 last;
|
|
120 }
|
|
121 }
|
|
122 }
|
|
123 print H "#endif\n";
|
|
124
|
|
125 my $ld_script = <<"EOFEOF";
|
|
126 / \\.text /
|
|
127 /\\\*\(\\.text/
|
|
128 s/\\\*\(\\.text/\*\( EXCLUDE_FILE(@ldfiles) .text/
|
|
129 /} =0/
|
|
130 a
|
|
131 OVERLAY :
|
|
132 {
|
|
133 $ldsegment
|
|
134 }
|
|
135 .
|
|
136 w
|
|
137 EOFEOF
|
|
138
|
|
139 open(H,">ld.script.ed");
|
|
140 print H $ld_script;
|
|
141
|
|
142 # end
|