Bug#9033: For the ELF assembler output, always quote the section name.
authorJoerg Sonnenberger <joerg@bec.de>
Thu, 3 Mar 2011 22:31:08 +0000 (22:31 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Thu, 3 Mar 2011 22:31:08 +0000 (22:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126963 91177308-0d34-0410-b5e6-96231b3b80d8

17 files changed:
lib/MC/MCSectionELF.cpp
test/CodeGen/ARM/ctors_dtors.ll
test/CodeGen/ARM/section.ll
test/CodeGen/Blackfin/jumptable.ll
test/CodeGen/CellSPU/bss.ll
test/CodeGen/Mips/2008-07-15-InternalConstant.ll
test/CodeGen/Mips/2008-07-22-Cstpool.ll
test/CodeGen/PowerPC/sections.ll
test/CodeGen/X86/attribute-sections.ll
test/CodeGen/X86/bss_pagealigned.ll
test/CodeGen/X86/global-sections-tls.ll
test/CodeGen/X86/global-sections.ll
test/CodeGen/X86/pic_jumptable.ll
test/CodeGen/XCore/constants.ll
test/CodeGen/XCore/globals.ll
test/CodeGen/XCore/tls.ll
test/MC/ELF/section-quoting.s [new file with mode: 0644]

index d32aea144e6ec8f37a4a694d6f46eb8f6a9e5582..b908a745b26285aee29eed97a3ee61376ff24cb4 100644 (file)
@@ -39,8 +39,22 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
     return;
   }
 
-  OS << "\t.section\t" << getSectionName();
-  
+  StringRef name = getSectionName();
+  OS << "\t.section\t\"";
+  for (const char *b = name.begin(), *e = name.end(); b < e; ++b) {
+    if (*b == '"') // Unquoted "
+      OS << "\\\"";
+    else if (*b != '\\') // Neither " or backslash
+      OS << *b;
+    else if (b + 1 == e) // Trailing backslash
+      OS << "\\\\";
+    else {
+      OS << b[0] << b[1]; // Quoted character
+      ++b;
+    }
+  }
+  OS << '"';
+
   // Handle the weird solaris syntax if desired.
   if (MAI.usesSunStyleELFSectionSwitchSyntax() && 
       !(Flags & ELF::SHF_MERGE)) {
index fb94626ab7dd03487583f5a2a6a0a7933de7a023..4ed2deee3330b0089326d8e5ada392b624cb84e0 100644 (file)
@@ -5,11 +5,11 @@
 ; DARWIN: .section     __DATA,__mod_init_func,mod_init_funcs
 ; DARWIN: .section     __DATA,__mod_term_func,mod_term_funcs
 
-; ELF: .section .ctors,"aw",%progbits
-; ELF: .section .dtors,"aw",%progbits
+; ELF: .section ".ctors","aw",%progbits
+; ELF: .section ".dtors","aw",%progbits
 
-; GNUEABI: .section .init_array,"aw",%init_array
-; GNUEABI: .section .fini_array,"aw",%fini_array
+; GNUEABI: .section ".init_array","aw",%init_array
+; GNUEABI: .section ".fini_array","aw",%fini_array
 
 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_init } ]                ; <[1 x { i32, void ()* }]*> [#uses=0]
 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_fini } ]                ; <[1 x { i32, void ()* }]*> [#uses=0]
index 7a566d49d322d3dba678fed26b592e83ca6c7f77..ff708d55ab355cc759db67752339d5f310529fc7 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -mtriple=arm-linux | \
 ; RUN:   grep {__DTOR_END__:}
 ; RUN: llc < %s -mtriple=arm-linux | \
-; RUN:   grep {\\.section.\\.dtors,"aw",.progbits}
+; RUN:   grep {\\.section."\\.dtors","aw",.progbits}
 
 @__DTOR_END__ = internal global [1 x i32] zeroinitializer, section ".dtors"       ; <[1 x i32]*> [#uses=0]
 
index 263533c000970c747ab3116acb8947f80db9a65f..21fc1dfa6f0bf41ae2b9e1097169f919f7a35386 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=bfin -verify-machineinstrs | FileCheck %s
 
-; CHECK: .section .rodata
+; CHECK: .section ".rodata"
 ; CHECK: JTI0_0:
 ; CHECK: .long .BB0_1
 
index 327800d09cbfdd47a512a4f49e15554e1e11a5ab..7731e3091b060778e08dee212261d519fd5e15ff 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=cellspu | FileCheck %s
 
 @bssVar = global i32 zeroinitializer
-; CHECK: .section .bss
+; CHECK: .section ".bss"
 ; CHECK-NEXT: .globl
 
 @localVar= internal global i32 zeroinitializer
index c3db6387aff3061528aec51b0e92e71b2c084f4d..df9b2ebc9e87be89200c687974415ee0a6f4ee9c 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=mips -o %t
-; RUN: grep {rodata.str1.4,"aMS",@progbits}  %t | count 1
-; RUN: grep {r.data,}  %t | count 1
+; RUN: grep {rodata.str1.4","aMS",@progbits}  %t | count 1
+; RUN: grep {r.data",}  %t | count 1
 ; RUN: grep {\%hi} %t | count 2
 ; RUN: grep {\%lo} %t | count 2
 ; RUN: not grep {gp_rel} %t
index 20bd88889061fc02070598686adca85c8cb32080..04574155358d7b5716366d47a4d6dadba5ec8a0d 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=mips -o %t
 ; RUN: grep {CPI\[01\]_\[01\]:} %t | count 2
-; RUN: grep {rodata.cst4,"aM",@progbits} %t | count 1
+; RUN: grep {".rodata.cst4","aM",@progbits} %t | count 1
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
 target triple = "mipsallegrexel-unknown-psp-elf"
 
index 0ff4a89ff3794c12d16966c61c2d5bec7876bce9..260b91e7722c717e2c2614a36d26696b0d3f03fe 100644 (file)
@@ -3,6 +3,6 @@
 
 @A = global i32 0
 
-; CHECK:  .section  .bss,"aw",@nobits
+; CHECK:  .section  ".bss","aw",@nobits
 ; CHECK:  .globl A
 
index 30353346b5c96780e46ed31a874ff5c6de421b75..19e56eeccea520843702c05148a0f1a55b1857fe 100644 (file)
@@ -3,16 +3,16 @@
 declare i32 @foo()
 @G0 = global i32 ()* @foo, section ".init_array"
 
-; LINUX:  .section  .init_array,"aw"
+; LINUX:  .section  ".init_array","aw"
 ; LINUX:  .globl G0
 
 @G1 = global i32 ()* @foo, section ".fini_array"
 
-; LINUX:  .section  .fini_array,"aw"
+; LINUX:  .section  ".fini_array","aw"
 ; LINUX:  .globl G1
 
 @G2 = global i32 ()* @foo, section ".preinit_array"
 
-; LINUX:  .section .preinit_array,"aw"
+; LINUX:  .section ".preinit_array","aw"
 ; LINUX:  .globl G2
 
index da95aca110da270100b9edf167ba7e783e0bc050..746364e7277f45160382b9c8c8eae1647dfab55d 100644 (file)
@@ -14,7 +14,7 @@ define void @unxlate_dev_mem_ptr(i64 %phis, i8* %addr) nounwind {
   ret void
 }
 @bm_pte = internal global [512 x %struct.kmem_cache_order_objects] zeroinitializer, section ".bss.page_aligned", align 4096
-; CHECK: .section        .bss.page_aligned,"aw",@nobits
+; CHECK: .section        ".bss.page_aligned","aw",@nobits
 ; CHECK-NEXT: .align  4096
 ; CHECK-NEXT: bm_pte:
 ; CHECK-NEXT: .zero   4096
index 2c2303042bc459f69370c90d7c18befb08aece59..e1e5fb3de12105cbe6257e8679cc27ec355cdfbc 100644 (file)
@@ -2,7 +2,7 @@
 
 ; PR4639
 @G1 = internal thread_local global i32 0               ; <i32*> [#uses=1]
-; LINUX: .section              .tbss,"awT",@nobits
+; LINUX: .section      ".tbss","awT",@nobits
 ; LINUX: G1:
 
 
index 39a69e17a1008d9f6042481266f6aa103c2659a2..7625a4082948a9cf69ca58d9a5acc54b72968fd2 100644 (file)
 ; DARWIN: _G3:
 ; DARWIN:     .long _G1
 
-; LINUX:   .section        .rodata,"a",@progbits
+; LINUX:   .section        ".rodata","a",@progbits
 ; LINUX:   .globl  G3
 
-; LINUX-SECTIONS: .section        .rodata.G3,"a",@progbits
+; LINUX-SECTIONS: .section        ".rodata.G3","a",@progbits
 ; LINUX-SECTIONS: .globl  G3
 
 
@@ -66,7 +66,7 @@
 @"foo bar" = linkonce global i32 42
 
 ; LINUX: .type foo_20_bar,@object
-; LINUX: .section .data.foo_20_bar,"aGw",@progbits,foo_20_bar,comdat
+; LINUX: .section ".data.foo_20_bar","aGw",@progbits,foo_20_bar,comdat
 ; LINUX: .weak foo_20_bar
 ; LINUX: foo_20_bar:
 
@@ -79,7 +79,7 @@
 @G6 = weak_odr unnamed_addr constant [1 x i8] c"\01"
 
 ; LINUX:   .type       G6,@object
-; LINUX:   .section    .rodata.G6,"aG",@progbits,G6,comdat
+; LINUX:   .section    ".rodata.G6","aG",@progbits,G6,comdat
 ; LINUX:   .weak       G6
 ; LINUX: G6:
 ; LINUX:   .byte       1
 ; DARWIN: _G7:
 ; DARWIN:      .asciz  "abcdefghi"
 
-; LINUX:       .section                .rodata.str1.1,"aMS",@progbits,1
+; LINUX:       .section        ".rodata.str1.1","aMS",@progbits,1
 ; LINUX:       .globl G7
 ; LINUX: G7:
 ; LINUX:       .asciz  "abcdefghi"
 
-; LINUX-SECTIONS: .section        .rodata.G7,"aMS",@progbits,1
+; LINUX-SECTIONS: .section        ".rodata.G7","aMS",@progbits,1
 ; LINUX-SECTIONS:      .globl G7
 
 
 ; DARWIN:      .globl _G8
 ; DARWIN: _G8:
 
-; LINUX:       .section                .rodata.str2.2,"aMS",@progbits,2
+; LINUX:       .section        ".rodata.str2.2","aMS",@progbits,2
 ; LINUX:       .globl G8
 ; LINUX:G8:
 
 ; DARWIN:      .globl _G9
 ; DARWIN: _G9:
 
-; LINUX:       .section                .rodata.str4.4,"aMS",@progbits,4
+; LINUX:       .section        ".rodata.str4.4","aMS",@progbits,4
 ; LINUX:       .globl G9
 ; LINUX:G9
 
index b6761e338aa9d3b9d59f4e2ffd9bf12be55406ba..8ddba4af72a0b51dad9b0007c86d164a3cb1628b 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | grep -F .text._Z3fooILi1EEvi,"axG",@progbits,_Z3fooILi1EEvi,comdat
+; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | grep -F .text._Z3fooILi1EEvi","axG",@progbits,_Z3fooILi1EEvi,comdat
 ; RUN: llc < %s -relocation-model=pic -mtriple=i686-apple-darwin -asm-verbose=false | FileCheck %s
 ; RUN: llc < %s                       -mtriple=x86_64-apple-darwin | not grep 'lJTI'
 ; rdar://6971437
index cad1a2153f4fe80c8472f094cf4b04cf13c5daa7..10cf9a75dfaeafecd84a8e93eba7d5f41510cb93 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=xcore -mcpu=xs1b-generic | FileCheck %s
 
-; CHECK: .section .cp.rodata.cst4,"aMc",@progbits,4
+; CHECK: .section ".cp.rodata.cst4","aMc",@progbits,4
 ; CHECK: .LCPI0_0:
 ; CHECK: .long 12345678
 ; CHECK: f:
index 7487561dec96d28f1d73b5f7d24b368e4438078c..f6ff3354ee8cde858b36d944f3bb33bc4fb69c00 100644 (file)
@@ -60,33 +60,33 @@ entry:
 }
 
 @G1 = global i32 4712
-; CHECK: .section .dp.data,"awd",@progbits
+; CHECK: .section ".dp.data","awd",@progbits
 ; CHECK: G1:
 
 @G2 = global i32 0
-; CHECK: .section .dp.bss,"awd",@nobits
+; CHECK: .section ".dp.bss","awd",@nobits
 ; CHECK: G2:
 
 @G3 = unnamed_addr constant i32 9401
-; CHECK: .section .cp.rodata.cst4,"aMc",@progbits,4
+; CHECK: .section ".cp.rodata.cst4","aMc",@progbits,4
 ; CHECK: G3:
 
 @G4 = global i32* @G1
-; CHECK: .section .dp.data,"awd",@progbits
+; CHECK: .section ".dp.data","awd",@progbits
 ; CHECK: G4:
 
 @G5 = unnamed_addr constant i32* @G1
-; CHECK: .section .cp.rodata,"ac",@progbits
+; CHECK: .section ".cp.rodata","ac",@progbits
 ; CHECK: G5:
 
 @G6 = global i32* @G8
-; CHECK: .section .dp.data,"awd",@progbits
+; CHECK: .section ".dp.data","awd",@progbits
 ; CHECK: G6:
 
 @G7 = unnamed_addr constant i32* @G8
-; CHECK: .section .cp.rodata,"ac",@progbits
+; CHECK: .section ".cp.rodata","ac",@progbits
 ; CHECK: G7:
 
 @G8 = internal global i32 9312
-; CHECK: .section .dp.data,"awd",@progbits
+; CHECK: .section ".dp.data","awd",@progbits
 ; CHECK: G8:
index ed41afae0996032394ad9f0396933bcd98c2c67d..b4f1671796a749aaf489c5aa46923ff31bf6f318 100644 (file)
@@ -8,7 +8,7 @@ entry:
 }
 
 @G = thread_local global i32 15
-; CHECK: .section .dp.data,"awd",@progbits
+; CHECK: .section ".dp.data","awd",@progbits
 ; CHECK: G:
 ; CHECK: .long 15
 ; CHECK: .long 15
diff --git a/test/MC/ELF/section-quoting.s b/test/MC/ELF/section-quoting.s
new file mode 100644 (file)
index 0000000..5335af1
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: llvm-mc -triple x86_64-pc-linux-gnu %s -o - | FileCheck %s
+
+// Test that we handle the strings like gas
+.section bar-"foo"
+.section "foo"
+.section "foo bar"
+
+// CHECK: .section "bar-\"foo\""
+// CHECK: .section "foo"
+// CHECK: .section "foo bar"