Output ELF .size directives for functions
authorJohan Tibell <johan.tibell@gmail.com>
Tue, 19 Apr 2011 16:04:03 +0000 (18:04 +0200)
committerIan Lynagh <igloo@earth.li>
Fri, 22 Apr 2011 14:27:14 +0000 (15:27 +0100)
This allows tools like Linux's perf events to display symbol names for
CMM primops.

compiler/nativeGen/X86/Ppr.hs

index 5fe78e1..5182f7c 100644 (file)
@@ -56,19 +56,19 @@ pprNatCmmTop (CmmData section dats) =
   pprSectionHeader section $$ vcat (map pprData dats)
 
  -- special case for split markers:
-pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel lbl
+pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel True lbl
 
 pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
   pprSectionHeader Text $$
   (if null info then -- blocks guaranteed not null, so label needed
-       pprLabel lbl
+       pprLabel True lbl
    else
 #if HAVE_SUBSECTIONS_VIA_SYMBOLS
             pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                 <> char ':' $$
 #endif
        vcat (map pprData info) $$
-       pprLabel (entryLblToInfoLbl lbl)
+       pprLabel True (entryLblToInfoLbl lbl)
   ) $$
   vcat (map pprBasicBlock blocks)
      -- above: Even the first block gets a label, because with branch-chain
@@ -87,17 +87,18 @@ pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
                       <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                     else empty
 #endif
+  $$ pprSizeDecl (if null info then lbl else entryLblToInfoLbl lbl)
 
 
 pprBasicBlock :: NatBasicBlock Instr -> Doc
 pprBasicBlock (BasicBlock blockid instrs) =
-  pprLabel (mkAsmTempLabel (getUnique blockid)) $$
+  pprCLabel_asm (mkAsmTempLabel (getUnique blockid)) <> char ':' $$
   vcat (map pprInstr instrs)
 
 
 pprData :: CmmStatic -> Doc
 pprData (CmmAlign bytes)         = pprAlign bytes
-pprData (CmmDataLabel lbl)       = pprLabel lbl
+pprData (CmmDataLabel lbl)       = pprLabel False lbl
 pprData (CmmString str)          = pprASCII str
 
 #if  darwin_TARGET_OS
@@ -115,19 +116,29 @@ pprGloblDecl lbl
                                     (sLit ".globl ")) <>
                 pprCLabel_asm lbl
 
-pprTypeAndSizeDecl :: CLabel -> Doc
+pprTypeDecl :: Bool -> CLabel -> Doc
 #if elf_OBJ_FORMAT
-pprTypeAndSizeDecl lbl
-  | not (externallyVisibleCLabel lbl) = empty
-  | otherwise = ptext (sLit ".type ") <>
-                pprCLabel_asm lbl <> ptext (sLit ", @object")
+pprTypeDecl isCode lbl =
+    ptext (sLit "\t.type ") <> pprCLabel_asm lbl
+    <> ptext (sLit (if isCode then ", @function" else ", @object"))
 #else
-pprTypeAndSizeDecl _
+pprTypeDecl _ _
   = empty
 #endif
 
-pprLabel :: CLabel -> Doc
-pprLabel lbl = pprGloblDecl lbl $$ pprTypeAndSizeDecl lbl $$ (pprCLabel_asm lbl <> char ':')
+-- | Output the ELF .size directive.
+pprSizeDecl :: CLabel -> Doc
+#if elf_OBJ_FORMAT
+pprSizeDecl lbl =
+    ptext (sLit "\t.size") <+> pprCLabel_asm lbl
+    <> ptext (sLit ", .-") <> pprCLabel_asm lbl
+#else
+pprSizeDecl _ = empty
+#endif
+
+pprLabel :: Bool -> CLabel -> Doc
+pprLabel isCode lbl = pprGloblDecl lbl $$ pprTypeDecl isCode lbl
+                      $$ (pprCLabel_asm lbl <> char ':')
 
 
 pprASCII :: [Word8] -> Doc