[llvm] [AArch64] Refactor @plt, @gotpcrel, and @AUTH to use parseDataExpr (PR #134202)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 10:54:49 PDT 2025


================
@@ -8086,11 +8106,56 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
   return false;
 }
 
-bool AArch64AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
-  // Try @AUTH expressions: they're more complex than the usual symbol variants.
-  if (!parseAuthExpr(Res, EndLoc))
+bool AArch64AsmParser::parseDataExpr(const MCExpr *&Res) {
+  SMLoc EndLoc;
+
+  if (getParser().parseExpression(Res))
+    return true;
+  MCAsmParser &Parser = getParser();
+  if (!parseOptionalToken(AsmToken::At))
     return false;
-  return getParser().parsePrimaryExpr(Res, EndLoc, nullptr);
+  if (getLexer().getKind() != AsmToken::Identifier)
+    return Error(getLoc(), "expected relocation specifier");
+
+  std::string Identifier = Parser.getTok().getIdentifier().lower();
+  SMLoc Loc = getLoc();
+  Lex();
+  if (Identifier == "auth")
+    return parseAuthExpr(Res, EndLoc);
+
+  auto Spec = MCSymbolRefExpr::VK_None;
+  if (STI->getTargetTriple().isOSBinFormatMachO()) {
+    if (Identifier == "got")
+      Spec = MCSymbolRefExpr::VK_GOT;
+  } else {
+    // Unofficial, experimental syntax that will be changed.
----------------
MaskRay wrote:

For ELF, `@got` and `@gotpcrel` are restricted to `clang -fexperimental-relative-c++-abi-vtables` uses, not used in hand-written assembly files, and not supported by GNU Assembler.

For RISC-V, I made the breaking change by removing the `@got` and `@gotpcrel` syntax support. I hope that we drop the legacy syntax for AArch64 as well.

https://github.com/llvm/llvm-project/pull/134202


More information about the llvm-commits mailing list