# HG changeset patch # User Shinji KONO # Date 1254392932 -32400 # Node ID ceaa00afd72632a748dfecd33c04e00d5731369c # Parent 44c0bce54dcfc7c1ce9bbd173baee3272d6bdc58 add library diff -r 44c0bce54dcf -r ceaa00afd726 bin/cell_fixpic.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/cell_fixpic.pl Thu Oct 01 19:28:52 2009 +0900 @@ -0,0 +1,74 @@ +#!/usr/bin/perl +# +# Author: Shinji KONO +# v.0.1 Sat May 30 04:41:18 JST 2009 +# +# fix spu-gcc assembler soruce for DMA loadable PIC code +# +#$(OVLOBJS): %.o : %.cc +# $(SPECC) $(SPECFLAGS) -c $< -S -o $(<:.cc=.s) +# perl spe/fixpic.pl $(<:.cc=.s) | $(SPECC) $(SPECFLAGS) -x assembler -c -o $@ - + +use strict; + +my %global; +my %local; +my %weak; +my @line; + +# Basically SPU code is PIC. But linked library is in the fixed +# address space. +# +# rewrite relative to absolute for global branch address +# +# Target instruction +# hbrr -> hbra +# br -> bra +# brsl -> brasl +# brnz cannot be global + +# lqr -> li (for global) +# ila global -> a $0,.LC0-.,$1 + +while(<>) { + push(@line,$_); + if(/\.global\s+([^\s]+)/) { + $global{$1} = 1; + } + if(/\.weak\s+([^\s]+)/) { + $weak{$1} = 1; + next; + } + if(/^([^\s]+):/) { + $local{$1} = 1; + } +} + +for(@line) { + if (! /^#/) { + next if (/\.section\s+\.rodata/); + if(/\s(br)\s+([^\s]+)/||/\s(brsl|hbrr)\s+[^\s]+,\s*([^\s]+)/) { + my $name = $2; + if (! defined $local{$name} || defined $weak{$name} ) { + s/hbrr/hbra/ || + s/brsl/brasl/ || + s/br/bra/ ; + } +# } elsif(/\s(lqr)\s+(\$\d+),([^\s]+)/) { +# my $name = $2; +# if (! defined $local{$name} || defined $weak{$name} ) { +# s/lqr/lqd/; +# } +# } elsif(/\s(ila)\s+(\$\d+),([^\s]+)/) { +# my $name = $3; +# if (! defined $local{$name} || defined $weak{$name} ) { +# $_ = $_; +# } else { +# $_ = "\tai\t$2,\$0,$3-.\n"; +# } + } + } + print ; +} + +# end diff -r 44c0bce54dcf -r ceaa00afd726 bin/cell_ovly_table.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/cell_ovly_table.pl Thu Oct 01 19:28:52 2009 +0900 @@ -0,0 +1,142 @@ +#!/usr/bin/perl +# // from readelf -all spu/spe_main +# // [12] .data PROGBITS 00000f20 0011a0 000384 00 WA 0 0 16 +# // 109: 00001260 64 OBJECT GLOBAL DEFAULT 12 _ovly_table + +use strict; + +package ReadElf; + +sub new { bless {} } + +sub readelf { + my ($self,$elf)= @_; + + my $debug = 0; + my $section_header; + my $symbol_table; + my %section; + my %symbol; + + $self->{section} = \%section; + $self->{symbol} = \%symbol; + + open(ELF, "readelf -all $elf |"); + while() { + if(/^Section Headers:/) { $section_header = 1 ; $symbol_table = 0; } + elsif(/^Symbol table/) { $section_header = 0 ; $symbol_table = 1; } + elsif(/^[A-Z]/) { $section_header = 0 ; $symbol_table = 0; } + if ($section_header) { + if (/\[\s*(\d+)\]\s+(\.\w+)\s+(\w+)\s+([\da-f]+)\s+([\da-f]+)\s+([\da-f]+)\s/) { + $section{$2} = {nr=>$1,name=>$2,type=>$3,addr=>$4,offset=>$5,size=>$6}; + } + } + if ($symbol_table) { + if(/^\s+(\d+):\s([\da-f]+)\s+([\da-f]+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+([\w\.\_]+)/) { + $symbol{$8} = {num=>$1,value=>$2,size=>$3,type=>$4,bind=>$5,vis=>$6,ndx=>$7,name=>$8}; + } + } + + } + + + if ($debug) { + print "seciton:\n"; + foreach my $key ( keys %section) { + foreach my $i ( keys %{$section{$key}}) { + print "$i=>$section{$key}->{$i} "; + } + print "\n"; + } + + print "symbol:\n"; + foreach my $key ( keys %symbol) { + foreach my $i ( keys %{$symbol{$key}}) { + print "$i=>$symbol{$key}->{$i} "; + } + print "\n"; + } + } + $self; +} + +sub symbol { + my ($self, $name) = @_; + $self->{symbol}->{$name}; +} + +sub segment { + my ($self, $name) = @_; + $self->{section}->{$name}; +} + + +package Main; + +my $elf = ReadElf->new; + +my $file = shift; +if (! -e $file) { + open(H,">runTask_offset.h"); + for my $header (@ARGV) { + open(HD,"<$header") or die("Can't open $header"); + my $class = $header; + my $entry = 0; + $class =~ s/\.cc//; + while() { + if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) { + print H "#define runTask_${class}_offset 0x$entry\n"; + last; + } + } + } + open(H,">ld.script.ed"); + exit(0); +} + +$elf->readelf($file) ; + +my $base = $elf->segment(".segment0")->{addr}; + +my @ldfiles; +my $ldsegment = ""; + +open(H,">runTask_offset.h"); +print H "#ifndef RUNTASK_OFFSET_H\n"; +print H "#define RUNTASK_OFFSET_H\n"; +for my $header (@ARGV) { + open(HD,"<$header") or die("Can't open $header"); + while() { + if (/SchedDefineDynamicTask\(\s*(\w+)\s*,\s*(\d+)\s*\)/) { + my $class = $1; + my $segment = $2; + my $entry = $elf->symbol("runTask_$class")->{value}; + print H "#define runTask_${class}_offset (0x$entry-0x$base)\n"; + my $ofile = $header; + $ofile =~ s/\.cc/.o/; + push(@ldfiles,$ofile); + $ldsegment .= " .segment$segment { $ofile(.text) }\n"; + last; + } + } +} +print H "#endif\n"; + +my $ld_script = <<"EOFEOF"; +/ \\.text / +/\\\*\(\\.text/ +s/\\\*\(\\.text/\*\( EXCLUDE_FILE(@ldfiles) .text/ +/} =0/ +a + OVERLAY : + { +$ldsegment + } +. +w +EOFEOF + +open(H,">ld.script.ed"); +print H $ld_script; + +# end diff -r 44c0bce54dcf -r ceaa00afd726 lib/ld.script.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/ld.script.orig Thu Oct 01 19:28:52 2009 +0900 @@ -0,0 +1,193 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-spu", "elf32-spu", + "elf32-spu") +OUTPUT_ARCH(spu) +ENTRY(_start) +SEARCH_DIR("/usr/spu/lib"); +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = 0); . = 0; + .interrupt : { KEEP(*(.interrupt)) } + .interp : { *(.interp) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } + .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } + .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } + .rel.data.rel.ro : { *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) } + .rela.data.rel.ro : { *(.rela.data.rel.ro* .rela.gnu.linkonce.d.rel.ro.*) } + .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } + .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } + .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } + .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } + .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } + .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } + .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .text : + { + *(.text .stub .text.* .gnu.linkonce.t.*) + KEEP (*(.text.*personality*)) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(0x80); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got.plt) *(.got) } + .data : + { + *(.data .data.* .gnu.linkonce.d.*) + KEEP (*(.gnu.linkonce.d.*personality*)) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 16 : 1); + } + .toe ALIGN(128) : { *(.toe) } = 0 + . = ALIGN(16); + . = ALIGN(16); + PROVIDE (__stack = 0x3fff0); + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .note.spu_name 0 : { KEEP(*(.note.spu_name)) } + /DISCARD/ : { *(.note.GNU-stack) } +}