Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:56:21+00:00 2026-05-24T02:56:21+00:00

When compiling a haskell source file using the -S option in GHC the assembly

  • 0

When compiling a haskell source file using the -S option in GHC the assembly code generated is not clear. There’s no clear distinction between which parts of the assembly code belong to which parts of the haskell code. Unlike GCC were each label is named according to the function it corresponds to.

Is there a certain convention in these names produced by GHC? How can I relate certain parts in the generated assembly code to their corresponding parts in the haskell code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:56:21+00:00Added an answer on May 24, 2026 at 2:56 am

    For top level declarations, it’s not too hard. Local definitions can be harder to recognize as their names get mangled and they are likely to get inlined.

    Let’s see what happens when we compile this simple module.

    module Example where
    
    add :: Int -> Int -> Int
    add x y = x + y
    
    .data
        .align 8
    .globl Example_add_closure
    .type Example_add_closure, @object
    Example_add_closure:
        .quad   Example_add_info
    .text
        .align 8
        .quad   8589934604
        .quad   0
        .quad   15
    .globl Example_add_info
    .type Example_add_info, @object
    Example_add_info:
    .LckX:
        jmp base_GHCziBase_plusInt_info
    .data
        .align 8
    _module_registered:
        .quad   0
    .text
        .align 8
    .globl __stginit_Example_
    .type __stginit_Example_, @object
    __stginit_Example_:
    .Lcl7:
        cmpq $0,_module_registered
        jne .Lcl8
    .Lcl9:
        movq $1,_module_registered
        addq $-8,%rbp
        movq $__stginit_base_Prelude_,(%rbp)
    .Lcl8:
        addq $8,%rbp
        jmp *-8(%rbp)
    .text
        .align 8
    .globl __stginit_Example
    .type __stginit_Example, @object
    __stginit_Example:
    .Lcld:
        jmp __stginit_Example_
    .section .note.GNU-stack,"",@progbits
    .ident "GHC 7.0.2"
    

    You can see that our function Example.add resulted in the generation of Example_add_closure and Example_add_info. The _closure part, as the name suggests, has to do with closures. The _info part contains the actual instructions of the function. In this case, this is simply a jump to the built-in function GHC.Base.plusInt.

    Note that assembly generated from Haskell code looks quite different from what you might get from other languages. The calling conventions are different, and things can get reordered a lot.

    In most cases you don’t want to jump straight to assembly. It is usually much easier to understand core, a simplified version of Haskell. (Simpler to compile, not necessarily to read). To get at the core, compile with the -ddump-simpl option.

    Example.add :: GHC.Types.Int -> GHC.Types.Int -> GHC.Types.Int
    [GblId, Arity=2]
    Example.add =
      \ (x_abt :: GHC.Types.Int) (y_abu :: GHC.Types.Int) ->
        GHC.Num.+ @ GHC.Types.Int GHC.Num.$fNumInt x_abt y_abu
    

    For some good resources on how to read core, see this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When compiling a haskell source file via ghc --make foo.hs GHC always leaves behind
When compiling code with VC++, MSDN gives you the option between using the x86_amd64
When compiling my Haskell application with the -Wall option, GHC complains about orphaned instances,
While compiling the c++ code using android NDK I am getting the following error:
Compiling a C++ file takes a very long time when compared to C# and
Compiling a file that uses OpenGL with Visual C++, when I try to include
After compiling a simple C++ project using Visual Studio 2008 on vista, everything runs
When compiling the following code: void DoSomething(int Numbers[]) { int SomeArray[] = Numbers; }
I'm compiling a simple .c in visual c++ with Compile as C Code (/TC)
I'm going through Real world Haskell , and got to the example: -- file:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.