Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/CmmToLlvm.hs
    ... ... @@ -271,15 +271,23 @@ cmmUsedLlvmGens = do
    271 271
       -- used if we didn't provide these hints. This will generate a
    
    272 272
       -- definition of the form
    
    273 273
       --
    
    274
    -  --   @llvm.used = appending global [42 x i8*] [i8* bitcast <var> to i8*, ...]
    
    274
    +  --   @llvm.compiler.used = appending global [42 x i8*] [i8* bitcast <var> to i8*, ...]
    
    275 275
       --
    
    276 276
       -- Which is the LLVM way of protecting them against getting removed.
    
    277
    +  --
    
    278
    +  -- We used to emit @llvm.used, but it's too strong and results in
    
    279
    +  -- SHF_GNU_RETAIN section flag in the object, which prevents linker
    
    280
    +  -- gc-sections from working properly for LLVM backend (#26770).
    
    281
    +  -- @llvm.compiler.used serves a similar purpose that protects the
    
    282
    +  -- variable from being dropped by llc/opt, but it allows linker
    
    283
    +  -- gc-sections to work. See
    
    284
    +  -- https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable
    
    277 285
       ivars <- getUsedVars
    
    278 286
       let cast x = LMBitc (LMStaticPointer (pVarLift x)) i8Ptr
    
    279 287
           ty     = LMArray (length ivars) i8Ptr
    
    280 288
           usedArray = LMStaticArray (map cast ivars) ty
    
    281 289
           sectName  = Just $ fsLit "llvm.metadata"
    
    282
    -      lmUsedVar = LMGlobalVar (fsLit "llvm.used") ty Appending sectName Nothing Constant
    
    290
    +      lmUsedVar = LMGlobalVar (fsLit "llvm.compiler.used") ty Appending sectName Nothing Constant
    
    283 291
           lmUsed    = LMGlobal lmUsedVar (Just usedArray)
    
    284 292
       if null ivars
    
    285 293
          then return ()
    

  • compiler/GHC/CmmToLlvm/Base.hs
    ... ... @@ -286,7 +286,7 @@ data LlvmEnv = LlvmEnv
    286 286
       , envUniqMeta  :: UniqFM Unique MetaId   -- ^ Global metadata nodes
    
    287 287
       , envFunMap    :: LlvmEnvMap       -- ^ Global functions so far, with type
    
    288 288
       , envAliases   :: UniqSet LMString -- ^ Globals that we had to alias, see [Llvm Forward References]
    
    289
    -  , envUsedVars  :: [LlvmVar]        -- ^ Pointers to be added to llvm.used (see @cmmUsedLlvmGens@)
    
    289
    +  , envUsedVars  :: [LlvmVar]        -- ^ Pointers to be added to llvm.compiler.used (see @cmmUsedLlvmGens@)
    
    290 290
     
    
    291 291
         -- the following get cleared for every function (see @withClearVars@)
    
    292 292
       , envVarMap    :: LlvmEnvMap       -- ^ Local variables so far, with type
    

  • compiler/GHC/Driver/Pipeline/Execute.hs
    ... ... @@ -934,6 +934,14 @@ llvmOptions llvm_config llvm_version dflags =
    934 934
            [("-relocation-model=" ++ rmodel
    
    935 935
             ,"-relocation-model=" ++ rmodel) | not (null rmodel)]
    
    936 936
     
    
    937
    +    -- Both llc/opt need these flags for split sections
    
    938
    +    ++ [ ("--data-sections", "--data-sections")
    
    939
    +       | gopt Opt_SplitSections dflags
    
    940
    +       ]
    
    941
    +    ++ [ ("--function-sections", "--function-sections")
    
    942
    +       | gopt Opt_SplitSections dflags
    
    943
    +       ]
    
    944
    +
    
    937 945
         -- Additional llc flags
    
    938 946
         ++ [("", "-mcpu=" ++ mcpu)   | not (null mcpu)
    
    939 947
                                      , not (any (isInfixOf "-mcpu") (getOpts dflags opt_lc)) ]