summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain HENRY <hsyl20@gmail.com>2015-10-30 19:55:24 +0100
committerBen Gamari <ben@smart-cactus.org>2015-10-30 19:55:34 +0100
commitf78b477bd0ba1f85089c515259c9e3145abd1f7b (patch)
tree6df29427f2028cb7f7d67869cbe0fd5fac1ef7a7
parentaa289d2a1bea3c30719710530c5a4409230f90d4 (diff)
downloadhaskell-f78b477bd0ba1f85089c515259c9e3145abd1f7b.tar.gz
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
-rw-r--r--compiler/main/DriverPipeline.hs36
1 files changed, 27 insertions, 9 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 697353e5c3..60897a3d04 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