Skip to content

GHC 9.4.5 places data into .text

I'm trying to build GHC with my linker, mold, and noticed that GHC places data into .text. I built GHC using Hadrian without any special option (I built it just with ./boot && ./configure && ./hadrian/build -j). Please take a look at the following readelf dump.

$ readelf -WSs _build/stage1/rts/build/cmm/StgStdThunks.thr_dyn_o
There are 10 section headers, starting at offset 0x2328:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040 00118b 00  AX  0   0  8
  [ 2] .rela.text        RELA            0000000000000000 001be8 0006f0 18   I  7   1  8
  [ 3] .data             PROGBITS        0000000000000000 0011cb 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          0000000000000000 0011cb 000000 00  WA  0   0  1
  [ 5] .note.GNU-stack   PROGBITS        0000000000000000 0011cb 000000 00      0   0  1
  [ 6] .comment          PROGBITS        0000000000000000 0011cb 000012 01  MS  0   0  1
  [ 7] .symtab           SYMTAB          0000000000000000 0011e0 000570 18      8   1  8
  [ 8] .strtab           STRTAB          0000000000000000 001750 000493 00      0   0  1
  [ 9] .shstrtab         STRTAB          0000000000000000 0022d8 00004a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

Symbol table '.symtab' contains 58 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000010   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_0_upd_info
     2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _GLOBAL_OFFSET_TABLE_
     3: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_upd_frame_info
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_0_fast
     5: 0000000000000088   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_1_upd_info
     6: 0000000000000100   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_2_upd_info
     7: 0000000000000178   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_3_upd_info
     8: 00000000000001f0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_4_upd_info
     9: 0000000000000268   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_5_upd_info
    10: 00000000000002e0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_6_upd_info
    11: 0000000000000358   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_7_upd_info
    12: 00000000000003d0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_8_upd_info
    13: 0000000000000448   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_9_upd_info
    14: 00000000000004c0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_10_upd_info
    15: 0000000000000538   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_11_upd_info
    16: 00000000000005b0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_12_upd_info
    17: 0000000000000628   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_13_upd_info
    18: 00000000000006a0   101 OBJECT  GLOBAL DEFAULT    1 stg_sel_14_upd_info
    19: 0000000000000718   104 OBJECT  GLOBAL DEFAULT    1 stg_sel_15_upd_info
    20: 0000000000000790    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_0_noupd_info
    21: 00000000000007f8    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_1_noupd_info
    22: 0000000000000860    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_2_noupd_info
    23: 00000000000008c8    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_3_noupd_info
    24: 0000000000000930    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_4_noupd_info
    25: 0000000000000998    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_5_noupd_info
    26: 0000000000000a00    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_6_noupd_info
    27: 0000000000000a68    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_7_noupd_info
    28: 0000000000000ad0    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_8_noupd_info
    29: 0000000000000b38    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_9_noupd_info
    30: 0000000000000ba0    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_10_noupd_info
    31: 0000000000000c08    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_11_noupd_info
    32: 0000000000000c70    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_12_noupd_info
    33: 0000000000000cd8    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_13_noupd_info
    34: 0000000000000d40    81 OBJECT  GLOBAL DEFAULT    1 stg_sel_14_noupd_info
    35: 0000000000000da8    84 OBJECT  GLOBAL DEFAULT    1 stg_sel_15_noupd_info
    36: 0000000000000e10    42 OBJECT  GLOBAL DEFAULT    1 stg_ap_1_upd_info
    37: 0000000000000e50    46 OBJECT  GLOBAL DEFAULT    1 stg_ap_2_upd_info
    38: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_p_fast
    39: 0000000000000e90    50 OBJECT  GLOBAL DEFAULT    1 stg_ap_3_upd_info
    40: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_pp_fast
    41: 0000000000000ed8    54 OBJECT  GLOBAL DEFAULT    1 stg_ap_4_upd_info
    42: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_ppp_fast
    43: 0000000000000f20    58 OBJECT  GLOBAL DEFAULT    1 stg_ap_5_upd_info
    44: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_pppp_fast
    45: 0000000000000f70    62 OBJECT  GLOBAL DEFAULT    1 stg_ap_6_upd_info
    46: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_ppppp_fast
    47: 0000000000000fc0    73 OBJECT  GLOBAL DEFAULT    1 stg_ap_7_upd_info
    48: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_ap_pppppp_fast
    49: 0000000000001010    51 FUNC    GLOBAL DEFAULT    1 stg_do_unpack_cstring
    50: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_bh_upd_frame_info
    51: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND ghczmprim_GHCziCString_unpackCStringzh_info
    52: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND stg_gc_prim_pp
    53: 0000000000001058   115 OBJECT  GLOBAL DEFAULT    1 stg_unpack_cstring_info
    54: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND newCAF
    55: 00000000000010d0    51 FUNC    GLOBAL DEFAULT    1 stg_do_unpack_cstring_utf8
    56: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND ghczmprim_GHCziCString_unpackCStringUtf8zh_info
    57: 0000000000001118   115 OBJECT  GLOBAL DEFAULT    1 stg_unpack_cstring_utf8_info

Section 1 is .text, and many symbols starting with stg_ are defined for that section. However, the symbol type of these symbols are not STT_FUNC but STT_OBJECT. If they are functions, they should have had STT_FUNC.

Normally, the linker doesn't care about symbol type, but when it creates copy relocations, the symbol type matters. So setting a correct symbol type is important.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information