[PATCH] D69296: [ARM] Uses "Sun Style" syntax for section switching

Jian Cai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 16:56:33 PDT 2019


jcai19 updated this revision to Diff 226523.
jcai19 added a comment.

Right now once we toggle SunStyleELFSectionSwitchSyntax on an architecture, all the section switching assembly is emitted on sun-style syntax, which is the reason why some test cases fail as they assume the regular syntax. To deal with this issue, I introduced a new variable that would allow the architecture to parse sun-style assembly while not emitting it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69296/new/

https://reviews.llvm.org/D69296

Files:
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
  llvm/test/MC/AsmParser/gas-compl-sun-elf.s


Index: llvm/test/MC/AsmParser/gas-compl-sun-elf.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/gas-compl-sun-elf.s
@@ -0,0 +1,13 @@
+@ RUN: llvm-mc -filetype=obj -triple arm-linux-gnu %s -o - | llvm-readelf --sections | FileCheck %s
+
+@ CHECK: .f1              PROGBITS        00000000 000034 000000 00   A  0   0  1
+.section ".f1", #alloc
+
+@ CHECK: .f2              PROGBITS        00000000 000034 000000 00   W  0   0  1
+.section ".f2", #write
+
+@ CHECK: .f3              PROGBITS        00000000 000034 000000 00   A  0   0  1
+.section ".f3", "a"
+
+@ CHECK: .f4              PROGBITS        00000000 000034 000000 00   W  0   0  1
+.section ".f4", "w"
Index: llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
===================================================================
--- llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
+++ llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
@@ -75,6 +75,10 @@
   UseParensForSymbolVariant = true;
 
   UseIntegratedAssembler = true;
+
+  // The GNU assembler supports Sun style section switching for Arm targets, and
+  // it is used in projects like the Linux kernel.
+  IsCompatibleWithSunStyleELFSectionSwitchSyntax = true;
 }
 
 void ARMELFMCAsmInfo::setUseIntegratedAssembler(bool Value) {
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -528,8 +528,10 @@
     unsigned extraFlags;
 
     if (getLexer().isNot(AsmToken::String)) {
-      if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
-          || getLexer().isNot(AsmToken::Hash))
+      if (!getContext()
+               .getAsmInfo()
+               ->supportsSunStyleELFSectionSwitchSyntax() ||
+          getLexer().isNot(AsmToken::Hash))
         return TokError("expected string in directive");
       extraFlags = parseSunStyleSectionFlags();
     } else {
Index: llvm/include/llvm/MC/MCAsmInfo.h
===================================================================
--- llvm/include/llvm/MC/MCAsmInfo.h
+++ llvm/include/llvm/MC/MCAsmInfo.h
@@ -214,6 +214,12 @@
   const char *TPRel32Directive = nullptr;
   const char *TPRel64Directive = nullptr;
 
+  /// This is true if this target is compatible with "Sun Style" syntax for
+  /// section switching
+  /// ("#alloc,#write" etc) alongside the normal ELF syntax (,"a,w") in
+  /// .section directives.  Defaults to false.
+  bool IsCompatibleWithSunStyleELFSectionSwitchSyntax = false;
+
   /// This is true if this target uses "Sun Style" syntax for section switching
   /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
   /// .section directives.  Defaults to false.
@@ -471,6 +477,11 @@
     return SunStyleELFSectionSwitchSyntax;
   }
 
+  bool supportsSunStyleELFSectionSwitchSyntax() const {
+    return SunStyleELFSectionSwitchSyntax ||
+           IsCompatibleWithSunStyleELFSectionSwitchSyntax;
+  }
+
   bool usesELFSectionDirectiveForBSS() const {
     return UsesELFSectionDirectiveForBSS;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69296.226523.patch
Type: text/x-patch
Size: 3135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191025/a9ff4876/attachment.bin>


More information about the llvm-commits mailing list