[commit: ghc] master: driver: use PROGBITS type for .debug-ghc-link-info section (f78b477)

git at git.haskell.org git at git.haskell.org
Fri Oct 30 19:20:28 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f78b477bd0ba1f85089c515259c9e3145abd1f7b/ghc

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

commit f78b477bd0ba1f85089c515259c9e3145abd1f7b
Author: Sylvain HENRY <hsyl20 at gmail.com>
Date:   Fri Oct 30 19:55:24 2015 +0100

    driver: use PROGBITS type for .debug-ghc-link-info section
    
    Previously the `.debug-ghc-link-info` section was of type `SHT_NOTE` but
    this is not compliant with the ELF specification, which requires that
    `NOTE` sections are in a particular record-based format. We mark this
    section as `PROGBITS` instead, which is defined as implying no
    particular format.
    
    Fixes #11022.
    
    Reviewers: bgamari, austin
    
    Reviewed By: bgamari, austin
    
    Subscribers: thomie, hsyl20
    
    Differential Revision: https://phabricator.haskell.org/D1375
    
    GHC Trac Issues: #11022


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

f78b477bd0ba1f85089c515259c9e3145abd1f7b
 compiler/main/DriverPipeline.hs | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 697353e..60897a3 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -456,6 +456,7 @@ platformSupportsSavingLinkOpts os
   | os == OSSolaris2 = False -- see #5382
   | otherwise        = osElfTarget os
 
+-- See Note [LinkInfo section]
 ghcLinkInfoSectionName :: String
 ghcLinkInfoSectionName = ".debug-ghc-link-info"
    -- if we use the ".debug" prefix, then strip will strip it by default
@@ -1659,9 +1660,11 @@ mkNoteObjsToLinkIntoBinary dflags dep_packages = do
 
   where
     link_opts info = hcat [
+          -- LinkInfo section must be of type "progbits"
+          -- See Note [LinkInfo section]
           text "\t.section ", text ghcLinkInfoSectionName,
                                    text ",\"\",",
-                                   text elfSectionNote,
+                                   text elfSectionProgBits,
                                    text "\n",
 
           text "\t.ascii \"", info', text "\"\n",
@@ -1681,15 +1684,14 @@ mkNoteObjsToLinkIntoBinary dflags dep_packages = do
             escape :: String -> String
             escape = concatMap (charToC.fromIntegral.ord)
 
-            elfSectionNote :: String
-            elfSectionNote = case platformArch (targetPlatform dflags) of
-                               ArchARM _ _ _ -> "%note"
-                               _             -> "@note"
+            elfSectionProgBits :: String
+            elfSectionProgBits = case platformArch (targetPlatform dflags) of
+                                     ArchARM _ _ _ -> "%progbits"
+                                     _             -> "@progbits"
 
--- The "link info" is a string representing the parameters of the
--- link.  We save this information in the binary, and the next time we
--- link, if nothing else has changed, we use the link info stored in
--- the existing binary to decide whether to re-link or not.
+-- | Return the "link info" string
+--
+-- See Note [LinkInfo section]
 getLinkInfo :: DynFlags -> [UnitId] -> IO String
 getLinkInfo dflags dep_packages = do
    package_link_opts <- getPackageLinkOpts dflags dep_packages
@@ -1708,6 +1710,22 @@ getLinkInfo dflags dep_packages = do
    --
    return (show link_info)
 
+
+{- Note [LinkInfo section]
+   ~~~~~~~~~~~~~~~~~~~~~~~
+
+The "link info" is a string representing the parameters of the link. We save
+this information in the binary, and the next time we link, if nothing else has
+changed, we use the link info stored in the existing binary to decide whether
+to re-link or not.
+
+The "link info" string is stored in a ELF section called ".debug-ghc-link-info"
+(see ghcLinkInfoSectionName) with the SHT_PROGBITS type. It used to be of type
+SHT_NOTE without following their specified record-based format (see #11022).
+
+-}
+
+
 -----------------------------------------------------------------------------
 -- Look for the /* GHC_PACKAGES ... */ comment at the top of a .hc file
 



More information about the ghc-commits mailing list