summaryrefslogtreecommitdiffstats
path: root/src/build
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2013-06-19 14:30:55 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2013-07-12 09:28:26 -0500
commit3699cdda9adeabf550b3e875b35218620e93f186 (patch)
tree75870ea4a2c604ec6a352e1069ad3710f922e93c /src/build
parentcc3da0a999d8d37cfbb53d8386a6c0b9e3fa3992 (diff)
downloadtalos-hostboot-3699cdda9adeabf550b3e875b35218620e93f186.tar.gz
talos-hostboot-3699cdda9adeabf550b3e875b35218620e93f186.zip
Make libs smaller by overlapping text and rodata sections.
Change-Id: I0f3b9a941c19040635752b2648ef51c50dba849b Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/5135 Tested-by: Jenkins Server Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/build')
-rw-r--r--src/build/linker/linker.C41
-rwxr-xr-xsrc/build/tools/genlist149
-rwxr-xr-xsrc/build/tools/hb11
3 files changed, 113 insertions, 88 deletions
diff --git a/src/build/linker/linker.C b/src/build/linker/linker.C
index 209745af6..1a9a88ba3 100644
--- a/src/build/linker/linker.C
+++ b/src/build/linker/linker.C
@@ -112,6 +112,7 @@ struct Object
string name; //!< full path name of file
bfd* image; //!< bfd image of object
Section text; //!< text section of binary
+ Section rodata; //!< rodata section of binary
Section data; //!< data section of binary
map<string, Symbol> symbols; //!< symbol map
vector<Symbol> relocs; //!< relocations
@@ -181,7 +182,8 @@ struct Object
/**
* CTOR default
*/
- Object() : image(NULL), offset(0), base_addr(0), iv_output(NULL) {}
+ Object() : image(NULL), offset(0), base_addr(0), iv_output(NULL),
+ text(), rodata(), data() {}
/**
* CTOR
@@ -189,7 +191,8 @@ struct Object
* @param[in] i_out : output FILE handle
*/
Object(unsigned long i_baseAddr, FILE* i_out)
- : image(NULL), offset(0), base_addr(i_baseAddr), iv_output(i_out) {}
+ : image(NULL), offset(0), base_addr(i_baseAddr), iv_output(i_out),
+ text(), rodata(), data() {}
};
inline bool Object::isELF()
@@ -500,7 +503,13 @@ bool Object::read_object(const char* i_file)
{
s = &this->text;
}
- if (string(".data") == bfd_get_section_name(image, image_section))
+ else if (string(".rodata") ==
+ bfd_get_section_name(image, image_section))
+ {
+ s = &this->rodata;
+ }
+ else if (string(".data") ==
+ bfd_get_section_name(image, image_section))
{
s = &this->data;
}
@@ -546,6 +555,16 @@ bool Object::write_object()
cout << strerror(error) << endl;
}
+ // Output RODATA section.
+ fseek(iv_output, offset + rodata.vma_offset, SEEK_SET);
+ if ((0 != rodata.size) &&
+ (rodata.size != fwrite(rodata.data, 1, rodata.size, iv_output)))
+ {
+ int error = errno;
+ cout << "Error writing to output for rodata." << endl;
+ cout << strerror(error) << endl;
+ }
+
// Output DATA section.
fseek(iv_output, offset + data.vma_offset, SEEK_SET);
if (data.size != fwrite(data.data, 1, data.size, iv_output))
@@ -707,7 +726,8 @@ bool Object::read_relocation()
s.type = Symbol::UNRESOLVED;
}
- if (loc[i]->howto->name == string("R_PPC64_ADDR64"))
+ if ((loc[i]->howto->name == string("R_PPC64_ADDR64")) ||
+ (loc[i]->howto->name == string("R_PPC64_UADDR64")))
{
s.type |= Symbol::VARIABLE;
}
@@ -719,7 +739,7 @@ bool Object::read_relocation()
cout << "\tSymbol: " << loc[i]->sym_ptr_ptr[0]->name;
cout << "\tAddress: " << std::hex << loc[i]->address << ", "
- << loc[i]->addend << endl;
+ << loc[i]->addend << ", " << loc[i]->howto->name << endl;
}
cleanup:
@@ -754,7 +774,7 @@ bool Object::perform_local_relocations()
fread(data, sizeof(uint64_t), 1, iv_output);
address = bfd_getb64(data);
- if (address != i->addend)
+ if ((address != i->addend) && (address != 0))
{
ostringstream oss;
oss << "Expected " << i->addend << " found " << address
@@ -902,7 +922,7 @@ uint64_t Object::find_init_symbol()
return 0;
return symbols[VFS_TOSTRING(VFS_SYMBOL_INIT)].address +
- offset + base_addr + data.vma_offset;
+ offset + base_addr + rodata.vma_offset;
}
//-----------------------------------------------------------------------------
@@ -913,7 +933,7 @@ uint64_t Object::find_start_symbol()
return 0;
return symbols[VFS_TOSTRING(VFS_SYMBOL_START)].address +
- offset + base_addr + data.vma_offset;
+ offset + base_addr + rodata.vma_offset;
}
//-----------------------------------------------------------------------------
@@ -924,7 +944,7 @@ uint64_t Object::find_fini_symbol()
return 0;
return symbols[VFS_TOSTRING(VFS_SYMBOL_FINI)].address +
- offset + base_addr + data.vma_offset;
+ offset + base_addr + rodata.vma_offset;
}
@@ -991,7 +1011,8 @@ void ModuleTable::write_table(vector<Object> & i_objects)
start_symbol = i->find_start_symbol();
fini_symbol = i->find_fini_symbol();
text_offset = i->text.vma_offset + i->offset + i->base_addr;
- data_offset = i->data.vma_offset + i->offset + i->base_addr;
+ data_offset = (i->data.vma_offset + i->offset + i->base_addr) &
+ (~(0xfff));
module_size = i->data.vma_offset + i->data.size;
module_size = page_align(module_size);
}
diff --git a/src/build/tools/genlist b/src/build/tools/genlist
index a853d096a..f7b501167 100755
--- a/src/build/tools/genlist
+++ b/src/build/tools/genlist
@@ -33,29 +33,29 @@ sub add_image_subdir
sub find_symbol_name
{
- my ($offset, $require_function, $symbol_addrs,
+ my ($offset, $require_function, $symbol_addrs,
$symbol_sorted_addrs, $symbol_funcs) = @_;
if (defined $symbol_addrs->{$offset})
{
- for my $sym (@{$symbol_addrs->{$offset}})
- {
- if ($symbol_funcs->{$sym})
- {
- return $sym;
- }
- }
- if ($require_function)
- {
- return 0;
- }
- return @{$symbol_addrs->{$offset}}[0];
+ for my $sym (@{$symbol_addrs->{$offset}})
+ {
+ if ($symbol_funcs->{$sym})
+ {
+ return $sym;
+ }
+ }
+ if ($require_function)
+ {
+ return 0;
+ }
+ return @{$symbol_addrs->{$offset}}[0];
}
if ($require_function)
{
- return 0;
+ return 0;
}
-
+
my $prevoffset = -1;
my $search_first = 0;
my $search_last = $#$symbol_sorted_addrs;
@@ -86,18 +86,18 @@ sub find_symbol_name
{
$prevoffset = @$symbol_sorted_addrs[$search_first];
}
-
+
if (defined $symbol_addrs->{$prevoffset})
{
- for my $sym (@{$symbol_addrs->{$prevoffset}})
- {
- if ($symbol_funcs->{$sym})
- {
- return sprintf "%s+0x%x", $sym, ($offset - $prevoffset);
- }
- }
- return sprintf "%s+0x%x", @{$symbol_addrs->{$prevoffset}}[0],
- ($offset - $prevoffset);
+ for my $sym (@{$symbol_addrs->{$prevoffset}})
+ {
+ if ($symbol_funcs->{$sym})
+ {
+ return sprintf "%s+0x%x", $sym, ($offset - $prevoffset);
+ }
+ }
+ return sprintf "%s+0x%x", @{$symbol_addrs->{$prevoffset}}[0],
+ ($offset - $prevoffset);
}
return sprintf "Unknown @ 0x%x", $offset;
}
@@ -137,7 +137,7 @@ while (my $modline = <MODINFO>)
$module_offsets{@splitline[0]} = (hex @splitline[1]) + $image_offset;
if ($all_modules)
{
- push @modules, @splitline[0];
+ push @modules, @splitline[0];
}
}
@@ -151,7 +151,7 @@ while (my $line = <GENSYMS>)
{
chomp $line;
my ($is_func,$code_addr,$addr,$function);
-
+
$line =~ m/(.*?),(.*?),(.*?),(.*?),(.*)/;
$is_func = "F" eq $1;
$addr = hex $2;
@@ -159,7 +159,7 @@ while (my $line = <GENSYMS>)
if (not defined $symbol_address{$addr})
{
- $symbol_address{$addr} = ();
+ $symbol_address{$addr} = ();
}
push @{$symbol_address{$addr}}, $function;
$symbol_isfunc{$function} = $is_func;
@@ -181,58 +181,61 @@ foreach my $module (@modules)
my $enabled = 0;
my $sections = 0;
my $PREFIX = $ENV{'CROSS_PREFIX'};
- open OBJDUMP, ("${PREFIX}objdump -DCS ".add_image_subdir($module)."|");
+ open OBJDUMP, ("${PREFIX}objdump -dCS -j .text -j .data -j .rodata ".
+ add_image_subdir($module)."|");
while (my $line = <OBJDUMP>)
{
- if (!$enabled && ($sections >= 2))
- {
- close OBJDUMP;
+ if (!$enabled && ($sections >= 3))
+ {
+ close OBJDUMP;
}
- if (($line =~ m/Disassembly/) && ($line =~ m/Disassembly of section/))
- {
- if (($line =~ m/.text/) || ($line =~ m/.data/))
- {
- $enabled = 1;
+ if (($line =~ m/Disassembly/) && ($line =~ m/Disassembly of section/))
+ {
+ if (($line =~ m/.text/) ||
+ ($line =~ m/.rodata/) ||
+ ($line =~ m/.data/))
+ {
+ $enabled = 1;
$sections = $sections + 1;
- }
- else
- {
- $enabled = 0;
- }
- }
- elsif ($enabled)
- {
- if ($line =~ s/(^[\s]*)([0-9a-f]+)(:)/$1__HEXVALUE__$3/)
- {
- my $value = hex $2;
- my $offset = $value + $module_offsets{$module};
- my $format = sprintf "%x\t%08x", $value, $offset;
- $line =~ s/__HEXVALUE__/$format/;
-
- my $symname = find_symbol_name($offset, 1, \%symbol_address,
+ }
+ else
+ {
+ $enabled = 0;
+ }
+ }
+ elsif ($enabled)
+ {
+ if ($line =~ s/(^[\s]*)([0-9a-f]+)(:)/$1__HEXVALUE__$3/)
+ {
+ my $value = hex $2;
+ my $offset = $value + $module_offsets{$module};
+ my $format = sprintf "%x\t%08x", $value, $offset;
+ $line =~ s/__HEXVALUE__/$format/;
+
+ my $symname = find_symbol_name($offset, 1, \%symbol_address,
\@symbol_sorted_addrs,
- \%symbol_isfunc);
- if ($symname)
- {
- printf "%016x <%s>:\n", $offset, $symname;
- }
-
- if ($line =~ s/(b[a-z]*[+-]*[\s]*(.*,){0,1})([0-9a-f]+)([\s]*<)(.*)(>)/$1__HEXVALUE__$4__FUNCREF__$6/)
- {
- $value = hex $3;
- $offset = $value + $module_offsets{$module};
- $format = sprintf "%x", $offset;
- $line =~ s/__HEXVALUE__/$format/;
-
- my $refname = find_symbol_name($offset, 0,
- \%symbol_address, \@symbol_sorted_addrs,
+ \%symbol_isfunc);
+ if ($symname)
+ {
+ printf "%016x <%s>:\n", $offset, $symname;
+ }
+
+ if ($line =~ s/(b[a-z]*[+-]*[\s]*(.*,){0,1})([0-9a-f]+)([\s]*<)(.*)(>)/$1__HEXVALUE__$4__FUNCREF__$6/)
+ {
+ $value = hex $3;
+ $offset = $value + $module_offsets{$module};
+ $format = sprintf "%x", $offset;
+ $line =~ s/__HEXVALUE__/$format/;
+
+ my $refname = find_symbol_name($offset, 0,
+ \%symbol_address, \@symbol_sorted_addrs,
\%symbol_isfunc);
- $line =~ s/__FUNCREF__/$refname/
- }
- }
- print $line;
- }
+ $line =~ s/__FUNCREF__/$refname/
+ }
+ }
+ print $line;
+ }
}
close OBJDUMP;
print "\n";
diff --git a/src/build/tools/hb b/src/build/tools/hb
index d1b86e705..f5690f990 100755
--- a/src/build/tools/hb
+++ b/src/build/tools/hb
@@ -402,16 +402,17 @@ hb_objsizes()
{
[ -z "${HOSTBOOTROOT}" ] && echo "Missing HOSTBOOTROOT." && exit -1
- echo "Object,Text Size,Data Size"
+ echo "Object,Text Size,RO Data Size,Data Size"
objdump -h ${HOSTBOOTROOT}/img/*.elf ${HOSTBOOTROOT}/img/*.so | \
- grep -e ".elf" -e ".so:" -e ".text " -e ".data " | \
+ grep -e ".elf" -e ".so:" -e ".text " -e ".rodata" -e ".data " | \
sed "s/.so:.*/.so/" | \
sed "s/.elf:.*/.elf/" | \
sed 's/.*\.text *\([0-9a-f]*\).*/,0x\1/' | \
- sed "s/.*\.data *\([0-9a-f]*\).*/,0x\1/" | \
- sed "N ; N ; s/\n//g" | \
- xargs -n1 perl -e 'printf "%s,%d,%d\n", map { 0 == hex $_ ? $_ : hex $_ } split /\,/,shift;' | \
+ sed 's/.*\.rodata *\([0-9a-f]*\).*/,0x\1/' | \
+ sed 's/.*\.data *\([0-9a-f]*\).*/,0x\1/' | \
+ sed "N ; N ; N ; s/\n//g" | \
+ xargs -n1 perl -e 'printf "%s,%d,%d,%d\n", map { 0 == hex $_ ? $_ : hex $_ } split /\,/,shift;' | \
sed "s/.*\///"
}
OpenPOWER on IntegriCloud