[llvm-dev] Building LLVM's fuzzers
Justin Bogner via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 24 16:22:34 PDT 2017
Peter Collingbourne <peter at pcc.me.uk> writes:
> On Thu, Aug 24, 2017 at 3:21 PM, Kostya Serebryany via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>>
>>
>> On Thu, Aug 24, 2017 at 3:20 PM, Justin Bogner <mail at justinbogner.com>
>> wrote:
>>
>>> I think the simplest fix is something like this:
>>>
>>> diff --git a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>>> b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>>> index c6f0d17f8fe..e81957ab80a 100644
>>> --- a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>>> +++ b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>>> @@ -256,6 +256,7 @@ SanitizerCoverageModule::CreateSecStartEnd(Module
>>> &M, const char *Section,
>>> new GlobalVariable(M, Ty, false, GlobalVariable::ExternalLinkage,
>>> nullptr, getSectionEnd(Section));
>>> SecEnd->setVisibility(GlobalValue::HiddenVisibility);
>>> + appendToUsed(M, {SecStart, SecEnd});
>>>
>>> return std::make_pair(SecStart, SecEnd);
>>> }
>>>
>>> I'm trying it out now.
>>>
>>
>> LGTM (if this works), thanks!
>
> I wouldn't expect that to work because for ELF targets llvm.used has no
> effect on the object file (only on the optimizer).
Interesting. Appending to llvm.used is the only thing that's done to
keep variables alive in the PGO instrumentation, and it seems to work
in practice.
In any case, the first patch handled the wrong variables - those section
start and end variables aren't stripped. The symbol that's being
stripped is actually a global array with private linkage inside the
section, and the following patch works on macOS:
diff --git a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index c6f0d17f8fe..fdf265143fd 100644
--- a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -557,6 +557,10 @@ void SanitizerCoverageModule::CreatePCArray(Function &F,
FunctionPCsArray->setInitializer(
ConstantArray::get(ArrayType::get(Int8PtrTy, N), PCs));
FunctionPCsArray->setConstant(true);
+
+ // We don't reference the PCs array in any of our runtime functions, so we
+ // need to prevent it from being dead stripped.
+ appendToUsed(*F.getParent(), {FunctionPCsArray});
}
void SanitizerCoverageModule::CreateFunctionLocalArrays(
I'm building on linux now to see what happens.
More information about the llvm-dev
mailing list