[PATCH] D12423: MCAsmInfo: Allow targets to specify when the .section directive should be omitted

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 08:58:48 PDT 2015


No, what I meant is to include a change to lib/Target/AMDGPU showing
this in use (and a test).

On 8 September 2015 at 11:42, Tom Stellard <thomas.stellard at amd.com> wrote:
> tstellarAMD updated this revision to Diff 34222.
> tstellarAMD added a comment.
>
> Updated commit message to explain usage for AMDGPU backend.  The new commit message looks like this:
>
>   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.
>
>
> http://reviews.llvm.org/D12423
>
> Files:
>   include/llvm/MC/MCAsmInfo.h
>   lib/MC/MCAsmInfo.cpp
>   lib/MC/MCSectionELF.cpp
>
> Index: lib/MC/MCSectionELF.cpp
> ===================================================================
> --- lib/MC/MCSectionELF.cpp
> +++ lib/MC/MCSectionELF.cpp
> @@ -27,12 +27,7 @@
>    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) {
> Index: lib/MC/MCAsmInfo.cpp
> ===================================================================
> --- lib/MC/MCAsmInfo.cpp
> +++ lib/MC/MCAsmInfo.cpp
> @@ -157,3 +157,9 @@
>
>    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: include/llvm/MC/MCAsmInfo.h
> ===================================================================
> --- include/llvm/MC/MCAsmInfo.h
> +++ include/llvm/MC/MCAsmInfo.h
> @@ -414,6 +414,15 @@
>    /// 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;
>    }
>
>


More information about the llvm-commits mailing list