https://parisc.wiki.kernel.org/index.php?title=Binutils&feed=atom&action=historyBinutils - Revision history2024-03-28T09:40:20ZRevision history for this page on the wikiMediaWiki 1.19.24https://parisc.wiki.kernel.org/index.php?title=Binutils&diff=6321&oldid=prevThibaut Varene: Import original page2014-06-02T13:35:11Z<p>Import original page</p>
<p><b>New page</b></p><div>= binutils =<br />
<br />
Upstream webpage: http://sources.redhat.com/binutils<br />
<br />
Binutils contains the GNU assembler, linker and binary utilities. For PA-RISC, binutils supports several targets, including <tt>hppa-linux</tt>, <tt>hppa64-linux</tt>, <tt>hppa-netbsd</tt>, <tt>hppa-hpux</tt>, <tt>hppa64-hpux</tt>.<br />
<br />
== BFD ==<br />
A large part of binutils is the "bfd" library. According to the README that comes with bfd:<br />
<br />
<nowiki><br />
BFD is an object file library. It permits applications to use the<br />
same routines to process object files regardless of their format.<br />
<br />
BFD is used by the GNU debugger, assembler, linker, and the binary<br />
utilities.<br />
<br />
The documentation on using BFD is scanty and may be occasionally<br />
incorrect. Pointers to documentation problems, or an entirely<br />
rewritten manual, would be appreciated.<br />
</nowiki><br />
<br />
Sigh...<br />
<br />
The interesting files for this port are:<br />
* bfd/elf-hppa.h<br />
* bfd/elf32-hppa.[ch]<br />
* bfd/elf64-hppa.[ch]<br />
* bfd/libhppa.h<br />
* include/elf/hppa.h<br />
<br />
One of the wishlist TODO items is to merge the 32 and 64-bit implementations into a single file, so that it can be maintained more easily. Currently there is quite a bit of overlap, but also a lot of differences between the two targets.<br />
<br />
=== bfd/elf32.hppa.c ===<br />
Data structures:<br />
<br />
<tt>elf32_hppa_link_hash_table</tt> is derived from <tt>elf_link_hash_table</tt>. It is passed around to most of the linker functions (usually as a parameter called <tt>info</tt>). "Global" data is placed in this structure.<br />
<br />
<tt>elf32_hppa_link_hash_entry</tt> is derived from <tt>elf_link_hash_entry</tt>. One of these are created for each dynamic symbol.<br />
<br />
Embedded in the <tt>elf32_hppa_link_hash_table</tt> is a generic ELF hash table <tt>stub_hash_table</tt>. This is used to hold information about a variety of linker-generated stubs. <br />
<br />
On hppa-linux, the following stub types are used:<br />
* Long branch stub: used when a branch (R_PARISC_PCREL17F or R_PARISC_PCREL22F) cannot reach its destination (non-PIC and PIC versions)<br />
* Import stub: used to call a shared library function. There is one version for calling a sharedlib function from other sharedlib, and another for calling a sharedlib function from an executable.<br />
<br />
Since hppa-linux doesn't support multiple subspaces, we do not need export stubs.<br />
<br />
TODO: put call sequence here<br />
<br />
* `elf32_hppa_link_hash_table_create` - create the link hash table structure<br />
* `elf32_hppa_create_dynamic_sections` - create the .got and .plt sections, and possibly .dynamic<br />
* `elf32_hppa_copy_indirect_symbol`<br />
* `elf32_hppa_check_relocs` - Do some preliminary checks on relocs, if needed allocate space for local GOT/PLT entries, do some checking on TLS references<br />
* `elf32_hppa_gc_mark_hook`<br />
* `elf32_hppa_gc_sweep_hook`<br />
* `elf32_hppa_hide_symbol`<br />
* `elf32_hppa_adjust_dynamic_symbol`<br />
* `elf32_hppa_size_dynamic_sections`<br />
** `allocate_plt_static`<br />
** `allocate_dynrelocs`<br />
** `clobber_millicode_symbols`<br />
** `readonly_dynrelocs`<br />
* `elf32_hppa_setup_section_lists`<br />
* `elf32_hppa_next_input_section`<br />
** `elf32_hppa_size_stubs`<br />
** `group_sections`<br />
** `get_local_syms`<br />
* `elf32_hppa_set_gp`<br />
* `elf32_hppa_build_stubs`<br />
* `elf32_hppa_final_link`<br />
* `elf32_hppa_relocate_section`<br />
** `hppa_record_segment_addr`<br />
** `final_link_relocate`<br />
* `elf32_hppa_finish_dynamic_symbol`<br />
* `elf32_hppa_reloc_type_class`<br />
* `elf32_hppa_finish_dynamic_sections`<br />
* `elf32_hppa_post_process_headers`<br />
* `elf32_hppa_elf_get_symbol_type`<br />
<br />
<br />
<br />
=== bfd/elf64-hppa.c ===<br />
TODO: put call sequence here<br />
<br />
<br />
== Assembler (gas) ==<br />
The interesting files for this port are:<br />
* gas/config/tc-hppa.c<br />
* gas/config/tc-hppa.h<br />
* include/opcode/hppa.h: description of all the insns<br />
* include/elf/hppa.h: ELF constants<br />
<br />
<br />
== Linker (ld) ==<br />
<br />
The gnu linker is an interesting piece of software that uses a weird<br />
combination of templates to generate a working cross linker. I still<br />
don't fully understand all this.<br />
<br />
Files of interest are:<br />
* ld/emultmpl/hppaelf.em<br />
* ld/emulparams/hppaelf.sh<br />
* ld/emulparams/hppalinux.sh<br />
<br />
There a number of other files that might be of interest, including<br />
the elf64 stuff:<br />
* ld/emulparams/elf64hppa.sh<br />
* ld/emulparams/hppa64linux.sh<br />
<br />
TODO: The 64-bit linker doesn't have multiple stub sections. Therefore<br />
the stub might not be able to reach the intended target if the distance<br />
is too large. We need to add multiple stub section support for the 64-bit<br />
linker.<br />
<br />
Should trace the linker function calls in order to determine how <br />
the mechanics work for 32-bit.<br />
<br />
For example, for 32-bit from the ld/emultmpl/hppaelf.em definition<br />
we will call:<br />
<br />
<nowiki><br />
gld${EMULATION_NAME}_finish (void) [ld]<br />
elf32_hppa_size_stubs [bfd]<br />
get_local_syms [bfd]<br />
if we need an export stub<br />
if (stub_entry == NULL)<br />
hppa_add_stub [bfd]<br />
</nowiki><br />
<br />
In hppa_add_stub(...) if the stub_sec is empty,<br />
then we check to see if the stub_sec in the link_sec is<br />
empty, and if both those conditions are met then we use the<br />
generic add_stub_section(...) to create and place a stub in<br />
htab->stub_group[link_sec->id].stub_sec. If there is a stub<br />
section in the link_sec already then it is used as the<br />
section stub section e.g.<br />
htab->stub_group[section->id].stub_sec = stub_sec.<br />
<br />
Here is how the ld code calls into the hppa-specific code for the 32-bit target. Line numbers are from binutils-2.15<br />
<br />
<nowiki><br />
main()<br />
-> [ldmain.c:466] lang_process()<br />
-> [ldlang.c:4160] lang_for_each_statement_worker()<br />
-> [ldlang.c:289] ldlang_open_output()<br />
-> [ldlang.c:1779] open_output()<br />
-> [ldlang.c:1764] elf32_hppa_link_hash_table_create()<br />
-> [ldlang.c:4172] open_input_bfds()<br />
-> [ldlang.c:1888] load_symbols()<br />
-> [ldlang.c:1475] elf_link_add_object_symbols()<br />
-> [elflink.c:2995] _bfd_elf_link_create_dynamic_sections()<br />
-> [elflink.c:237] elf32_hppa_create_dynamic_sections()<br />
-> [elflink.c:4055] elf32_hppa_check_relocs()<br />
-> [ldlang.c:4233] ldemul_before_allocation()<br />
-> [ldemul.c:77] gldhppa_linux_before_allocation()<br />
-> [ehppalinux.c:1073] bfd_elf_size_dynamic_sections()<br />
-> [elflink.c:4981] elf32_hppa_size_dynamic_sections<br />
-> [ldlang.c:4311] ldemul_finish()<br />
-> [ldemul.c:90] gldhppalinux_finish()<br />
-> [ehppalinux.c:295] elf32_hppa_setup_section_lists()<br />
-> [ehppalinux.c:305] lang_for_each_statement_worker()<br />
-> [ldlang.c:294] elf32_hppa_next_input_section()<br />
-> [ehppalinux.c:328] elf32_hppa_set_gp()<br />
-> [ehppalinux.c:337] elf32_hppa_build_stubs()<br />
-> [ldmain.c:475] ldwrite()<br />
-> [ldwrite.c:565] elf32_hppa_final_link()<br />
-> [elf32-hppa.c:3195] bfd_elf_final_link()<br />
-> [elflink.c:7579] elf_link_input_bfd()<br />
-> [elflink.c:6652] elf32_hppa_relocate_section()<br />
-> [elflink.c:7702] bfd_hash_traverse()<br />
-> [hash.c:492] elf_link_output_extsym()<br />
-> [elflink.c:6124] elf32_hppa_finish_dynamic_symbol()<br />
-> [elflink.c:7960] elf32_hppa_finish_dynamic_sections()<br />
-> [elflink.c:7334] _bfd_elf_compute_section_file_positions()<br />
-> [elf.c:3068] elf32_hppa_post_process_headers()<br />
</nowiki><br />
<br />
== Disassembler (objdump) ==<br />
<br />
Objdump is (in part) a disassembler. Interesting files:<br />
* opcodes/hppa-dis.c<br />
* opcodes/libhppa.h<br />
* include/opcode/hppa.h: Shared with gas</div>Thibaut Varene