summaryrefslogtreecommitdiff
path: root/test/CodeGen/X86/osx-private-labels.ll
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-18 22:24:57 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-18 22:24:57 +0000
commit6880f0e19f24f7e7f0877e876b74c5cab10abc22 (patch)
tree87a2dc150f33e195518f8533ecdde923762aab8b /test/CodeGen/X86/osx-private-labels.ll
parent1836fe5651722c638e32ac94c5b4fe885afa9f15 (diff)
downloadllvm-6880f0e19f24f7e7f0877e876b74c5cab10abc22.tar.gz
llvm-6880f0e19f24f7e7f0877e876b74c5cab10abc22.tar.bz2
llvm-6880f0e19f24f7e7f0877e876b74c5cab10abc22.tar.xz
Fix PR18743.
The IR @foo = private constant i32 42 is valid, but before this patch we would produce an invalid MachO from it. It was invalid because it would use an L label in a section where the liker needs the labels in order to atomize it. One way of fixing it would be to just reject this IR in the backend, but that would not be very front end friendly. What this patch does is use an 'l' prefix in sections that we know the linker requires symbols for atomizing them. This allows frontends to just use private and not worry about which sections they go to or how the linker handles them. One small issue with this strategy is that now a symbol name depends on the section, which is not available before codegen. This is not a problem in practice. The reason is that it only happens with private linkage, which will be ignored by the non codegen users (llvm-nm and llvm-ar). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201608 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/X86/osx-private-labels.ll')
-rw-r--r--test/CodeGen/X86/osx-private-labels.ll71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/CodeGen/X86/osx-private-labels.ll b/test/CodeGen/X86/osx-private-labels.ll
new file mode 100644
index 0000000000..349ce7d0cc
--- /dev/null
+++ b/test/CodeGen/X86/osx-private-labels.ll
@@ -0,0 +1,71 @@
+; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
+; Test all the cases where a L label is safe. Removing any entry from
+; TargetLoweringObjectFileMachO::isSectionAtomizableBySymbols should cause
+; this to fail.
+; We also test some noteworthy cases that require an l label.
+
+@private1 = private unnamed_addr constant [4 x i8] c"zed\00"
+; CHECK: .section __TEXT,__cstring,cstring_literals
+; CHECK-NEXT: L_private1:
+
+@private2 = private unnamed_addr constant [5 x i16] [i16 116, i16 101,
+ i16 115, i16 116, i16 0]
+; CHECK: .section __TEXT,__ustring
+; CHECK-NEXT: .align 1
+; CHECK-NEXT: l_private2:
+
+; There is no dedicated 4 byte strings on MachO.
+
+%struct.NSConstantString = type { i32*, i32, i8*, i32 }
+@private3 = private constant %struct.NSConstantString { i32* null, i32 1992, i8* null, i32 0 }, section "__DATA,__cfstring"
+; CHECK: .section __DATA,__cfstring
+; CHECK-NEXT: .align 4
+; CHECK-NEXT: L_private3:
+
+; There is no dedicated 1 or 2 byte constant section on MachO.
+
+@private4 = private unnamed_addr constant i32 42
+; CHECK: .section __TEXT,__literal4,4byte_literals
+; CHECK-NEXT: .align 2
+; CHECK-NEXT: L_private4:
+
+@private5 = private unnamed_addr constant i64 42
+; CHECK: .section __TEXT,__literal8,8byte_literals
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private5:
+
+@private6 = private unnamed_addr constant i128 42
+; CHECK: .section __TEXT,__literal16,16byte_literals
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private6:
+
+%struct._objc_class = type { i8* }
+@private7 = private global %struct._objc_class* null, section "__OBJC,__cls_refs,literal_pointers,no_dead_strip"
+; CHECK: .section __OBJC,__cls_refs,literal_pointers,no_dead_strip
+; CHECK: .align 3
+; CHECK: L_private7:
+
+@private8 = private global i32* null, section "__DATA,__nl_symbol_ptr,non_lazy_symbol_pointers"
+; CHECK: .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private8:
+
+@private9 = private global i32* null, section "__DATA,__la_symbol_ptr,lazy_symbol_pointers"
+; CHECK: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private9:
+
+@private10 = private global i32* null, section "__DATA,__mod_init_func,mod_init_funcs"
+; CHECK: .section __DATA,__mod_init_func,mod_init_funcs
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private10:
+
+@private11 = private global i32* null, section "__DATA,__mod_term_func,mod_term_funcs"
+; CHECK: .section __DATA,__mod_term_func,mod_term_funcs
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private11:
+
+@private12 = private global i32* null, section "__DATA,__foobar,interposing"
+; CHECK: .section __DATA,__foobar,interposing
+; CHECK-NEXT: .align 3
+; CHECK-NEXT: L_private12: