This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Don't instrument globals from __objc_classname
ClosedPublic

Authored by kubamracek on Dec 2 2014, 3:30 PM.

Details

Summary

Fixes https://code.google.com/p/address-sanitizer/issues/detail?id=360 – Using Obj-C blocks triggers a false-positive ODR violation

The change in r221451 (http://llvm.org/viewvc/llvm-project?view=revision&revision=221451) caused Obj-C related global constants to be instrumented, but the linker rearranges the sections, so the redzones break. We already added a check to skip objc_methname section from being instrumented because of this, see r221480 (http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?view=diff&r1=221479&r2=221480&pathrev=221480). The same issue still exists for class names in objc_classname, this patch skips the __objc_classname section from being instrumented, as well.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 16834.Dec 2 2014, 3:30 PM
kubamracek retitled this revision from to [compiler-rt] Don't instrument globals from __objc_classname.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added reviewers: samsonov, glider.
kubamracek added subscribers: Unknown Object (MLST), samsonov, glider and 2 others.
samsonov accepted this revision.Dec 2 2014, 5:32 PM
samsonov edited edge metadata.

LGTM, but let's see if glider@ has anything to add.

This revision is now accepted and ready to land.Dec 2 2014, 5:32 PM
kledzik added a subscriber: kledzik.Dec 2 2014, 5:44 PM

Can you just generalize ShouldInstrumentGlobal() to return false for all cstring_literals sections? The linker is always going to coalesce sections of that type.

kubamracek updated this revision to Diff 16845.Dec 2 2014, 6:27 PM
kubamracek edited edge metadata.

Changing the patch to disable instrumentation of all cstring_literals sections.

majnemer added inline comments.
lib/Transforms/Instrumentation/AddressSanitizer.cpp
1047

This is not reliable, it could end with ", cstring_literals".

Can you please use MCSectionMachO::ParseSectionSpecifier to parse the section string instead?

kubamracek updated this revision to Diff 16851.Dec 2 2014, 9:27 PM

Modified the patch to use MCSectionMachO::ParseSectionSpecifier to correctly parse the section name, segment name and attributes.

I had to modify a couple of function prototypes to pass the llvm::Triple in order to avoid creating the Triple object for each global. Not sure if there's an easier way.

glider accepted this revision.Dec 3 2014, 9:34 AM
glider edited edge metadata.

LGTM

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1271–1272

How about making TargetTriple a class member?

Why does ShouldInstrumentGlobal need a triple argument? GlobalVariable has a getParent method which will return the Module.

kubamracek updated this revision to Diff 16870.Dec 3 2014, 10:13 AM
kubamracek edited edge metadata.

Making TargetTriple a class member.

In D6488#17, @majnemer wrote:

Why does ShouldInstrumentGlobal need a triple argument? GlobalVariable has a getParent method which will return the Module.

Because Module only stores the triple as a string, and I wanted to avoid parsing the string for every single global.

ygribov added a subscriber: ygribov.Dec 4 2014, 6:50 AM

Could someone comment on issues raised in GCC Bugzilla about related bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63888 ?

Is it okay to commit this patch?

majnemer accepted this revision.Dec 5 2014, 11:45 AM
majnemer added a reviewer: majnemer.

I'm cool with it and @glider and @samsonov seem to be as well.

kubamracek closed this revision.Dec 5 2014, 1:05 PM

Landed in r223513 and r223514.