sun4.h revision 89858
11558Srgrimes/* SPARC-specific values for a.out files 21558Srgrimes 31558Srgrimes Copyright 2001 Free Software Foundation, Inc. 41558Srgrimes 51558Srgrimes This program is free software; you can redistribute it and/or modify 61558Srgrimes it under the terms of the GNU General Public License as published by 71558Srgrimes the Free Software Foundation; either version 2 of the License, or 81558Srgrimes (at your option) any later version. 91558Srgrimes 101558Srgrimes This program is distributed in the hope that it will be useful, 111558Srgrimes but WITHOUT ANY WARRANTY; without even the implied warranty of 121558Srgrimes MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131558Srgrimes GNU General Public License for more details. 141558Srgrimes 151558Srgrimes You should have received a copy of the GNU General Public License 161558Srgrimes along with this program; if not, write to the Free Software 171558Srgrimes Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 181558Srgrimes 191558Srgrimes/* Some systems, e.g., AIX, may have defined this in header files already 201558Srgrimes included. */ 211558Srgrimes#undef TARGET_PAGE_SIZE 221558Srgrimes#define TARGET_PAGE_SIZE 0x2000 /* 8K. aka NBPG in <sys/param.h> */ 231558Srgrimes/* Note that some SPARCs have 4K pages, some 8K, some others. */ 241558Srgrimes 251558Srgrimes#define SEG_SIZE_SPARC TARGET_PAGE_SIZE 261558Srgrimes#define SEG_SIZE_SUN3 0x20000 /* Resolution of r/w protection hw */ 271558Srgrimes 281558Srgrimes#define TEXT_START_ADDR TARGET_PAGE_SIZE /* Location 0 is not accessible */ 291558Srgrimes#define N_HEADER_IN_TEXT(x) 1 30114589Sobrien 311558Srgrimes/* Non-default definitions of the accessor macros... */ 3237674Scharnier 331558Srgrimes/* Segment size varies on Sun-3 versus Sun-4. */ 341558Srgrimes 351558Srgrimes#define N_SEGSIZE(x) (N_MACHTYPE(x) == M_SPARC? SEG_SIZE_SPARC: \ 361558Srgrimes N_MACHTYPE(x) == M_68020? SEG_SIZE_SUN3: \ 371558Srgrimes /* Guess? */ TARGET_PAGE_SIZE) 381558Srgrimes 39114589Sobrien/* Virtual Address of text segment from the a.out file. For OMAGIC, 4037674Scharnier (almost always "unlinked .o's" these days), should be zero. 41114589Sobrien Sun added a kludge so that shared libraries linked ZMAGIC get 42114589Sobrien an address of zero if a_entry (!!!) is lower than the otherwise 431558Srgrimes expected text address. These kludges have gotta go! 441558Srgrimes For linked files, should reflect reality if we know it. */ 4537674Scharnier 4674525Siedowse/* This differs from the version in aout64.h (which we override by defining 471558Srgrimes it here) only for NMAGIC (we return TEXT_START_ADDR+EXEC_BYTES_SIZE; 4837674Scharnier they return 0). */ 4937674Scharnier 5095485Swes#define N_TXTADDR(x) \ 5137674Scharnier (N_MAGIC(x)==OMAGIC? 0 \ 521558Srgrimes : (N_MAGIC(x) == ZMAGIC && (x).a_entry < TEXT_START_ADDR)? 0 \ 531558Srgrimes : TEXT_START_ADDR+EXEC_BYTES_SIZE) 541558Srgrimes 5578732Sdd/* When a file is linked against a shared library on SunOS 4, the 561558Srgrimes dynamic bit in the exec header is set, and the first symbol in the 5737674Scharnier symbol table is __DYNAMIC. Its value is the address of the 581558Srgrimes following structure. */ 59140795Sdelphij 60140795Sdelphijstruct external_sun4_dynamic 611558Srgrimes{ 621558Srgrimes /* The version number of the structure. SunOS 4.1.x creates files 631558Srgrimes with version number 3, which is what this structure is based on. 641558Srgrimes According to gdb, version 2 is similar. I believe that version 2 6574525Siedowse used a different type of procedure linkage table, and there may 661558Srgrimes have been other differences. */ 67140795Sdelphij bfd_byte ld_version[4]; 68140794Sdelphij /* The virtual address of a 28 byte structure used in debugging. 6974525Siedowse The contents are filled in at run time by ld.so. */ 70140795Sdelphij bfd_byte ldd[4]; 711558Srgrimes /* The virtual address of another structure with information about 722171Sdg how to relocate the executable at run time. */ 731558Srgrimes bfd_byte ld[4]; 741558Srgrimes}; 751558Srgrimes 761558Srgrimes/* The size of the debugging structure pointed to by the debugger 77140794Sdelphij field of __DYNAMIC. */ 7895485Swes#define EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE (24) 791558Srgrimes 8053523Sjdp/* The structure pointed to by the linker field of __DYNAMIC. As far 8153523Sjdp as I can tell, most of the addresses in this structure are offsets 8253523Sjdp within the file, but some are actually virtual addresses. */ 8395485Swes 8495485Swesstruct internal_sun4_dynamic_link 8595485Swes{ 8677122Snik /* Linked list of loaded objects. This is filled in at runtime by 871558Srgrimes ld.so and probably by dlopen. */ 881558Srgrimes unsigned long ld_loaded; 891558Srgrimes 901558Srgrimes /* The address of the list of names of shared objects which must be 911558Srgrimes included at runtime. Each entry in the list is 16 bytes: the 4 921558Srgrimes byte address of the string naming the object (e.g., for -lc this 9317801Sjulian is "c"); 4 bytes of flags--the high bit is whether to search for 9417801Sjulian the object using the library path; the 2 byte major version 95104572Sthomas number; the 2 byte minor version number; the 4 byte address of 9617801Sjulian the next entry in the list (zero if this is the last entry). The 971558Srgrimes version numbers seem to only be non-zero when doing library 981558Srgrimes searching. */ 991558Srgrimes unsigned long ld_need; 1001558Srgrimes 1011558Srgrimes /* The address of the path to search for the shared objects which 1021558Srgrimes must be included. This points to a string in PATH format which 1031558Srgrimes is generated from the -L arguments to the linker. According to 1041558Srgrimes the man page, ld.so implicitly adds ${LD_LIBRARY_PATH} to the 1051558Srgrimes beginning of this string and /lib:/usr/lib:/usr/local/lib to the 1061558Srgrimes end. The string is terminated by a null byte. This field is 10753523Sjdp zero if there is no additional path. */ 10853523Sjdp unsigned long ld_rules; 10926676Scharnier 11026676Scharnier /* The address of the global offset table. This appears to be a 11126676Scharnier virtual address, not a file offset. The first entry in the 11226676Scharnier global offset table seems to be the virtual address of the 1131558Srgrimes sun4_dynamic structure (the same value as the __DYNAMIC symbol). 1141558Srgrimes The global offset table is used for PIC code to hold the 1151558Srgrimes addresses of variables. A dynamically linked file which does not 11626676Scharnier itself contain PIC code has a four byte global offset table. */ 1171558Srgrimes unsigned long ld_got; 1181558Srgrimes 119140794Sdelphij /* The address of the procedure linkage table. This appears to be a 120143948Spjd virtual address, not a file offset. 121143948Spjd 12295485Swes On a SPARC, the table is composed of 12 byte entries, each of 12397428Sgordon which consists of three instructions. The first entry is 12495485Swes sethi %hi(0),%g1 12595485Swes jmp %g1 12695485Swes nop 12795485Swes These instructions are changed by ld.so into a jump directly into 12895485Swes ld.so itself. Each subsequent entry is 12995485Swes save %sp, -96, %sp 13095485Swes call <address of first entry in procedure linkage table> 1311558Srgrimes <reloc_number | 0x01000000> 1321558Srgrimes The reloc_number is the number of the reloc to use to resolve 1331558Srgrimes this entry. The reloc will be a JMP_SLOT reloc against some 1341558Srgrimes symbol that is not defined in this object file but should be 1351558Srgrimes defined in a shared object (if it is not, ld.so will report a 1361558Srgrimes runtime error and exit). The constant 0x010000000 turns the 1371558Srgrimes reloc number into a sethi of %g0, which does nothing since %g0 is 1381558Srgrimes hardwired to zero. 1391558Srgrimes 1401558Srgrimes When one of these entries is executed, it winds up calling into 1411558Srgrimes ld.so. ld.so looks at the reloc number, available via the return 1421558Srgrimes address, to determine which entry this is. It then looks at the 1431558Srgrimes reloc and patches up the entry in the table into a sethi and jmp 1441558Srgrimes to the real address followed by a nop. This means that the reloc 1451558Srgrimes lookup only has to happen once, and it also means that the 1461558Srgrimes relocation only needs to be done if the function is actually 1471558Srgrimes called. The relocation is expensive because ld.so must look up 1481558Srgrimes the symbol by name. 1491558Srgrimes 1501558Srgrimes The size of the procedure linkage table is given by the ld_plt_sz 1511558Srgrimes field. */ 1521558Srgrimes unsigned long ld_plt; 1531558Srgrimes 1541558Srgrimes /* The address of the relocs. These are in the same format as 1551558Srgrimes ordinary relocs. Symbol index numbers refer to the symbols 15626676Scharnier pointed to by ld_stab. I think the only way to determine the 1571558Srgrimes number of relocs is to assume that all the bytes from ld_rel to 1581558Srgrimes ld_hash contain reloc entries. */ 1591558Srgrimes unsigned long ld_rel; 1601558Srgrimes 1611558Srgrimes /* The address of a hash table of symbols. The hash table has 162112991Srwatson roughly the same number of entries as there are dynamic symbols; 16326676Scharnier I think the only way to get the exact size is to assume that 1641558Srgrimes every byte from ld_hash to ld_stab is devoted to the hash table. 1651558Srgrimes 1661558Srgrimes Each entry in the hash table is eight bytes. The first four 1671558Srgrimes bytes are a symbol index into the dynamic symbols. The second 16874525Siedowse four bytes are the index of the next hash table entry in the 16974525Siedowse bucket. The ld_buckets field gives the number of buckets, say B. 17074525Siedowse The first B entries in the hash table each start a bucket which 1711558Srgrimes is chained through the second four bytes of each entry. A value 1721558Srgrimes of zero ends the chain. 17374525Siedowse 17474525Siedowse The hash function is simply 17574525Siedowse h = 0; 17674525Siedowse while (*string != '\0') 17774525Siedowse h = (h << 1) + *string++; 17874525Siedowse h &= 0x7fffffff; 17974525Siedowse 18074525Siedowse To look up a symbol, compute the hash value of the name. Take 1811558Srgrimes the modulos of hash value and the number of buckets. Start at 1821558Srgrimes that entry in the hash table. See if the symbol (from the first 1831558Srgrimes four bytes of the hash table entry) has the name you are looking 1841558Srgrimes for. If not, use the chain field (the second four bytes of the 1851558Srgrimes hash table entry) to move on to the next entry in this bucket. 1861558Srgrimes If the chain field is zero you have reached the end of the 1871558Srgrimes bucket, and the symbol is not in the hash table. */ 1881558Srgrimes unsigned long ld_hash; 1891558Srgrimes 1901558Srgrimes /* The address of the symbol table. This is a list of 1911558Srgrimes external_nlist structures. The string indices are relative to 1921558Srgrimes the ld_symbols field. I think the only way to determine the 1931558Srgrimes number of symbols is to assume that all the bytes between ld_stab 1941558Srgrimes and ld_symbols are external_nlist structures. */ 1951558Srgrimes unsigned long ld_stab; 1961558Srgrimes 1971558Srgrimes /* I don't know what this is for. It seems to always be zero. */ 1981558Srgrimes unsigned long ld_stab_hash; 1991558Srgrimes 2001558Srgrimes /* The number of buckets in the hash table. */ 20126676Scharnier unsigned long ld_buckets; 2021558Srgrimes 2031558Srgrimes /* The address of the symbol string table. The first string in this 2041558Srgrimes string table need not be the empty string. */ 2051558Srgrimes unsigned long ld_symbols; 206140795Sdelphij 2071558Srgrimes /* The size in bytes of the symbol string table. */ 2081558Srgrimes unsigned long ld_symb_size; 209141611Sru 210141611Sru /* The size in bytes of the text segment. */ 2111558Srgrimes unsigned long ld_text; 2121558Srgrimes 21374525Siedowse /* The size in bytes of the procedure linkage table. */ 214140795Sdelphij unsigned long ld_plt_sz; 21574525Siedowse}; 21674525Siedowse 21774525Siedowse/* The external form of the structure. */ 21874525Siedowse 21974525Siedowsestruct external_sun4_dynamic_link 22074525Siedowse{ 22174525Siedowse bfd_byte ld_loaded[4]; 22274525Siedowse bfd_byte ld_need[4]; 22374525Siedowse bfd_byte ld_rules[4]; 22474525Siedowse bfd_byte ld_got[4]; 22574525Siedowse bfd_byte ld_plt[4]; 22674525Siedowse bfd_byte ld_rel[4]; 22774525Siedowse bfd_byte ld_hash[4]; 228 bfd_byte ld_stab[4]; 229 bfd_byte ld_stab_hash[4]; 230 bfd_byte ld_buckets[4]; 231 bfd_byte ld_symbols[4]; 232 bfd_byte ld_symb_size[4]; 233 bfd_byte ld_text[4]; 234 bfd_byte ld_plt_sz[4]; 235}; 236