This is an archive of the discontinued LLVM Phabricator instance.

[ms] [llvm-ml] Add support for anonymous labels (`@@`, `@B`, `@F`)
ClosedPublic

Authored by epastor on Jun 30 2022, 2:13 PM.

Details

Summary

ml.exe and ml64.exe support the use of anonymous labels, with @B and @F referring to the previous and next anonymous label respectively.

We add similar support to llvm-ml, with the exception that we are unable to emit an error message for an @F expression not followed by a @@ label.

Diff Detail

Event Timeline

epastor created this revision.Jun 30 2022, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 2:13 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
epastor requested review of this revision.Jun 30 2022, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 2:13 PM
rnk added a comment.Jun 30 2022, 2:25 PM

Should these be unnamed labels so they don't appear in the COFF file symbol table? I'm guessing ml64 doesn't produce symbols for these labels, but correct me if I'm wrong.

If that is the case, I suggest:

  • keep the counter
  • store a vector of MCSymbols indexed by label counter
  • use a getOrCreate operation to fill in that vector or read from it to handle support for forward references (@F)
llvm/lib/MC/MCParser/MasmParser.cpp
406

Looks like an unintended change

epastor updated this revision to Diff 442583.Jul 6 2022, 8:02 AM

Switch to the pre-existing anonymous label support. (Missed this in the first attempt!)

epastor marked an inline comment as done.EditedJul 6 2022, 8:04 AM

Should these be unnamed labels so they don't appear in the COFF file symbol table? I'm guessing ml64 doesn't produce symbols for these labels, but correct me if I'm wrong.

If that is the case, I suggest:

  • keep the counter
  • store a vector of MCSymbols indexed by label counter
  • use a getOrCreate operation to fill in that vector or read from it to handle support for forward references (@F)

It turns out we've already got support for directional local labels inside of MCContext; the difference here is that MASM only supports one set of local labels, where GNU-style assembler supports an integer-indexed family of them. I've revised this change to take advantage of the pre-existing support instead!

EDIT: And it looks like these will not be emitted to the symbol table, either.

llvm/lib/MC/MCParser/MasmParser.cpp
406

Removed, thanks.

epastor updated this revision to Diff 442589.Jul 6 2022, 8:09 AM
epastor marked an inline comment as done.

Rebase to HEAD

rnk accepted this revision.Jul 6 2022, 9:22 AM
rnk added a subscriber: ayzhao.

lgtm, thanks!

cc +@ayzhao

llvm/lib/MC/MCParser/MasmParser.cpp
2250

Can IDVal be used directly in place of Label below to simplify?

This revision is now accepted and ready to land.Jul 6 2022, 9:22 AM
epastor updated this revision to Diff 442612.Jul 6 2022, 9:29 AM

Addressing last comment

epastor updated this revision to Diff 442613.Jul 6 2022, 9:31 AM

Small update to comments

epastor marked an inline comment as done.Jul 6 2022, 9:41 AM
epastor updated this revision to Diff 442880.Jul 7 2022, 6:12 AM

Fix collision with tombstone entry, and also remove one more bit of handling for GNU-as-style directional labels

This revision was landed with ongoing or failed builds.Jul 7 2022, 7:29 AM
This revision was automatically updated to reflect the committed changes.