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