Removed debug symbols and fixed .section directive to be appropriate for mach-o

This commit is contained in:
Egor Sheremetov 2024-04-17 04:20:27 +03:00 committed by Roman Venediktov
parent 234c76963b
commit 05983251c1
2 changed files with 28 additions and 28 deletions

View file

@ -291,10 +291,10 @@ void compact_phase (size_t additional_size) {
physically_relocate(&old_heap); physically_relocate(&old_heap);
heap.current = heap.begin + live_size; heap.current = heap.begin + live_size;
// if (munmap(old_heap.begin, old_heap.size) < 0) { if (munmap(old_heap.begin, old_heap.size) < 0) {
// perror("ERROR: compact_phase: munmap failed\n"); perror("ERROR: compact_phase: munmap failed\n");
// exit(1); exit(1);
// } }
} }
size_t compute_locations () { size_t compute_locations () {

View file

@ -709,28 +709,28 @@ let compile cmd env imports code =
"Function name %s is reserved for built-in" f)) "Function name %s is reserved for built-in" f))
in in
let rec stabs_scope scope = let rec stabs_scope scope =
let names = let names = []
List.map (* List.map
(fun (name, index) -> (fun (name, index) ->
Meta Meta
(Printf.sprintf "\t.stabs \"%s:1\",128,0,0,-%d" name (Printf.sprintf "\t.stabs \"%s:1\",128,0,0,-%d" name
(stack_offset index))) (stack_offset index)))
scope.names scope.names *)
in in
names names
@ (if names = [] then [] @ (if names = [] then []
else else
[ [
Meta (* Meta
(Printf.sprintf "\t.stabn 192,0,0,%s-%s" scope.blab f); (Printf.sprintf "\t.stabn 192,0,0,%s-%s" scope.blab f); *)
]) ])
@ (List.flatten @@ List.map stabs_scope scope.subs) @ (List.flatten @@ List.map stabs_scope scope.subs)
@ @
if names = [] then [] if names = [] then []
else else
[ [
Meta (* Meta
(Printf.sprintf "\t.stabn 224,0,0,%s-%s" scope.elab f); (Printf.sprintf "\t.stabn 224,0,0,%s-%s" scope.elab f); *)
] ]
in in
let name = let name =
@ -741,19 +741,19 @@ let compile cmd env imports code =
let has_closure = closure <> [] in let has_closure = closure <> [] in
let env = env#enter f nargs nlocals has_closure in let env = env#enter f nargs nlocals has_closure in
( env, ( env,
[ Meta (Printf.sprintf "\t.type %s, @function" name) ] [ (* Meta (Printf.sprintf "\t.type %s, @function" name) *) ]
@ (if f = "main" then [] @ (if f = "main" then []
else else
[ [
Meta (* Meta
(Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f); (Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f); *)
] ]
@ List.mapi (* @ List.mapi
(fun i a -> (fun i a ->
Meta Meta
(Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a (Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a
((i * 4) + 8))) ((i * 4) + 8)))
args args *)
@ List.flatten @ List.flatten
@@ List.map stabs_scope scopes) @@ List.map stabs_scope scopes)
@ [ Meta "\t.cfi_startproc" ] @ [ Meta "\t.cfi_startproc" ]
@ -842,7 +842,7 @@ let compile cmd env imports code =
Meta Meta
(Printf.sprintf "\t.set\t%s,\t%d" env#allocated_size (Printf.sprintf "\t.set\t%s,\t%d" env#allocated_size
env#allocated); env#allocated);
Meta (Printf.sprintf "\t.size %s, .-%s" name name); (* Meta (Printf.sprintf "\t.size %s, .-%s" name name); *)
] ) ] )
| RET -> | RET ->
let x = env#peek in let x = env#peek in
@ -1261,13 +1261,13 @@ class env prg =
let lab = Printf.sprintf ".L%d" nlabels in let lab = Printf.sprintf ".L%d" nlabels in
( {<nlabels = nlabels + 1; first_line = false>}, ( {<nlabels = nlabels + 1; first_line = false>},
if fname = "main" then if fname = "main" then
[ Meta (Printf.sprintf "\t.stabn 68,0,%d,%s" line lab); Label lab ] [ (* Meta (Printf.sprintf "\t.stabn 68,0,%d,%s" line lab); *) Label lab ]
else else
(if first_line then (if first_line then
[ Meta (Printf.sprintf "\t.stabn 68,0,%d,0" line) ] [ (* Meta (Printf.sprintf "\t.stabn 68,0,%d,0" line) *) ]
else []) else [])
@ [ @ [
Meta (Printf.sprintf "\t.stabn 68,0,%d,%s-%s" line lab fname); (* Meta (Printf.sprintf "\t.stabn 68,0,%d,%s-%s" line lab fname); *)
Label lab; Label lab;
] ) ] )
end end
@ -1288,18 +1288,18 @@ let genasm cmd prog =
env#strings env#strings
@ [ @ [
Meta "_init:\t.quad 0"; Meta "_init:\t.quad 0";
Meta "\t.section custom_data,\"aw\",@progbits"; Meta "\t.section __DATA, custom_data, regular, no_dead_strip";
Meta (Printf.sprintf "filler:\t.fill\t%d, 8, 1" env#max_locals_size); Meta (Printf.sprintf "filler:\t.fill\t%d, 8, 1" env#max_locals_size);
] ]
@ List.concat @ List.concat
@@ List.map @@ List.map
(fun s -> (fun s ->
[ [
Meta (* For mach-o STABS format is not supported: Meta
( Printf.sprintf "\t.stabs \"%s:S1\",40,0,0,%s" ( Printf.sprintf "\t.stabs \"%s:S1\",40,0,0,%s"
(String.sub s (String.length "global_") (String.sub s (String.length "global_")
(String.length s - String.length "global_")) (String.length s - String.length "global_"))
s); s); *)
Meta (Printf.sprintf "%s:\t.quad\t1" s); Meta (Printf.sprintf "%s:\t.quad\t1" s);
]) ])
env#globals env#globals
@ -1309,15 +1309,15 @@ let genasm cmd prog =
(fun i -> Buffer.add_string asm (Printf.sprintf "%s\n" @@ show i)) (fun i -> Buffer.add_string asm (Printf.sprintf "%s\n" @@ show i))
([ ([
Meta (Printf.sprintf "\t.file \"%s\"" cmd#get_absolute_infile); Meta (Printf.sprintf "\t.file \"%s\"" cmd#get_absolute_infile);
Meta (* For mach-o STABS format is not supported: Meta
( Printf.sprintf "\t.stabs \"%s\",100,0,0,.Ltext" ( Printf.sprintf "\t.stabs \"%s\",100,0,0,.Ltext"
cmd#get_absolute_infile); cmd#get_absolute_infile); *)
] ]
@ globals @ data @ globals @ data
@ [ @ [
Meta "\t.text"; Meta "\t.text";
Label ".Ltext"; Label ".Ltext";
Meta "\t.stabs \"data:t1=r1;0;4294967295;\",128,0,0,0"; (* For mach-o STABS format is not supported: Meta "\t.stabs \"data:t1=r1;0;4294967295;\",128,0,0,0"; *)
] ]
@ code); @ code);
Buffer.contents asm Buffer.contents asm