@@ -2103,23 +2103,10 @@ void ModuleAddressSanitizer::InstrumentGlobalsELF(
2103
2103
SetComdatForGlobalMetadata (G, Metadata, UniqueModuleId);
2104
2104
}
2105
2105
2106
- // This should never be called when there are no globals, by the logic that
2107
- // computes the UniqueModuleId string, which is "" when there are no globals.
2108
- // It's important that this path is only used when there are actually some
2109
- // globals, because that means that there will certainly be a live
2110
- // `asan_globals` input section at link time and thus `__start_asan_globals`
2111
- // and `__stop_asan_globals` symbols will definitely be defined at link time.
2112
- // This means there's no need for the references to them to be weak, which
2113
- // enables better code generation because ExternalWeakLinkage implies
2114
- // isInterposable() and thus requires GOT indirection for PIC. Since these
2115
- // are known-defined hidden/dso_local symbols, direct PIC accesses without
2116
- // dynamic relocation are always sufficient.
2117
- assert (!MetadataGlobals.empty ());
2118
- assert (!UniqueModuleId.empty ());
2119
-
2120
2106
// Update llvm.compiler.used, adding the new metadata globals. This is
2121
2107
// needed so that during LTO these variables stay alive.
2122
- appendToCompilerUsed (M, MetadataGlobals);
2108
+ if (!MetadataGlobals.empty ())
2109
+ appendToCompilerUsed (M, MetadataGlobals);
2123
2110
2124
2111
// RegisteredFlag serves two purposes. First, we can pass it to dladdr()
2125
2112
// to look up the loaded image that contains it. Second, we can store in it
@@ -2132,18 +2119,15 @@ void ModuleAddressSanitizer::InstrumentGlobalsELF(
2132
2119
ConstantInt::get (IntptrTy, 0 ), kAsanGlobalsRegisteredFlagName );
2133
2120
RegisteredFlag->setVisibility (GlobalVariable::HiddenVisibility);
2134
2121
2135
- // Create start and stop symbols. These are known to be defined by
2136
- // the linker, see comment above.
2137
- auto MakeStartStopGV = [&](const char *Prefix) {
2138
- GlobalVariable *StartStop =
2139
- new GlobalVariable (M, IntptrTy, false , GlobalVariable::ExternalLinkage,
2140
- nullptr , Prefix + getGlobalMetadataSection ());
2141
- StartStop->setVisibility (GlobalVariable::HiddenVisibility);
2142
- assert (StartStop->isImplicitDSOLocal ());
2143
- return StartStop;
2144
- };
2145
- GlobalVariable *StartELFMetadata = MakeStartStopGV (" __start_" );
2146
- GlobalVariable *StopELFMetadata = MakeStartStopGV (" __stop_" );
2122
+ // Create start and stop symbols.
2123
+ GlobalVariable *StartELFMetadata = new GlobalVariable (
2124
+ M, IntptrTy, false , GlobalVariable::ExternalWeakLinkage, nullptr ,
2125
+ " __start_" + getGlobalMetadataSection ());
2126
+ StartELFMetadata->setVisibility (GlobalVariable::HiddenVisibility);
2127
+ GlobalVariable *StopELFMetadata = new GlobalVariable (
2128
+ M, IntptrTy, false , GlobalVariable::ExternalWeakLinkage, nullptr ,
2129
+ " __stop_" + getGlobalMetadataSection ());
2130
+ StopELFMetadata->setVisibility (GlobalVariable::HiddenVisibility);
2147
2131
2148
2132
// Create a call to register the globals with the runtime.
2149
2133
IRB.CreateCall (AsanRegisterElfGlobals,
0 commit comments