Skip to content

Remove old x86 Directives #3948

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

spiessimon
Copy link
Contributor

@spiessimon spiessimon commented Apr 30, 2025

This PR removes the old x86 directives in favor of the new ones. This notably includes using the new logic for printing directives instead of the existing x86 logic for printing directives. The changes that were observed in the emitted assembly code are summarized in PR #3951.

@spiessimon spiessimon force-pushed the new-directives-x86-remove-old-ones branch from 7bf1756 to c73e03b Compare May 8, 2025 12:52
(* TODO: Buffer.length = 0 => set section align *)
let pos = Buffer.length b.buf in
let current = pos mod n in
if current > 0 then
let n = n - current in
if data then
match data with
| Asm_targets.Asm_directives_new.Zero ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just write "Zero" here (and "Nop" below), by virtue of constructor disambiguation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that earlier and it triggers warning 40 (i.e., the disambiguation will stop working if the type is no longer clear from context).

| Indirect_symbol _ -> assert false
| Type (lbl, kind) -> (get_symbol b lbl).sy_type <- Some kind
| Size (lbl, cst) -> (
| Directive (D.Comment _ )-> ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below (re. constructor disambiguation), you can remove the "D." prefixes I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

| C.Unsigned_int n, Sixteen -> buf_int16L b (Numbers.Uint64.to_int64 n)
| C.Unsigned_int n, Thirty_two -> buf_int32L b (Numbers.Uint64.to_int64 n)
| C.Unsigned_int n, Sixty_four -> buf_int64L b (Numbers.Uint64.to_int64 n)
| _, Eight ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should enable warning 4 in this file (see warning directive at the top), then expand these underscores. If that is too much work, at least enable the warning locally for this function, and do the same expansion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've enabled it on the function. Turning it on for the entire file currently leads to 94 warnings (after enabling and fixing it for this function). Do you see another function where you think it would be worth enabling the warning?

&& (not (Char.equal c '"' (* '"' *)))
&& not (Char.equal c '\\')
&& (not (Char.equal c '"'))
(* '"' *) && not (Char.equal c '\\')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. It's in the original code in x86_proc.ml and the code in emitaux.

let last_was_escape = ref false in
for i = 0 to String.length s - 1 do
for i = k to k + n - 1 do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should probably be a bounds check before this loop, so a proper error can be given

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a bounds check for going beyond the end of the string and for passing negative values.

@@ -403,9 +449,12 @@ module Directive = struct
(* masm only *)
| External _ -> assert false
| Reloc { offset; name; expr } ->
bprintf buf "\t.reloc\t%a, %s, %a" Constant.print offset
bprintf buf "\t.reloc\t%a, %s, %a"
(Constant.print ~force_digits:false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a shame these other call sites have become polluted with "force_digits", which is only used in two cases. Maybe have two functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined Constant.print (which will set it to false) and Constant.print_using_decimals (for the special case that sets it to true).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants