From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 487 invoked by alias); 9 Feb 2005 20:35:56 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 428 invoked from network); 9 Feb 2005 20:35:46 -0000 Received: from unknown (HELO mail.codesourcery.com) (65.74.133.9) by sourceware.org with SMTP; 9 Feb 2005 20:35:46 -0000 Received: (qmail 26818 invoked from network); 9 Feb 2005 20:35:45 -0000 Received: from localhost (HELO wren.home) (paul@127.0.0.1) by mail.codesourcery.com with SMTP; 9 Feb 2005 20:35:45 -0000 From: Paul Brook Organization: CodeSourcery To: binutils@sources.redhat.com Subject: [patch] SymbianOS Arm executables Date: Wed, 09 Feb 2005 23:38:00 -0000 User-Agent: KMail/1.7.2 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_fQnCCoc/OdeJLYr" Message-Id: <200502092035.43426.paul@codesourcery.com> X-SW-Source: 2005-02/txt/msg00181.txt.bz2 --Boundary-00=_fQnCCoc/OdeJLYr Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1576 arm-*-symbianelf executables are relocatable. This has a few implications: - We need to write out absolute relocations, like we do with shared libraries. - These need to be against a symbols because the RO and RW segments are relocated independently. In most cases we use the section symbol. - Imported data is addressed directly (with absolute relocations). Most of the changes are arm-specific, however I did need to add a new common-code flag to allow creation of the local dynamic symbols. Tested on i686-linux, arm-none-eabi and arm-none-symbianelf. Ok? Paul This depends on a previous patch for correct symbol ordering: http://sourceware.org/ml/binutils/2005-02/msg00169.html 2005-02-09 Paul Brook * elf-bfd.h (struct elf_link_hash_table): Add keep_local_dynsyms. * elf.c (_bfd_elf_link_hash_table_init): Initialize it. * elflink.c (bfd_elf_link_record_dynamic_symbol): Allow creation of local dynamic symbols. (bfd_elf_record_link_assignment): Allow creation of dynamic section symbols in ecxecutables. (_bfd_elf_link_renumber_dynsyms): Ditto. (bfd_elf_final_link): Ditto. * elf32-arm.c (elf32_arm_final_link_relocate): Copy absolute relocations into SymbianOS executables. (elf32_arm_check_relocs): Crate dynamic sections for SymbianOS executables. Copy absolute relocations into SymbianOS executables. (elf32_arm_adjust_dynamic_symbol): Don't create copy relocations in symbian objects. (allocate_dynrelocs): Copy relocations for SymbianOS executables. Output dynamic symbols for symbols defined in linker scripts. --Boundary-00=_fQnCCoc/OdeJLYr Content-Type: text/x-diff; charset="us-ascii"; name="patch.symbian_exec" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.symbian_exec" Content-length: 6314 Index: bfd/elf-bfd.h =================================================================== RCS file: /var/cvsroot/src-cvs/src/bfd/elf-bfd.h,v retrieving revision 1.170 diff -u -p -r1.170 elf-bfd.h --- bfd/elf-bfd.h 31 Jan 2005 22:53:24 -0000 1.170 +++ bfd/elf-bfd.h 9 Feb 2005 02:20:12 -0000 @@ -398,6 +398,10 @@ struct elf_link_hash_table /* A linked list of BFD's loaded in the link. */ struct elf_link_loaded_list *loaded; + + /* True if local symbols should be included in dynamic symbol tables + of executable objects. */ + bfd_boolean keep_local_dynsyms; }; /* Look up an entry in an ELF linker hash table. */ Index: bfd/elf.c =================================================================== RCS file: /var/cvsroot/src-cvs/src/bfd/elf.c,v retrieving revision 1.263 diff -u -p -r1.263 elf.c --- bfd/elf.c 31 Jan 2005 23:13:18 -0000 1.263 +++ bfd/elf.c 9 Feb 2005 02:03:46 -0000 @@ -1493,6 +1493,7 @@ _bfd_elf_link_hash_table_init table->tls_sec = NULL; table->tls_size = 0; table->loaded = NULL; + table->keep_local_dynsyms = FALSE; ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc); table->root.type = bfd_link_elf_hash_table; Index: bfd/elf32-arm.c =================================================================== RCS file: /var/cvsroot/src-cvs/src/bfd/elf32-arm.c,v retrieving revision 1.20 diff -u -p -r1.20 elf32-arm.c --- bfd/elf32-arm.c 31 Jan 2005 17:50:20 -0000 1.20 +++ bfd/elf32-arm.c 9 Feb 2005 02:23:36 -0000 @@ -2352,7 +2352,7 @@ elf32_arm_final_link_relocate (reloc_how /* When generating a shared object, these relocations are copied into the output file to be resolved at run time. */ - if (info->shared + if ((info->shared || globals->symbian_p) && (input_section->flags & SEC_ALLOC) && (r_type != R_ARM_REL32 || !SYMBOL_CALLS_LOCAL (info, h)) @@ -3985,6 +3985,14 @@ elf32_arm_check_relocs (bfd *abfd, struc htab = elf32_arm_hash_table (info); sreloc = NULL; + /* Create dynamic sections for SymbianOS executables so that we can + copy relocations. */ + if (htab->symbian_p && ! htab->root.dynamic_sections_created) + { + if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) + return FALSE; + } + dynobj = elf_hash_table (info)->dynobj; local_got_offsets = elf_local_got_offsets (abfd); @@ -4117,7 +4125,7 @@ elf32_arm_check_relocs (bfd *abfd, struc later (it is never cleared). We account for that possibility below by storing information in the relocs_copied field of the hash table entry. */ - if (info->shared + if ((info->shared || htab->symbian_p) && (sec->flags & SEC_ALLOC) != 0 && ((r_type != R_ARM_PC24 && r_type != R_ARM_PLT32 @@ -4377,7 +4385,9 @@ elf32_arm_adjust_dynamic_symbol (struct asection * s; unsigned int power_of_two; struct elf32_arm_link_hash_entry * eh; + struct elf32_arm_link_hash_table *globals; + globals = elf32_arm_hash_table (info); dynobj = elf_hash_table (info)->dynobj; /* Make sure we know what is going on here. */ @@ -4442,8 +4452,10 @@ elf32_arm_adjust_dynamic_symbol (struct /* If we are creating a shared library, we must presume that the only references to the symbol are via the global offset table. For such cases we need not do anything here; the relocations will - be handled correctly by relocate_section. */ - if (info->shared) + be handled correctly by relocate_section. On SymbianOS executables + can reference data in shared objects directly, so we don't need to + do anything here. */ + if (info->shared || globals->symbian_p) return TRUE; /* We must allocate the symbol in our .dynbss section, which will @@ -4636,13 +4648,23 @@ allocate_dynrelocs (struct elf_link_hash space for pc-relative relocs that have become local due to symbol visibility changes. */ - if (info->shared) + if (info->shared || htab->symbian_p) { /* Discard relocs on undefined weak syms with non-default visibility. */ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT && h->root.type == bfd_link_hash_undefweak) eh->relocs_copied = NULL; + else if (htab->symbian_p && h->dynindx == -1 + && h->root.type == bfd_link_hash_new) + { + /* Output absolute symbols so that we can create relocations + against them. For normal symbols we output a relocation + against the section that contains them. */ + if (! bfd_elf_link_record_dynamic_symbol (info, h)) + return FALSE; + } + } else { @@ -5845,6 +5867,7 @@ elf32_arm_symbian_link_hash_table_create /* The PLT entries are each three instructions. */ htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); htab->symbian_p = 1; + htab->root.keep_local_dynsyms = 1; } return ret; } Index: bfd/elflink.c =================================================================== RCS file: /var/cvsroot/src-cvs/src/bfd/elflink.c,v retrieving revision 1.126 diff -u -p -r1.126 elflink.c --- bfd/elflink.c 1 Feb 2005 01:11:14 -0000 1.126 +++ bfd/elflink.c 9 Feb 2005 02:07:31 -0000 @@ -386,7 +386,8 @@ bfd_elf_link_record_dynamic_symbol (stru && h->root.type != bfd_link_hash_undefweak) { h->forced_local = 1; - return TRUE; + if (!elf_hash_table (info)->keep_local_dynsyms) + return TRUE; } default: @@ -484,6 +485,6 @@ bfd_elf_record_link_assignment (bfd *out if ((h->def_dynamic || h->ref_dynamic - || info->shared) + || info->shared || elf_hash_table (info)->keep_local_dynsyms) && h->dynindx == -1) { if (! bfd_elf_link_record_dynamic_symbol (info, h)) @@ -667,7 +701,7 @@ _bfd_elf_link_renumber_dynsyms { unsigned long dynsymcount = 0; - if (info->shared) + if (info->shared || elf_hash_table (info)->keep_local_dynsyms) { const struct elf_backend_data *bed = get_elf_backend_data (output_bfd); asection *p; @@ -8104,7 +8143,7 @@ bfd_elf_final_link (bfd *abfd, struct bf long last_local = 0; /* Write out the section symbols for the output sections. */ - if (info->shared) + if (info->shared || elf_hash_table (info)->keep_local_dynsyms) { asection *s; --Boundary-00=_fQnCCoc/OdeJLYr--