[llvm] bf60953 - [MC][X86] Allow SHT_PROGBITS for .eh_frame on x86-64

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 10:43:21 PDT 2020


Author: Fangrui Song
Date: 2020-04-16T10:42:52-07:00
New Revision: bf60953faf3a0b80876e7345462d959586250daf

URL: https://github.com/llvm/llvm-project/commit/bf60953faf3a0b80876e7345462d959586250daf
DIFF: https://github.com/llvm/llvm-project/commit/bf60953faf3a0b80876e7345462d959586250daf.diff

LOG: [MC][X86] Allow SHT_PROGBITS for .eh_frame on x86-64

GNU as emits SHT_PROGBITS .eh_frame by default for .cfi_* directives.
We follow x86-64 psABI and use SHT_X86_64_UNWIND for .eh_frame

Don't error for SHT_PROGBITS .eh_frame on x86-64.
This keeps compatibility with `.section .eh_frame,"a", at progbits` in existing assembly files.

See https://groups.google.com/d/msg/x86-64-abi/7sr4E6THl3g/zUU2UPHOAQAJ
for more discussions.

Reviewed By: joerg

Differential Revision: https://reviews.llvm.org/D76151

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/ELFAsmParser.cpp
    llvm/test/MC/ELF/section-type-changed.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 6d8a8a71468c..a80e8a5832ef 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -637,7 +637,11 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
   MCSectionELF *Section = getContext().getELFSection(
       SectionName, Type, Flags, Size, GroupName, UniqueID, LinkedToSym);
   getStreamer().SwitchSection(Section, Subsection);
-  if (Section->getType() != Type)
+  // x86-64 psABI names SHT_X86_64_UNWIND as the canonical type for .eh_frame,
+  // but GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't error
+  // for SHT_PROGBITS .eh_frame
+  if (Section->getType() != Type &&
+      !(SectionName == ".eh_frame" && Type == ELF::SHT_PROGBITS))
     Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getType()));
   if (Section->getFlags() != Flags)

diff  --git a/llvm/test/MC/ELF/section-type-changed.s b/llvm/test/MC/ELF/section-type-changed.s
index cc871462e2db..f8fd092919ed 100644
--- a/llvm/test/MC/ELF/section-type-changed.s
+++ b/llvm/test/MC/ELF/section-type-changed.s
@@ -9,3 +9,11 @@
 .pushsection .foo,"a", at nobits
 
 .pushsection .foo,"a", at progbits
+
+## GNU as emits SHT_PROGBITS .eh_frame for .cfi_* directives. Don't error.
+.section .eh_frame,"a", at progbits
+.section .eh_frame,"a", at unwind
+.pushsection .eh_frame,"a", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section type for .eh_frame, expected: 0x70000001
+.section .eh_frame,"a", at nobits


        


More information about the llvm-commits mailing list