Named sections seem to be breaking after the switch to clang/LLVM. The first test in test/sections.rkt was commented out and crashes at least on Mac systems with an invalid memory error. I found that removing the .p2algin 4 line that gets generated with the section resolves the issue. I don't know why, but simply removing the alignment avoids the memory error.
(check-equal?
(asm-interp
(prog (Text 'foo)
(Global 'entry)
(Label 'entry)
(Mov 'rax 42)
(Ret)))
42)
Which is turned into the following assembly code in Mac:
.intel_syntax noprefix
.text
.section __TEXT,foo
.p2align 4
.global "_entry"
"_entry":
lea rax, [rip + "_d"]
mov rax, [rax]
ret
.section __DATA,bar
.p2align 3
"_d":
.quad 42
Named text sections are only relevant if you want compile lambdas in a single pass (emitting code for the constructor in the default text section and code for the function definition in a named text section). I'm not sure I ever got that working, so it may be that we just want to give up on named sections.
Another note: .p2align aligns to the section base, which may itself not be aligned. That wouldn't cause the error here, but it may be an issue for named sections.
The second test works on Mac, but crashes on Linux with a memory error.
(check-equal?
(asm-interp
(prog (Text 'foo)
(Global 'entry)
(Label 'entry)
(Lea 'rax 'd)
(Mov 'rax (Mem 'rax))
(Ret)
(Data 'bar)
(Label 'd)
(Dq 42)))
42)
which is turned into this code on Linux:
.intel_syntax noprefix
.text
.section foo,"ax",@progbits
.p2align 4
.global "entry"
"entry":
lea rax, [rip + "d"]
mov rax, [rax]
ret
.section bar,"aw",@progbits
.p2align 3
"d":
.quad 42
I don't know what's going wrong here.
I think for the time being we should restore that first test, but then add this to the ignore list while it work it out. I don't think affects anything in langs currently.
Named sections seem to be breaking after the switch to clang/LLVM. The first test in
test/sections.rktwas commented out and crashes at least on Mac systems with an invalid memory error. I found that removing the.p2algin 4line that gets generated with the section resolves the issue. I don't know why, but simply removing the alignment avoids the memory error.Which is turned into the following assembly code in Mac:
Named text sections are only relevant if you want compile lambdas in a single pass (emitting code for the constructor in the default text section and code for the function definition in a named text section). I'm not sure I ever got that working, so it may be that we just want to give up on named sections.
Another note:
.p2alignaligns to the section base, which may itself not be aligned. That wouldn't cause the error here, but it may be an issue for named sections.The second test works on Mac, but crashes on Linux with a memory error.
which is turned into this code on Linux:
I don't know what's going wrong here.
I think for the time being we should restore that first test, but then add this to the ignore list while it work it out. I don't think affects anything in langs currently.