[PATCH] D115854: [PowerPC] Support parsing GNU attributes in MC

Qiu Chaofan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 15 23:47:38 PST 2021


qiucf created this revision.
qiucf added reviewers: nemanjai, shchenz, jsji, stefanp, PowerPC, MaskRay.
Herald added subscribers: steven.zhang, kbarton, hiraditya.
qiucf requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

According to GNU as documentation, PowerPC supports two kinds of `.gnu_attribute` tag to represent the vector and float ABI type in the object file. (https://sourceware.org/binutils/docs-2.35/as/GNU-Object-Attributes.html) Some linkers like GNU ld respects the attribute and will prevent objects with conflicting ABIs being linked.

Commit 7aef993 <https://reviews.llvm.org/rG7aef99351ac3ff56a34de91ba5ad3d3d9815fa20> already did the work for generally parse and emit GNU attributes information. This patch is the first step to enable support of the attribute in LLVM PowerPC, enabling it for PowerPC targets, otherwise `llvm-mc` raises error when seeing the attribute section.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115854

Files:
  llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
  llvm/test/MC/PowerPC/gnu-attribute.s


Index: llvm/test/MC/PowerPC/gnu-attribute.s
===================================================================
--- /dev/null
+++ llvm/test/MC/PowerPC/gnu-attribute.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -triple powerpc64-unknown-linux-gnu < %s | FileCheck %s
+# RUN: llvm-mc -triple powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+
+	.text
+add:
+	add 3, 4, 3
+	blr
+	.gnu_attribute 4, 13
+
+# CHECK-LABEL: add:
+# CHECK: .gnu_attribute 4, 13
Index: llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
===================================================================
--- llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -121,6 +121,7 @@
   bool ParseDirectiveMachine(SMLoc L);
   bool ParseDirectiveAbiVersion(SMLoc L);
   bool ParseDirectiveLocalEntry(SMLoc L);
+  bool ParseGNUAttribute(SMLoc L);
 
   bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
                                OperandVector &Operands, MCStreamer &Out,
@@ -1604,6 +1605,8 @@
     ParseDirectiveAbiVersion(DirectiveID.getLoc());
   else if (IDVal == ".localentry")
     ParseDirectiveLocalEntry(DirectiveID.getLoc());
+  else if (IDVal.startswith(".gnu_attribute"))
+    ParseGNUAttribute(DirectiveID.getLoc());
   else
     return true;
   return false;
@@ -1719,7 +1722,16 @@
   return false;
 }
 
+bool PPCAsmParser::ParseGNUAttribute(SMLoc L) {
+  int64_t Tag;
+  int64_t IntegerValue;
+  if (!getParser().parseGNUAttribute(L, Tag, IntegerValue))
+    return false;
+
+  getParser().getStreamer().emitGNUAttribute(Tag, IntegerValue);
 
+  return true;
+}
 
 /// Force static initialization.
 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115854.394759.patch
Type: text/x-patch
Size: 1718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/90c5ef7d/attachment.bin>


More information about the llvm-commits mailing list