-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ocamlopt generates invalid MASM for C stubs using reserved identifiers #8901
Comments
(PS I'll be very happy to be told that MASM has a simpler way of doing this - I've struggled to find examples of this happening elsewhere) |
Still an issue, I think.
In stead of using the syntax described above, couldn't we just record a
list of MASM-reserved keywords and make sure we do not generate them?
Wouldn't that be simpler?
|
I'd need to page this back in (indeed, I have most if not all of a fix for it somewhere), but IIRC the problem here is user-code generating these symbols |
Still an issue - I just pushed the code I'd started to put together in 2019 to dra27/ocaml. |
I think that the only thing needed for the branch referenced is to lookup and add the complete list of MASM reserved keywords to it |
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
An instance of ocaml#8901
In #8897, @stedolan made the capital offence of naming a C stub function intended to test something
test
. Honestly. The assembler generated for:looks something like:
However, MASM doesn't permit the use of processor instructions (amongst many other things) as symbol names so both lines with
test
will cause assembler errors, and not just any assembler errors - really, really weird ones. After much head bashing, I believe that the only way to accomplish this is to recognise that a reserved symbol is being used (i.e. whenOFFSET
is emitted) and decorate it. So:becomes
then when the External functions section is emitted, prefix it with:
and then the later definition will be fine, since
test
is no longer a reserved word:(before you ask:
OPTION NOKEYWORD
has no reverse and it's not possible to scope it - it was added in order to allow assembler listings to continue using symbol names of CPU instructions added after the listing was written)This can be solved by altering the signature of
add_used_symbol
in the amd64 and i386 emitters to return the symbol name to use; the function itself will then record the correct usage. It shouldn't be necessary to do anything withadd_def_symbol
because all ocamlopt-generated names are already valid MASM identifiers - this is only about dealing with non-ocamlopt generated object files. A few new MASM-specific constructs inX86_masm
and Stephen may then name his functions as logically as he pleases.It's a mildly noisy change to both the emitters, though, so before I make it I'd prefer the concept of the change to be approved. A proof of concept (creating a special-case renaming of
test
to_test
for theOFFSET
instruction only and inserting theOPTION NOKEYWORD
construct fortest
) fixes the original test from #8897.The text was updated successfully, but these errors were encountered: