mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-09 11:26:06 +00:00

For a definition (of most linkage types), dso_local is set for ELF -fno-pic/-fpie and COFF, but not for Mach-O. This nuance causes unneeded binary format differences. This patch replaces (function) `define ` with `define{{.*}} `, (variable/constant/alias) `= ` with `={{.*}} `, or inserts appropriate `{{.*}} ` if there is an explicit linkage. * Clang will set dso_local for Mach-O, which is currently implied by TargetMachine.cpp. This will make COFF/Mach-O and executable ELF similar. * Eventually I hope we can make dso_local the textual LLVM IR default (write explicit "dso_preemptable" when applicable) and -fpic ELF will be similar to everything else. This patch helps move toward that goal.
37 lines
1.5 KiB
C++
37 lines
1.5 KiB
C++
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
|
|
|
|
int &f();
|
|
|
|
// LINUX: @r ={{.*}} thread_local global i32* null
|
|
// DARWIN: @r = internal thread_local global i32* null
|
|
thread_local int &r = f();
|
|
|
|
// LINUX: @_ZTH1r ={{.*}} alias void (), void ()* @__tls_init
|
|
// DARWIN: @_ZTH1r = internal alias void (), void ()* @__tls_init
|
|
|
|
int &g() { return r; }
|
|
|
|
// CHECK: define {{.*}} @[[R_INIT:.*]]()
|
|
// CHECK: call nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) i32* @_Z1fv()
|
|
// CHECK: store i32* %{{.*}}, i32** @r, align 8
|
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) i32* @_Z1gv()
|
|
// LINUX: call i32* @_ZTW1r()
|
|
// DARWIN: call cxx_fast_tlscc i32* @_ZTW1r()
|
|
// CHECK: ret i32* %{{.*}}
|
|
|
|
// LINUX: define weak_odr hidden i32* @_ZTW1r() [[ATTR0:#[0-9]+]] comdat {
|
|
// DARWIN: define cxx_fast_tlscc i32* @_ZTW1r() [[ATTR1:#[0-9]+]] {
|
|
// LINUX: call void @_ZTH1r()
|
|
// DARWIN: call cxx_fast_tlscc void @_ZTH1r()
|
|
// CHECK: load i32*, i32** @r, align 8
|
|
// CHECK: ret i32* %{{.*}}
|
|
|
|
// LINUX-LABEL: define internal void @__tls_init()
|
|
// DARWIN-LABEL: define internal cxx_fast_tlscc void @__tls_init()
|
|
// CHECK: call void @[[R_INIT]]()
|
|
|
|
// LINUX: attributes [[ATTR0]] = { {{.*}}"target-features"{{.*}} }
|
|
// DARWIN: attributes [[ATTR1]] = { {{.*}}nounwind{{.*}}"target-features"{{.*}} }
|