@@ -488,6 +488,7 @@ let elf32_linux_x86_file
488
488
~(entry_name :string )
489
489
~(text_frags :(string option, frag) Hashtbl.t )
490
490
~(data_frags :(string option, frag) Hashtbl.t )
491
+ ~(bss_frags :(string option, frag) Hashtbl.t )
491
492
~(rodata_frags :(string option, frag) Hashtbl.t )
492
493
~(required_fixups :(string, fixup) Hashtbl.t )
493
494
~(dwarf :Dwarf.debug_records )
@@ -652,7 +653,7 @@ let elf32_linux_x86_file
652
653
(* let gotpltndx = 8L in *) (* Section index of .got.plt *)
653
654
(* let relapltndx = 9L in *) (* Section index of .rela.plt *)
654
655
let datandx = 10L in (* Section index of .data *)
655
- (* let bssndx = 11L in *) (* Section index of .bss *)
656
+ let bssndx = 11L in (* Section index of .bss *)
656
657
(* let dynamicndx = 12L in *) (* Section index of .dynamic *)
657
658
let shstrtabndx = 13L in (* Section index of .shstrtab *)
658
659
@@ -999,6 +1000,22 @@ let elf32_linux_x86_file
999
1000
(strtab_entry, symtab_entry)
1000
1001
in
1001
1002
1003
+ let bss_sym name st_bind fixup =
1004
+ let name_fixup = new_fixup (" bss symbol name fixup: '" ^ name ^ " '" ) in
1005
+ let strtab_entry = DEF (name_fixup, ZSTRING name) in
1006
+ let symtab_entry =
1007
+ symbol
1008
+ ~string_table_fixup: dynstr_section_fixup
1009
+ ~name_string_fixup: name_fixup
1010
+ ~sym_target_fixup: (Some fixup)
1011
+ ~st_bind
1012
+ ~st_type: STT_OBJECT
1013
+ ~st_shndx: bssndx
1014
+ in
1015
+ incr n_syms;
1016
+ (strtab_entry, symtab_entry)
1017
+ in
1018
+
1002
1019
let rodata_sym name st_bind fixup =
1003
1020
let name_fixup = new_fixup (" rodata symbol name fixup: '" ^ name ^ " '" ) in
1004
1021
let strtab_entry = DEF (name_fixup, ZSTRING name) in
@@ -1220,6 +1237,12 @@ let elf32_linux_x86_file
1220
1237
Hashtbl. fold (frags_of_symbol data_sym STB_GLOBAL ) data_frags ([] ,[] ,[] )
1221
1238
in
1222
1239
1240
+ let (bss_strtab_frags,
1241
+ bss_symtab_frags,
1242
+ bss_body_frags) =
1243
+ Hashtbl. fold (frags_of_symbol bss_sym STB_GLOBAL ) bss_frags ([] ,[] ,[] )
1244
+ in
1245
+
1223
1246
let (_,
1224
1247
require_strtab_frags,
1225
1248
require_symtab_frags,
@@ -1285,7 +1308,8 @@ let elf32_linux_x86_file
1285
1308
global_text_symtab_frags @
1286
1309
local_text_symtab_frags @
1287
1310
rodata_symtab_frags @
1288
- data_symtab_frags))
1311
+ data_symtab_frags @
1312
+ bss_symtab_frags))
1289
1313
in
1290
1314
1291
1315
let dynstr_frags = (null_strtab_frag ::
@@ -1294,6 +1318,7 @@ let elf32_linux_x86_file
1294
1318
local_text_strtab_frags @
1295
1319
rodata_strtab_frags @
1296
1320
data_strtab_frags @
1321
+ bss_strtab_frags @
1297
1322
(Array. to_list dynamic_needed_strtab_frags)))
1298
1323
in
1299
1324
@@ -1319,7 +1344,7 @@ let elf32_linux_x86_file
1319
1344
in
1320
1345
let bss_section =
1321
1346
DEF (bss_section_fixup,
1322
- SEQ [| |] )
1347
+ SEQ ( Array. of_list bss_body_frags) )
1323
1348
in
1324
1349
let dynsym_section =
1325
1350
DEF (dynsym_section_fixup,
@@ -1498,6 +1523,7 @@ let emit_file
1498
1523
let text_frags = Hashtbl. create 4 in
1499
1524
let rodata_frags = Hashtbl. create 4 in
1500
1525
let data_frags = Hashtbl. create 4 in
1526
+ let bss_frags = Hashtbl. create 4 in
1501
1527
let required_fixups = Hashtbl. create 4 in
1502
1528
1503
1529
(*
@@ -1630,13 +1656,15 @@ let emit_file
1630
1656
end
1631
1657
sem.Semant. ctxt_native_required
1632
1658
in
1659
+
1633
1660
let all_frags =
1634
1661
elf32_linux_x86_file
1635
1662
~sess
1636
1663
~crate
1637
1664
~entry_name: " _start"
1638
1665
~text_frags
1639
1666
~data_frags
1667
+ ~bss_frags
1640
1668
~dwarf
1641
1669
~sem
1642
1670
~rodata_frags
0 commit comments