Asm_directives: new abstraction layer for assembly directive emission#756
Asm_directives: new abstraction layer for assembly directive emission#756mshinwell wants to merge 173 commits intoocaml:trunkfrom
Conversation
|
This patch has been significantly reworked. By removing the non-x86-specific directives from @alainfrisch I believe you have some code that depends on the "directive" type (now I need to do some more tidying up in the x86-64 backend and then make all of the other backends use |
|
(This patch also includes #753 for the moment.) |
|
I've also now tried to tidy up the terminology surrounding "labels" and "symbols". "Labels" are now always of type @alainfrisch Could you possibly check that the |
|
I've only looked very quickly to this PR. It's not completely clear to which extend the notion of "directive" can be made general. Even if there are many similarities in different backends, isn't it inherently tied to the target system and the specific assembly language syntax? Perhaps it is a bit theoretical, but an ocamlopt backend could use a very different directive syntax than gas or masm, so putting concrete syntax emitters in Asm_directives (which is linked for all backends) does not seem right. Similarly, Target_system, in its current form, seems rather specific to Intel backends. The rationale for this big refactoring would be much clearer (to me) if non-Intel backends were ported to the new abstraction layer as well. Otherwise it is hard to know how general this layer will be. As long as it remains used only by Intel backends, I don't see the benefits.
Thanks for thinking about it, and no, indeed, I don't foresee any problem to adapt our code. |
asmcomp/amd64/emit.mlp
Outdated
| let lbl = emit_symbol lbl in | ||
| D.global lbl; | ||
| _label lbl | ||
| D.define_label lbl ~typ:NONE; |
There was a problem hiding this comment.
I don't know if this matters but all instances of _label should be translated to ~typ:QWORD, no?
There was a problem hiding this comment.
I was hoping you were going to tell me the answer to that :)
I don't know exactly what masm uses this parameter for, but could it always be the natural machine width in our case? Maybe we could delete the parameter in our code.
There was a problem hiding this comment.
but could it always be the natural machine width in our case
I'll do some experiments... Stay tuned.
There was a problem hiding this comment.
So, simply generating "foo LABEL DWORD/QWORD" does not work (the assembler complains); at least for labels in code (jump targets), one needs to use "foo:". I've tried using "foo:" in code section and "foo LABEL ?DWORD" in data section, and a good fraction of the testsuite passes, except for some non-deterministic segfaults (perhaps depending on where the image is loaded).
asmcomp/amd64/emit.mlp
Outdated
| _label lbl; | ||
| D.switch_to_section Jump_tables; | ||
| D.align ~bytes:4; | ||
| D.define_label lbl ~typ:NONE; |
asmcomp/amd64/emit.mlp
Outdated
| List.iter emit_call_gc !call_gc_sites; | ||
| emit_call_bound_errors (); | ||
| let end_of_function_label = Cmm.new_label () in | ||
| D.define_label end_of_function_label ~typ:NONE; |
There was a problem hiding this comment.
What's the use of this new label?
There was a problem hiding this comment.
This is needed for DWARF emission, it shouldn't be in this patch.
asmcomp/amd64/emit.mlp
Outdated
| efa_string = (fun s -> D.bytes (s ^ "\000")) | ||
| D.between_this_and_label_offset_32bit ~upper:lbl | ||
| ~offset_upper:(Targetint.of_int32 ofs)); | ||
| efa_def_label = (fun l -> D.define_label l ~typ:NONE); |
There was a problem hiding this comment.
Same remark (_label -> ~typ:QWORD).
|
Keeping the two kinds of NewLabel looks confusing. Previously, the "typ" could only be NONE/DWORD/QWORD (and it is only used for the masm syntax). Couldn't this info be kept in the common layer (so as to get rid of the NewLabel in the intel-specific part)? |
|
Thanks for looking at this. I don't really see the problem with having the concrete syntax emitters in Asm_directives; it seems fairly unlikely that we're going to be targeting a platform in the near future that doesn't use gas, gas-like syntax or masm. This layer is actually used by all platforms for the DWARF emitters. I agree that we should port the other backends to use it throughout, but that can be done as a separate piece of work. |
|
I tried to review and failed because this huge collection of semi-related changes defies reviewing. A first step would be for @mshinwell to write down a high-level description of what's in this PR, which goes way beyond than factoring out the concrete syntax of directives, but also includes a bunch of other refactorings, new uses of the I also noticed abstractions that are not (abstractions). For example the The game is not to have the smallest possible emitters for each target. The game is to enforce a modular structure where code emitters hide target-related details from the rest of the system. Examples of such details that (I think) this PR leaks outside the emitters are 1- the need to |
|
Some of the changes can probably now be pulled out into separate pull requests which will make things easier. I shall try to do this for the One point on the other comments: things such as the need for |
|
I'm not yet asking for separate PRs. As a first step I'd like to see an up to date and comprehensive description of what's in this PR. |
|
I think I'm going to do separate PRs for some of this anyway, since thinking about some of the changes in isolation has already raised a few issues, which will need thinking about. As for the whole, this contains:
The extended use of The @lpw25 will have in his forthcoming namespaces proposal an effectively analogous set of renamings in the front-end of the compiler (instead of Merging some of these changes together would save a reasonable amount of work, which is why they were done together in the first place---in particular the change to use the new |
|
One further comment: the use of |
|
I would definitely like to see this merged. Right now it is not possible to debug OCaml native code, which is annoying. Bytecode works but
|
|
I want to echo similar sentiment as @DemiMarie. Debugging native code in ocaml is very painful right now. Having to use a crude mixture of printf/format is very time-consuming. A good debugger would also be very useful when you are trying to understand a large ocaml codebase. Would definitely like to see the debugging GPRs merged. |
|
Work is underway to split this pull request into pieces that are easier to review. Watch this space. |
|
This GPR is going to be superceded. |
25188da flambda-backend: Missed comment from PR802 (ocaml#887) 9469765 flambda-backend: Improve the semantics of asynchronous exceptions (new simpler version) (ocaml#802) d9e4dd0 flambda-backend: Fix `make runtest` on NixOS (ocaml#874) 4bbde7a flambda-backend: Simpler symbols (ocaml#753) ef37262 flambda-backend: Add opaqueness to Obj.magic under Flambda 2 (ocaml#862) a9616e9 flambda-backend: Add build system hooks for ocaml-jst (ocaml#869) 045ef67 flambda-backend: Allow the compiler to build with stock Dune (ocaml#868) 3cac5be flambda-backend: Simplify Makefile logic for natdynlinkops (ocaml#866) c5b12bf flambda-backend: Remove unnecessary install lines (ocaml#860) ff12bbe flambda-backend: Fix unused variable warning in st_stubs.c (ocaml#861) c84976c flambda-backend: Static check for noalloc: attributes (ocaml#825) ca56052 flambda-backend: Build system refactoring for ocaml-jst (ocaml#857) 39eb7f9 flambda-backend: Remove integer comparison involving nonconstant polymorphic variants (ocaml#854) c102688 flambda-backend: Fix soundness bug by using currying information from typing (ocaml#850) 6a96b61 flambda-backend: Add a primitive to enable/disable the tick thread (ocaml#852) f64370b flambda-backend: Make Obj.dup use a new primitive, %obj_dup (ocaml#843) 9b78eb2 flambda-backend: Add test for ocaml#820 (include functor soundness bug) (ocaml#841) 8f24346 flambda-backend: Add `-dtimings-precision` flag (ocaml#833) 65c2f22 flambda-backend: Add test for ocaml#829 (ocaml#831) 7b27a49 flambda-backend: Follow-up PR#829 (comballoc fixes for locals) (ocaml#830) ad7ec10 flambda-backend: Use a custom condition variable implementation (ocaml#787) 3ee650c flambda-backend: Fix soundness bug in include functor (ocaml#820) 2f57378 flambda-backend: Static check noalloc (ocaml#778) aaad625 flambda-backend: Emit begin/end region only when stack allocation is enabled (ocaml#812) 17c7173 flambda-backend: Fix .cmt for included signatures (ocaml#803) e119669 flambda-backend: Increase delays in tests/lib-threads/beat.ml (ocaml#800) ccc356d flambda-backend: Prevent dynamic loading of the same .cmxs twice in private mode, etc. (ocaml#784) 14eb572 flambda-backend: Make local extension point equivalent to local_ expression (ocaml#790) 487d11b flambda-backend: Fix tast_iterator and tast_mapper for include functor. (ocaml#795) a50a818 flambda-backend: Reduce closure allocation in List (ocaml#792) 96c9c60 flambda-backend: Merge ocaml-jst a775b88 flambda-backend: Fix ocaml/otherlibs/unix 32-bit build (ocaml#767) f7c2679 flambda-backend: Create object files internally to avoid invoking GAS (ocaml#757) c7a46bb flambda-backend: Bugfix for Cmmgen.expr_size with locals (ocaml#756) b337cb6 flambda-backend: Fix build_upstream for PR749 (ocaml#750) 8e7e81c flambda-backend: Differentiate is_int primitive between generic and variant-only versions (ocaml#749) git-subtree-dir: ocaml git-subtree-split: 25188da
Emission of DWARF debugging information necessitates support for various kinds of assembly directives, some of which are quite tricky with regard to their types (mainly widths of various integers, some of which may depend on the target machine, and some of which may not). This new abstraction layer provides a uniform interface for the emission of assembly directives.
This is currently sufficient for testing the debugging support on x86, but is not sufficient for merging. I think pieces missing at present are:
Asm_directivesimplementation for backends where there is no "assembly DSL" (i.e. everything except x86) -- there is some commented-out code from an old version of this, but it needs mostly rewriting and checking thoroughly against the currentasm_directives.mliinterface which has extensively changed since that old code was written;amd64/emit.mlp;Asm_directives_...implementation.This pull request has #755 as a prerequisite.
If anyone would like to volunteer to help bring this pull request up to scratch, it would be much appreciated. If not then I will get to it in due course. There are unfortunately some tricky, assembler-dependent details.