MCAsmInfo: Allow targets to specify when the .section directive should be omitted
authorTom Stellard <thomas.stellard@amd.com>
Fri, 25 Sep 2015 21:41:14 +0000 (21:41 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Fri, 25 Sep 2015 21:41:14 +0000 (21:41 +0000)
Summary:
The default behavior is to omit the .section directive for .text, .data,
and sometimes .bss, but some targets may want to omit this directive for
other sections too.

The AMDGPU backend will uses this to emit a simplified syntax for section
switches.  For example if the section directive is not omitted (current
behavior), section switches to .hsatext will be printed like this:

.section .hsatext,#alloc,#execinstr,#write

This is actually wrong, because .hsatext has some custom STT_* flags,
which MC doesn't know how to print or parse.

If the section directive is omitted (made possible by this commit),
section switches will be printed like this:

.hsatext

The motivation for this patch is to make it possible to emit sections
with custom STT_* flags without having to teach MC about all the target
specific STT_* flags.

Reviewers: rafael, grosbach

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12423

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248618 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
lib/MC/MCAsmInfo.cpp
lib/MC/MCSectionELF.cpp

index 9bb0fa63c523f6a2d693fcad458e8dc264d2c348..384584ef4ef0e06ee984c50951e9a2bdfa0aec6b 100644 (file)
@@ -414,6 +414,15 @@ public:
   /// syntactically correct.
   virtual bool isValidUnquotedName(StringRef Name) const;
 
+  /// Return true if the .section directive should be omitted when
+  /// emitting \p SectionName.  For example:
+  ///
+  /// shouldOmitSectionDirective(".text")
+  ///
+  /// returns false => .section .text,#alloc,#execinstr
+  /// returns true  => .text
+  virtual bool shouldOmitSectionDirective(StringRef SectionName) const;
+
   bool usesSunStyleELFSectionSwitchSyntax() const {
     return SunStyleELFSectionSwitchSyntax;
   }
index 100dc7c3dc60e799dc14b52936dd2dfd8b143d88..36e10b3c6a0738710756ef98d78cc4d2df21e1fd 100644 (file)
@@ -157,3 +157,9 @@ bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
 
   return true;
 }
+
+bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
+  // FIXME: Does .section .bss/.data/.text work everywhere??
+  return SectionName == ".text" || SectionName == ".data" ||
+        (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
+}
index b4448d79a2d5b5925253902ec1c02d3461713f52..92d2b9667c80513d2af238106369f050516d6fb2 100644 (file)
@@ -27,12 +27,7 @@ bool MCSectionELF::ShouldOmitSectionDirective(StringRef Name,
   if (isUnique())
     return false;
 
-  // FIXME: Does .section .bss/.data/.text work everywhere??
-  if (Name == ".text" || Name == ".data" ||
-      (Name == ".bss" && !MAI.usesELFSectionDirectiveForBSS()))
-    return true;
-
-  return false;
+  return MAI.shouldOmitSectionDirective(Name);
 }
 
 static void printName(raw_ostream &OS, StringRef Name) {