[commit: ghc] ghc-8.0: Remove lookup of sections by name instead use the index numbers as offsets (ca473b7)

git at git.haskell.org git at git.haskell.org
Sat Jan 16 12:48:50 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/ca473b7e0a3761c0259e8c5c49bb2a9a963ff1ed/ghc

>---------------------------------------------------------------

commit ca473b7e0a3761c0259e8c5c49bb2a9a963ff1ed
Author: Tamar Christina <tamar at zhox.com>
Date:   Tue Jan 12 20:34:25 2016 +0100

    Remove lookup of sections by name instead use the index numbers as offsets
    
    Summary:
    This patch comes from @awson
    
    {{{
    Playing with `-fsplit-sections` on Windows I've found a pile of ancient
    (it was borrowed from Hugs interpreter code and I don't even know when
    was it created), absolutely redundant and plain wrong code in RTS linker.
    
    Technically it is a bug, but it doesn't break things when used with
    current Windows binutils with no special linker scripts involved.
    
    OTOH, it slows down runtime linker on Windows noticeably and thus can
    be considered as a performance bug.
    
    The nice side-effect for existing users is that GHCi now loads compiled
    object code much faster on Windows.
    }}}
    
    More specifically, sections were being looked up by name by doing a loop
    over all sections until the section with the given name is found.
    
    The new approach uses the section index and finds the section in O(1) time
    based on information gathered when we originally processed the section
    
    Test Plan: ./validate (was run on GHC x86)
    
    Reviewers: austin, awson, erikd, thomie, bgamari
    
    Reviewed By: thomie, bgamari
    
    Subscribers: awson, #ghc_windows_task_force
    
    Differential Revision: https://phabricator.haskell.org/D1773
    
    GHC Trac Issues: #11388
    
    (cherry picked from commit 49e414a736efe6a5aa221907d9eab9019978e225)


>---------------------------------------------------------------

ca473b7e0a3761c0259e8c5c49bb2a9a963ff1ed
 rts/Linker.c | 64 +-----------------------------------------------------------
 1 file changed, 1 insertion(+), 63 deletions(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 6e20984..1c76a00 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -3232,62 +3232,6 @@ cstring_from_section_name (UChar* name, UChar* strtab)
     }
 }
 
-/* Just compares the short names (first 8 chars) */
-static COFF_section *
-findPEi386SectionCalled ( ObjectCode* oc,  UChar* name, UChar* strtab )
-{
-   int i;
-   rtsBool long_name = rtsFalse;
-   COFF_header* hdr
-      = (COFF_header*)(oc->image);
-   COFF_section* sectab
-      = (COFF_section*) (
-           ((UChar*)(oc->image))
-           + sizeof_COFF_header + hdr->SizeOfOptionalHeader
-        );
-   // String is longer than 8 bytes, swap in the proper
-   // (NULL-terminated) version, and make a note that this
-   // is a long name.
-   if (name[0]==0 && name[1]==0 && name[2]==0 && name[3]==0) {
-      UInt32 strtab_offset = * (UInt32*)(name+4);
-      name = ((UChar*)strtab) + strtab_offset;
-      long_name = rtsTrue;
-   }
-   for (i = 0; i < hdr->NumberOfSections; i++) {
-      UChar* n1;
-      UChar* n2;
-      COFF_section* section_i
-         = (COFF_section*)
-           myindex ( sizeof_COFF_section, sectab, i );
-      n1 = (UChar*) &(section_i->Name);
-      n2 = name;
-      // Long section names are prefixed with a slash, see
-      // also cstring_from_section_name
-      if (n1[0] == '/' && long_name) {
-         // Long name check
-         // We don't really want to make an assumption that the string
-         // table indexes are the same, so we'll do a proper check.
-         int n1_strtab_offset = strtol((char*)n1+1,NULL,10);
-         n1 = (UChar*) (((char*)strtab) + n1_strtab_offset);
-         if (0==strcmp((const char*)n1, (const char*)n2)) {
-            return section_i;
-         }
-      } else if (n1[0] != '/' && !long_name) {
-         // Short name check
-         if (n1[0]==n2[0] && n1[1]==n2[1] && n1[2]==n2[2] &&
-             n1[3]==n2[3] && n1[4]==n2[4] && n1[5]==n2[5] &&
-             n1[6]==n2[6] && n1[7]==n2[7]) {
-            return section_i;
-         }
-      } else {
-         // guaranteed to mismatch, because we never attempt to link
-         // in an executable where the section name may be truncated
-      }
-   }
-
-   return NULL;
-}
-
 /* See Note [mingw-w64 name decoration scheme] */
 #ifndef x86_64_HOST_ARCH
 static void
@@ -3986,13 +3930,7 @@ ocResolve_PEi386 ( ObjectCode* oc )
 
          if (sym->StorageClass == MYIMAGE_SYM_CLASS_STATIC) {
             COFF_section* section_sym
-               = findPEi386SectionCalled ( oc, sym->Name, strtab );
-            if (!section_sym) {
-               errorBelch("%" PATH_FMT ": can't find section named: ", oc->fileName);
-               printName(sym->Name, strtab);
-               errorBelch(" in %s", secname);
-               return 0;
-            }
+              = (COFF_section*) myindex ( sizeof_COFF_section, sectab, sym->SectionNumber-1 );
             S = ((size_t)(oc->image))
               + ((size_t)(section_sym->PointerToRawData))
               + ((size_t)(sym->Value));



More information about the ghc-commits mailing list