r208128 - Include translation unit filename in global ctor symbol names.
Nico Weber
thakis at chromium.org
Tue May 6 15:35:24 PDT 2014
Aha, lib/Transforms/Instrumentation/AddressSanitizer.cpp mentions
_GLOBAL__I_a (I only looked in compiler-rt so far, not llvm). Probably
easy to fix, giving it a shot…
On Tue, May 6, 2014 at 3:21 PM, Nico Weber <thakis at chromium.org> wrote:
> Apparently this makes TestCases/Linux/initialization-bug-any-order.cc
> and TestCases/initialization-bug.cc unhappy. I looked at the asan code
> for this for a bit (and I'll continue looking). I don't understand yet
> why this is causing that failure. (+samsonov in case it's obvious to
> him.)
>
> On Tue, May 6, 2014 at 1:32 PM, Nico Weber <nicolasweber at gmx.de> wrote:
>> Author: nico
>> Date: Tue May 6 15:32:45 2014
>> New Revision: 208128
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=208128&view=rev
>> Log:
>> Include translation unit filename in global ctor symbol names.
>>
>> This makes it easier to see where a global ctor comes from, and it also makes
>> ASan's init order analyzer output easier to understand. gcc does this too,
>> but only in -fPIC mode for some reason. Don't do this for constructors with
>> explicit init priority.
>>
>> Also prepend "sub_" before the 'I', that way regular constructors stay
>> lexicographically after symbols with init priority (because
>> ord('s') > ord('I')). gold seems to ignore the name of constructor symbols,
>> and ld only looks at the symbol if it includes an init priority, which this
>> patch doesn't change.
>>
>> Before: __GLOBAL_I_a
>> Now: __GLOBAL_sub_I_myfile.cc
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>> cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp
>> cfe/trunk/test/CodeGenCXX/global-init.cpp
>> cfe/trunk/test/CodeGenCXX/globalinit-loc.cpp
>> cfe/trunk/test/CodeGenCXX/init-priority-attr.cpp
>> cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>> cfe/trunk/test/CodeGenCXX/runtimecc.cpp
>> cfe/trunk/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
>> cfe/trunk/test/CodeGenObjCXX/arc-globals.mm
>>
>> Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Tue May 6 15:32:45 2014
>> @@ -17,6 +17,7 @@
>> #include "clang/Frontend/CodeGenOptions.h"
>> #include "llvm/ADT/StringExtras.h"
>> #include "llvm/IR/Intrinsics.h"
>> +#include "llvm/Support/Path.h"
>>
>> using namespace clang;
>> using namespace CodeGen;
>> @@ -362,7 +363,7 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
>> // Compute the function suffix from priority. Prepend with zeroes to make
>> // sure the function names are also ordered as priorities.
>> std::string PrioritySuffix = llvm::utostr(Priority);
>> - // Priority is always <= 65535 (enforced by sema)..
>> + // Priority is always <= 65535 (enforced by sema).
>> PrioritySuffix = std::string(6-PrioritySuffix.size(), '0')+PrioritySuffix;
>> llvm::Function *Fn =
>> CreateGlobalInitOrDestructFunction(*this, FTy,
>> @@ -376,8 +377,20 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
>> }
>> }
>>
>> - llvm::Function *Fn =
>> - CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
>> + // Include the filename in the symbol name. Including "sub_" matches gcc and
>> + // makes sure these symbols appear lexicographically behind the symbols with
>> + // priority emitted above.
>> + SourceManager &SM = Context.getSourceManager();
>> + SmallString<128> FileName(llvm::sys::path::filename(
>> + SM.getFileEntryForID(SM.getMainFileID())->getName()));
>> + for (size_t i = 0; i < FileName.size(); ++i) {
>> + // Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
>> + // to be the set of C preprocessing numbers.
>> + if (!isPreprocessingNumberBody(FileName[i]))
>> + FileName[i] = '_';
>> + }
>> + llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
>> + *this, FTy, llvm::Twine("_GLOBAL__sub_I_", FileName));
>>
>> CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits);
>> AddGlobalCtor(Fn);
>>
>> Modified: cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp Tue May 6 15:32:45 2014
>> @@ -11,6 +11,6 @@ void* bar() { return a; }
>> // CHECK: load i8** @foo
>> // CHECK: ret void
>>
>> -// CHECK-LABEL: define internal void @_GLOBAL__I_a
>> +// CHECK-LABEL: define internal void @_GLOBAL__sub_I_deferred_global_init.cpp
>> // CHECK: call void @__cxx_global_var_init()
>> // CHECK: ret void
>>
>> Modified: cfe/trunk/test/CodeGenCXX/global-init.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/global-init.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/global-init.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/global-init.cpp Tue May 6 15:32:45 2014
>> @@ -195,11 +195,11 @@ namespace test7 {
>> // CHECK-NEXT: sub
>> // CHECK-NEXT: store i32 {{.*}}, i32* @_ZN5test1L1yE
>>
>> -// CHECK: define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {
>> +// CHECK: define internal void @_GLOBAL__sub_I_global_init.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
>> // CHECK: call void [[TEST1_Y_INIT]]
>> // CHECK: call void [[TEST1_Z_INIT]]
>>
>> // rdar://problem/8090834: this should be nounwind
>> -// CHECK-NOEXC: define internal void @_GLOBAL__I_a() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {
>> +// CHECK-NOEXC: define internal void @_GLOBAL__sub_I_global_init.cpp() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" {
>>
>> // CHECK-NOEXC: attributes [[NUW]] = { nounwind }
>>
>> Modified: cfe/trunk/test/CodeGenCXX/globalinit-loc.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/globalinit-loc.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/globalinit-loc.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/globalinit-loc.cpp Tue May 6 15:32:45 2014
>> @@ -4,9 +4,9 @@
>> // Verify that the global init helper function does not get associated
>> // with any source location.
>> //
>> -// CHECK: define internal void @_GLOBAL__I_a
>> +// CHECK: define internal void @_GLOBAL__sub_I_globalinit_loc.cpp
>> // CHECK: !dbg ![[DBG:.*]]
>> -// CHECK: "_GLOBAL__I_a", i32 0, {{.*}}, i32 0} ; [ DW_TAG_subprogram ] [line 0] [local] [def]
>> +// CHECK: "_GLOBAL__sub_I_globalinit_loc.cpp", i32 0, {{.*}}, i32 0} ; [ DW_TAG_subprogram ] [line 0] [local] [def]
>> // CHECK: ![[DBG]] = metadata !{i32 0, i32 0,
>> # 99 "someheader.h"
>> class A {
>>
>> Modified: cfe/trunk/test/CodeGenCXX/init-priority-attr.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/init-priority-attr.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/init-priority-attr.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/init-priority-attr.cpp Tue May 6 15:32:45 2014
>> @@ -27,7 +27,7 @@ public:
>>
>> A C::a = A();
>>
>> -// CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 200, void ()* @_GLOBAL__I_000200 }, { i32, void ()* } { i32 300, void ()* @_GLOBAL__I_000300 }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
>> +// CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 200, void ()* @_GLOBAL__I_000200 }, { i32, void ()* } { i32 300, void ()* @_GLOBAL__I_000300 }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__sub_I_init_priority_attr.cpp }]
>>
>> // CHECK: _GLOBAL__I_000200()
>> // CHECK: _Z3fooi(i32 3)
>> @@ -38,7 +38,7 @@ A C::a = A();
>> // CHECK-NEXT: _Z3fooi(i32 1)
>> // CHECK-NEXT: ret void
>>
>> -// CHECK: _GLOBAL__I_a()
>> +// CHECK: _GLOBAL__sub_I_init_priority_attr.cpp()
>> // CHECK: _Z3fooi(i32 1)
>> // CHECK-NEXT: _Z3fooi(i32 4)
>> // CHECK-NEXT: ret void
>>
>> Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Tue May 6 15:32:45 2014
>> @@ -2,7 +2,7 @@
>>
>> // CHECK: @llvm.global_ctors = appending global [2 x { i32, void ()* }]
>> // CHECK: [{ i32, void ()* } { i32 65535, void ()* @"\01??__Efoo@?$B at H@@2VA@@A at YAXXZ"
>> -// CHECK: { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
>> +// CHECK: { i32, void ()* } { i32 65535, void ()* @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp }]
>>
>> struct S {
>> S();
>> @@ -160,7 +160,7 @@ void force_usage() {
>> // CHECK: call x86_thiscallcc void @"\01??1A@@QAE at XZ"{{.*}}foo
>> // CHECK: ret void
>>
>> -// CHECK: define internal void @_GLOBAL__I_a() [[NUW]] {
>> +// CHECK: define internal void @_GLOBAL__sub_I_microsoft_abi_static_initializers.cpp() [[NUW]] {
>> // CHECK: call void @"\01??__Es@@YAXXZ"()
>> // CHECK: ret void
>>
>>
>> Modified: cfe/trunk/test/CodeGenCXX/runtimecc.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/runtimecc.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/runtimecc.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/runtimecc.cpp Tue May 6 15:32:45 2014
>> @@ -45,7 +45,7 @@ namespace test1 {
>>
>> // CHECK: declare arm_aapcscc void @__cxa_throw(i8*, i8*, i8*)
>>
>> -// CHECK-LABEL: define internal arm_aapcscc void @_GLOBAL__I_a()
>> +// CHECK-LABEL: define internal arm_aapcscc void @_GLOBAL__sub_I_runtimecc.cpp()
>> // CHECK: call arm_aapcscc void @__cxx_global_var_init()
>>
>>
>>
>> Modified: cfe/trunk/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/static-member-variable-explicit-specialization.cpp Tue May 6 15:32:45 2014
>> @@ -19,14 +19,14 @@ template<> int A<bool>::a = 10;
>> // CHECK: { i32, void ()* } { i32 65535, void ()* @[[unordered4:[^ ]*]] },
>> // CHECK: { i32, void ()* } { i32 65535, void ()* @[[unordered5:[^ ]*]] },
>> // CHECK: { i32, void ()* } { i32 65535, void ()* @[[unordered6:[^ ]*]] },
>> -// CHECK: { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
>> +// CHECK: { i32, void ()* } { i32 65535, void ()* @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp }]
>>
>> template int A<short>::a; // Unordered
>> int b = foo();
>> int c = foo();
>> int d = A<void>::a; // Unordered
>>
>> -// An explicit specialization is ordered, and goes in __GLOBAL_I_a.
>> +// An explicit specialization is ordered, and goes in __GLOBAL_sub_I_static_member_variable_explicit_specialization.cpp.
>> template<> struct A<int> { static int a; };
>> int A<int>::a = foo();
>>
>> @@ -82,7 +82,7 @@ template int b::i<int>;
>> // CHECK: store {{.*}} @_Z1xIcE
>> // CHECK: ret
>>
>> -// CHECK: define internal void @_GLOBAL__I_a()
>> +// CHECK: define internal void @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp()
>> // We call unique stubs for every ordered dynamic initializer in the TU.
>> // CHECK: call
>> // CHECK: call
>>
>> Modified: cfe/trunk/test/CodeGenObjCXX/arc-globals.mm
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-globals.mm?rev=208128&r1=208127&r2=208128&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenObjCXX/arc-globals.mm (original)
>> +++ cfe/trunk/test/CodeGenObjCXX/arc-globals.mm Tue May 6 15:32:45 2014
>> @@ -19,7 +19,7 @@ id global_obj = getObject();
>> // CHECK-NEXT: ret void
>> id global_obj2 = getObject();
>>
>> -// CHECK-LABEL: define internal void @_GLOBAL__I_a
>> +// CHECK-LABEL: define internal void @_GLOBAL__sub_I_arc_globals.mm
>> // CHECK: call i8* @objc_autoreleasePoolPush()
>> // CHECK-NEXT: call void @__cxx_global_var_init
>> // CHECK-NEXT: call void @__cxx_global_var_init1
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list