[llvm-branch-commits] [llvm] 5932c00 - [MC][ELF] Fix accepting abbreviated form with Type change

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 14 17:33:54 PST 2021


Author: Tobias Burnus
Date: 2021-12-14T17:32:35-08:00
New Revision: 5932c004778cf251302db0d46d1dfb247325ed3f

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

LOG: [MC][ELF] Fix accepting abbreviated form with Type change

Follow up to D92052 and D94072, exposed due to D107707

Many assemblers to permit that only the first .section contains all
the attributes like '.lds_bss,"w", at nobits' and later section only
use the name ('.lds_bss') inheriting those attributes from the first
section.  I turned out that the case that Type changed was missed
when implementing it - and D107707 make it much more likely to hit
that issue. That's fixed by this commit.

Reviewed By: MaskRay

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

(cherry picked from commit c01c62c76c60a5a5da0496e41faae907944c92dd)

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/ELFAsmParser.cpp
    llvm/test/MC/ELF/section-omitted-attributes.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index fdaacb572f062..6a9a174a1b6ae 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -676,14 +676,14 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
       getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
                                  IsComdat, UniqueID, LinkedToSym);
   getStreamer().SwitchSection(Section, Subsection);
-  if (Section->getType() != Type &&
+  // Check that flags are used consistently. However, the GNU assembler permits
+  // to leave out in subsequent uses of the same sections; for compatibility,
+  // do likewise.
+  if (!TypeName.empty() && Section->getType() != Type &&
       !allowSectionTypeMismatch(getContext().getTargetTriple(), SectionName,
                                 Type))
     Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getType()));
-  // Check that flags are used consistently. However, the GNU assembler permits
-  // to leave out in subsequent uses of the same sections; for compatibility,
-  // do likewise.
   if ((extraFlags || Size || !TypeName.empty()) && Section->getFlags() != Flags)
     Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getFlags()));

diff  --git a/llvm/test/MC/ELF/section-omitted-attributes.s b/llvm/test/MC/ELF/section-omitted-attributes.s
index 5f89cdabd84f2..108ecd0b3401f 100644
--- a/llvm/test/MC/ELF/section-omitted-attributes.s
+++ b/llvm/test/MC/ELF/section-omitted-attributes.s
@@ -4,6 +4,7 @@
 
 # CHECK: .section        .foo,"aM", at progbits,1
 # CHECK: .section        .rodata.cst8,"aM", at progbits,8
+# CHECK: .section        .lds_bss,"w", at nobits
 
 .section .foo,"aM", at progbits,1
 
@@ -15,3 +16,7 @@
 .section .rodata.cst8,"aM", at progbits,8
 
 .section .rodata.cst8
+
+# Likewise for Type changes
+.section        .lds_bss,"w", at nobits
+.section        .lds_bss


        


More information about the llvm-branch-commits mailing list