Revert "[CodeGenModule] Set dso_local for Mach-O GlobalValue"

This reverts commit 809a1e0ffd.

Mach-O doesn't support dso_local and this change broke XNU because of the use of dso_local.

Differential Revision: https://reviews.llvm.org/D98458
This commit is contained in:
Alex Lorenz 2021-03-11 14:54:47 -08:00
parent 3315bd0beb
commit d672d5219a
8 changed files with 76 additions and 82 deletions

View File

@ -978,20 +978,14 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO()))
return true;
const auto &CGOpts = CGM.getCodeGenOpts();
llvm::Reloc::Model RM = CGOpts.RelocationModel;
const auto &LOpts = CGM.getLangOpts();
if (TT.isOSBinFormatMachO()) {
if (RM == llvm::Reloc::Static)
return true;
return GV->isStrongDefinitionForLinker();
}
// Only handle COFF and ELF for now.
if (!TT.isOSBinFormatELF())
return false;
// If this is not an executable, don't assume anything is local.
const auto &CGOpts = CGM.getCodeGenOpts();
llvm::Reloc::Model RM = CGOpts.RelocationModel;
const auto &LOpts = CGM.getLangOpts();
if (RM != llvm::Reloc::Static && !LOpts.PIE) {
// On ELF, if -fno-semantic-interposition is specified and the target
// supports local aliases, there will be neither CC1

View File

@ -18,9 +18,9 @@ extern int E __attribute__((weak_import));
int E;
extern int E __attribute__((weak_import));
// CHECK: @A = dso_local global i32
// CHECK: @A = global i32
// CHECK-NOT: @B =
// CHECK: @C = dso_local global i32
// CHECK: @D = dso_local global i32
// CHECK: @E = dso_local global i32
// CHECK: @C = global i32
// CHECK: @D = global i32
// CHECK: @E = global i32

View File

@ -93,7 +93,7 @@ int test_trunc_int() {
} const U = {15}; // 0b00001111
return U.i;
}
// CHECK: define dso_local i32 @test_trunc_int()
// CHECK: define{{.*}} i32 @test_trunc_int()
// CHECK: ret i32 -1
int test_trunc_three_bits() {
@ -102,7 +102,7 @@ int test_trunc_three_bits() {
} const U = {15}; // 0b00001111
return U.i;
}
// CHECK: define dso_local i32 @test_trunc_three_bits()
// CHECK: define{{.*}} i32 @test_trunc_three_bits()
// CHECK: ret i32 -1
int test_trunc_1() {
@ -111,7 +111,7 @@ int test_trunc_1() {
} const U = {15}; // 0b00001111
return U.i;
}
// CHECK: define dso_local i32 @test_trunc_1()
// CHECK: define{{.*}} i32 @test_trunc_1()
// CHECK: ret i32 -1
int test_trunc_zero() {
@ -120,7 +120,7 @@ int test_trunc_zero() {
} const U = {80}; // 0b01010000
return U.i;
}
// CHECK: define dso_local i32 @test_trunc_zero()
// CHECK: define{{.*}} i32 @test_trunc_zero()
// CHECK: ret i32 0
int test_constexpr() {
@ -129,7 +129,7 @@ int test_constexpr() {
} const U = {1 + 2 + 4 + 8}; // 0b00001111
return U.i;
}
// CHECK: define dso_local i32 @test_constexpr()
// CHECK: define{{.*}} i32 @test_constexpr()
// CHECK: ret i32 -1
int test_notrunc() {
@ -138,7 +138,7 @@ int test_notrunc() {
} const U = {1 + 2 + 4 + 8}; // 0b00001111
return U.i;
}
// CHECK: define dso_local i32 @test_notrunc()
// CHECK: define{{.*}} i32 @test_notrunc()
// CHECK: ret i32 15
long long test_trunc_long_long() {
@ -147,6 +147,6 @@ long long test_trunc_long_long() {
} const U = {0b0100111101001101};
return U.i;
}
// CHECK: define dso_local i64 @test_trunc_long_long()
// CHECK: define{{.*}} i64 @test_trunc_long_long()
// CHECK: ret i64 3917
}

View File

@ -2,17 +2,17 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -std=c++98 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -std=c++11 -o - %s | FileCheck %s
// CHECK: @a = dso_local global i32 10
// CHECK: @a = global i32 10
int a = 10;
// CHECK: @ar = dso_local constant i32* @a
// CHECK: @ar = constant i32* @a
int &ar = a;
void f();
// CHECK: @fr = dso_local constant void ()* @_Z1fv
// CHECK: @fr = constant void ()* @_Z1fv
void (&fr)() = f;
struct S { int& a; };
// CHECK: @s = dso_local global %struct.S { i32* @a }
// CHECK: @s = global %struct.S { i32* @a }
S s = { a };
// PR5581
@ -23,7 +23,7 @@ public:
unsigned f;
};
// CHECK: @_ZN6PR55812g0E = dso_local global %"class.PR5581::C" { i32 1 }
// CHECK: @_ZN6PR55812g0E = global %"class.PR5581::C" { i32 1 }
C g0 = { C::e1 };
}
@ -39,10 +39,10 @@ namespace test2 {
static int g();
} a;
// CHECK: @_ZN5test22t0E = dso_local global double {{1\.0+e\+0+}}, align 8
// CHECK: @_ZN5test22t1E = dso_local global [2 x double] [double {{1\.0+e\+0+}}, double {{5\.0+e-0*}}1], align 16
// CHECK: @_ZN5test22t2E = dso_local global double* @_ZN5test21A1d
// CHECK: @_ZN5test22t3E = dso_local global {{.*}} @_ZN5test21A1g
// CHECK: @_ZN5test22t0E = global double {{1\.0+e\+0+}}, align 8
// CHECK: @_ZN5test22t1E = global [2 x double] [double {{1\.0+e\+0+}}, double {{5\.0+e-0*}}1], align 16
// CHECK: @_ZN5test22t2E = global double* @_ZN5test21A1d
// CHECK: @_ZN5test22t3E = global {{.*}} @_ZN5test21A1g
double t0 = A::d;
double t1[] = { A::d, A::f };
const double *t2 = &a.d;
@ -50,7 +50,7 @@ namespace test2 {
}
// We don't expect to fold this in the frontend, but make sure it doesn't crash.
// CHECK: @PR9558 = dso_local global float 0.000000e+0
// CHECK: @PR9558 = global float 0.000000e+0
float PR9558 = reinterpret_cast<const float&>("asd");
// An initialized const automatic variable cannot be promoted to a constant
@ -66,7 +66,7 @@ int writeToMutable() {
// Make sure we don't try to fold this in the frontend; the backend can't
// handle it.
// CHECK: @PR11705 = dso_local global i128 0
// CHECK: @PR11705 = global i128 0
__int128_t PR11705 = (__int128_t)&PR11705;
// Make sure we don't try to fold this either.
@ -77,11 +77,11 @@ void UnfoldableAddrLabelDiff() { static __int128_t x = (long)&&a-(long)&&b; a:b:
// CHECK: @_ZZ21FoldableAddrLabelDiffvE1x = internal global i64 sub (i64 ptrtoint (i8* blockaddress(@_Z21FoldableAddrLabelDiffv
void FoldableAddrLabelDiff() { static long x = (long)&&a-(long)&&b; a:b:return;}
// CHECK: @i = dso_local constant i32* bitcast (float* @PR9558 to i32*)
// CHECK: @i = constant i32* bitcast (float* @PR9558 to i32*)
int &i = reinterpret_cast<int&>(PR9558);
int arr[2];
// CHECK: @pastEnd = dso_local constant i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*)
// CHECK: @pastEnd = constant i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*)
int &pastEnd = arr[2];
struct X {

View File

@ -226,5 +226,5 @@ namespace test18 {
template<template<typename> class> struct A {};
struct B { template<typename> struct C; };
void f(A<B::C>) {}
// CHECK-DAG: define dso_local void @_ZN6test181fENS_1AINS_1B1CEEE(
// CHECK-DAG: define void @_ZN6test181fENS_1AINS_1B1CEEE(
}

View File

@ -60,7 +60,7 @@ namespace RefTempSubobject {
};
// CHECK: @_ZGRN16RefTempSubobject2srE_ = internal global { i32*, [3 x i32] } { {{.*}} getelementptr {{.*}} @_ZGRN16RefTempSubobject2srE_ {{.*}}, [3 x i32] [i32 1, i32 2, i32 3] }
// CHECK: @_ZN16RefTempSubobject2srE = {{.*}} constant {{.*}} @_ZGRN16RefTempSubobject2srE_
// CHECK: @_ZN16RefTempSubobject2srE = constant {{.*}} @_ZGRN16RefTempSubobject2srE_
constexpr const SelfReferential &sr = SelfReferential();
}

View File

@ -110,14 +110,14 @@ namespace type0 {
};
void A::foo() {}
// FUNS-LABEL: define{{.*}} void @_ZN5type01A3fooEv(
// VARS: @_ZTVN5type01AE = dso_local unnamed_addr constant
// VARS: @_ZTSN5type01AE = dso_local constant
// VARS: @_ZTIN5type01AE = dso_local constant
// FUNS-LABEL: define void @_ZN5type01A3fooEv(
// VARS: @_ZTVN5type01AE = unnamed_addr constant
// VARS: @_ZTSN5type01AE = constant
// VARS: @_ZTIN5type01AE = constant
// FUNS-HIDDEN-LABEL: define hidden void @_ZN5type01A3fooEv(
// VARS-HIDDEN: @_ZTVN5type01AE = dso_local unnamed_addr constant
// VARS-HIDDEN: @_ZTSN5type01AE = dso_local constant
// VARS-HIDDEN: @_ZTIN5type01AE = dso_local constant
// VARS-HIDDEN: @_ZTVN5type01AE = unnamed_addr constant
// VARS-HIDDEN: @_ZTSN5type01AE = constant
// VARS-HIDDEN: @_ZTIN5type01AE = constant
}
namespace type1 {
@ -127,13 +127,13 @@ namespace type1 {
void A::foo() {}
// FUNS-LABEL: define hidden void @_ZN5type11A3fooEv(
// VARS: @_ZTVN5type11AE = dso_local unnamed_addr constant
// VARS: @_ZTSN5type11AE = dso_local constant
// VARS: @_ZTIN5type11AE = dso_local constant
// VARS: @_ZTVN5type11AE = unnamed_addr constant
// VARS: @_ZTSN5type11AE = constant
// VARS: @_ZTIN5type11AE = constant
// FUNS-HIDDEN-LABEL: define hidden void @_ZN5type11A3fooEv(
// VARS-HIDDEN: @_ZTVN5type11AE = dso_local unnamed_addr constant
// VARS-HIDDEN: @_ZTSN5type11AE = dso_local constant
// VARS-HIDDEN: @_ZTIN5type11AE = dso_local constant
// VARS-HIDDEN: @_ZTVN5type11AE = unnamed_addr constant
// VARS-HIDDEN: @_ZTSN5type11AE = constant
// VARS-HIDDEN: @_ZTIN5type11AE = constant
}
namespace type2 {
@ -142,7 +142,7 @@ namespace type2 {
};
void A::foo() {}
// FUNS-LABEL: define dso_local void @_ZN5type21A3fooEv(
// FUNS-LABEL: define void @_ZN5type21A3fooEv(
// VARS: @_ZTVN5type21AE = hidden unnamed_addr constant
// VARS: @_ZTSN5type21AE = hidden constant
// VARS: @_ZTIN5type21AE = hidden constant
@ -158,11 +158,11 @@ namespace type3 {
};
void A::foo() {}
// FUNS-LABEL: define dso_local void @_ZN5type31A3fooEv(
// FUNS-LABEL: define void @_ZN5type31A3fooEv(
// VARS: @_ZTVN5type31AE = hidden unnamed_addr constant
// VARS: @_ZTSN5type31AE = hidden constant
// VARS: @_ZTIN5type31AE = hidden constant
// FUNS-HIDDEN-LABEL: define dso_local void @_ZN5type31A3fooEv(
// FUNS-HIDDEN-LABEL: define void @_ZN5type31A3fooEv(
// VARS-HIDDEN: @_ZTVN5type31AE = hidden unnamed_addr constant
// VARS-HIDDEN: @_ZTSN5type31AE = hidden constant
// VARS-HIDDEN: @_ZTIN5type31AE = hidden constant

View File

@ -18,7 +18,7 @@ namespace test30 {
};
H DEFAULT a;
X<&a> b;
// CHECK: _ZN6test301bE = dso_local global
// CHECK: _ZN6test301bE = global
// CHECK-HIDDEN: _ZN6test301bE = hidden global
}
@ -33,7 +33,7 @@ namespace test25 {
class DEFAULT A { };
X<int>::definition<A> a;
// CHECK: @_ZN6test251aE = dso_local global
// CHECK: @_ZN6test251aE = global
// CHECK-HIDDEN: @_ZN6test251aE = hidden global
}
@ -41,7 +41,7 @@ namespace test28 {
class DEFAULT foo {
};
foo myvec;
// CHECK: @_ZN6test285myvecE = dso_local global
// CHECK: @_ZN6test285myvecE = global
// CHECK-HIDDEN: @_ZN6test285myvecE = hidden global
}
@ -53,8 +53,8 @@ namespace test29 {
DEFAULT extern RECT data_rect;
RECT data_rect = { -1};
#pragma GCC visibility pop
// CHECK: @_ZN6test299data_rectE = dso_local global
// CHECK-HIDDEN: @_ZN6test299data_rectE = dso_local global
// CHECK: @_ZN6test299data_rectE = global
// CHECK-HIDDEN: @_ZN6test299data_rectE = global
}
namespace test40 {
@ -103,17 +103,17 @@ namespace test48 {
// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
// CHECK: @_ZN5Test71aE = hidden global
// CHECK: @_ZN5Test71bE = dso_local global
// CHECK: @test9_var = dso_local global
// CHECK-HIDDEN: @test9_var = dso_local global
// CHECK: @_ZN5Test71bE = global
// CHECK: @test9_var = global
// CHECK-HIDDEN: @test9_var = global
// CHECK: @_ZN6Test121A6hiddenE = external hidden global
// CHECK: @_ZN6Test121A7visibleE = external global
// CHECK-HIDDEN: @_ZN6Test121A6hiddenE = external hidden global
// CHECK-HIDDEN: @_ZN6Test121A7visibleE = external global
// CHECK: @_ZN6Test131B1aE = hidden global
// CHECK: @_ZN6Test131C1aE = dso_local global
// CHECK: @_ZN6Test131C1aE = global
// CHECK-HIDDEN: @_ZN6Test131B1aE = hidden global
// CHECK-HIDDEN: @_ZN6Test131C1aE = dso_local global
// CHECK-HIDDEN: @_ZN6Test131C1aE = global
// CHECK: @_ZN6Test143varE = external global
// CHECK-HIDDEN: @_ZN6Test143varE = external global
// CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
@ -134,8 +134,8 @@ namespace test27 {
void C<int>::D::g() {
}
// CHECK: _ZTVN6test271CIiE1DE = dso_local unnamed_addr constant
// CHECK-HIDDEN: _ZTVN6test271CIiE1DE = dso_local unnamed_addr constant
// CHECK: _ZTVN6test271CIiE1DE = unnamed_addr constant
// CHECK-HIDDEN: _ZTVN6test271CIiE1DE = unnamed_addr constant
}
// CHECK: @_ZTVN5Test63fooE = linkonce_odr hidden unnamed_addr constant
@ -195,7 +195,7 @@ namespace Test4 HIDDEN {
};
// A has default visibility.
// CHECK-LABEL: define dso_local void @_ZN5Test41A1fEv
// CHECK-LABEL: define void @_ZN5Test41A1fEv
void A::f() { }
}
@ -209,7 +209,7 @@ namespace Test5 {
namespace NS {
// g is in NS, but this NS decl is not hidden.
// CHECK-LABEL: define dso_local void @_ZN5Test52NS1gEv
// CHECK-LABEL: define void @_ZN5Test52NS1gEv
void g() { }
}
}
@ -268,8 +268,8 @@ namespace Test9 {
void DEFAULT test9_fun(struct A *a) { }
struct A DEFAULT test9_var; // above
}
// CHECK-LABEL: define dso_local void @test9_fun(
// CHECK-HIDDEN-LABEL: define dso_local void @test9_fun(
// CHECK-LABEL: define void @test9_fun(
// CHECK-HIDDEN-LABEL: define void @test9_fun(
void test() {
A a = test9_var;
@ -285,8 +285,8 @@ namespace Test10 {
void foo(A*);
};
// CHECK-LABEL: define dso_local void @_ZN6Test101B3fooEPNS_1AE(
// CHECK-HIDDEN-LABEL: define dso_local void @_ZN6Test101B3fooEPNS_1AE(
// CHECK-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
// CHECK-HIDDEN-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
void B::foo(A*) {}
}
@ -507,7 +507,7 @@ namespace Test20 {
static void test3();
};
// CHECK-LABEL: define dso_local void @_ZN6Test201AILj1EE5test2Ev()
// CHECK-LABEL: define void @_ZN6Test201AILj1EE5test2Ev()
void A<1>::test2() {}
// CHECK: declare void @_ZN6Test201AILj1EE5test3Ev()
@ -684,8 +684,8 @@ namespace test26 {
template<>
void C<int>::f() { }
// CHECK-LABEL: define dso_local void @_ZN6test261CIiE1fEv
// CHECK-HIDDEN-LABEL: define dso_local void @_ZN6test261CIiE1fEv
// CHECK-LABEL: define void @_ZN6test261CIiE1fEv
// CHECK-HIDDEN-LABEL: define void @_ZN6test261CIiE1fEv
}
namespace test31 {
@ -709,8 +709,8 @@ namespace test32 {
};
void A::B::baz() {
}
// CHECK-LABEL: define dso_local void @_ZN6test321A1B3bazEv
// CHECK-HIDDEN-LABEL: define dso_local void @_ZN6test321A1B3bazEv
// CHECK-LABEL: define void @_ZN6test321A1B3bazEv
// CHECK-HIDDEN-LABEL: define void @_ZN6test321A1B3bazEv
}
namespace test33 {
@ -829,8 +829,8 @@ namespace test42 {
};
void bar<foo>::zed() {
}
// CHECK-LABEL: define dso_local void @_ZN6test423barINS_3fooEE3zedEv
// CHECK-HIDDEN-LABEL: define dso_local void @_ZN6test423barINS_3fooEE3zedEv
// CHECK-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
// CHECK-HIDDEN-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
}
namespace test43 {
@ -842,8 +842,8 @@ namespace test43 {
template <>
DEFAULT void bar<foo>() {
}
// CHECK-LABEL: define dso_local void @_ZN6test433barINS_3fooEEEvv
// CHECK-HIDDEN-LABEL: define dso_local void @_ZN6test433barINS_3fooEEEvv
// CHECK-LABEL: define void @_ZN6test433barINS_3fooEEEvv
// CHECK-HIDDEN-LABEL: define void @_ZN6test433barINS_3fooEEEvv
}
namespace test44 {
@ -1208,10 +1208,10 @@ namespace test65 {
static void foo() {}
};
// CHECK-LABEL: define dso_local void @_ZN6test651BINS_1AEE4funcEv()
// CHECK-LABEL: define void @_ZN6test651BINS_1AEE4funcEv()
template <> DEFAULT void B<A>::func() {}
// CHECK-LABEL: define dso_local void @_ZN6test651BINS_1AEE6funcT2IS1_EEvv()
// CHECK-LABEL: define void @_ZN6test651BINS_1AEE6funcT2IS1_EEvv()
template <> template <> DEFAULT void B<A>::funcT2<A>() {}
// CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE6funcT1IiEEvv()
@ -1314,6 +1314,6 @@ namespace test69 {
}
namespace foo __attribute__((visibility("hidden"))) {
}
// CHECK-LABEL: define dso_local void @_ZN6test693foo1fEv
// CHECK-LABEL: define void @_ZN6test693foo1fEv
// CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
}