This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer] Generalize the code for getting the previous offset for different architectures
ClosedPublic

Authored by george.karpenkov on Oct 9 2018, 1:55 PM.

Details

Summary

Without this change, tests in coverage.test and dump_coverage.test are failing on non-x86_64 platforms.
The diff is copied from sanitizer_common library, an alternative would be to link it together with libFuzzer.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added subscribers: Restricted Project, fedor.sergeev. · View Herald TranscriptOct 9 2018, 1:55 PM

@morehouse After this and the linked change, it should be safe to re-enable coverage.test on AArch64.

george.karpenkov added a reviewer: Dor1s.
Dor1s accepted this revision.Oct 9 2018, 2:50 PM

I should admit that I'm not familiar with ARM offsets, but since the change fixes the test, LGTM.

compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
202 ↗(On Diff #168874)

Are you sure you need -3 here, not -2? I'm definitely not an expert here, so it's more like a sanity check question :)

>>> hex((0x122 - 3) & (~1))
'0x11e'
>>> hex((0x122 - 2) & (~1))
'0x120'
213 ↗(On Diff #168874)

some comment here might be useful too

This revision is now accepted and ready to land.Oct 9 2018, 2:50 PM
compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
202 ↗(On Diff #168874)

I've copied this code from sanitizer_common/sanitizer_stracktrace.h.

Another possibility is to link to sanitizer_common instead, but I think at one point @kcc was against that (has that changed?)

@Dor1s I have definitely seen this error, but at some point it disappeared. I do not recall exactly the circumstances, maybe it appeared when the compiler version did not match exactly the runtime version.

@Dor1s this can't land without D53039, does that look fine as well?

morehouse added inline comments.Oct 9 2018, 5:23 PM
compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
221 ↗(On Diff #168874)

Could we avoid putting ifdefs here? Maybe they could go in FuzzerDefs.h.

compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
221 ↗(On Diff #168874)

I don't think this is a good idea.

  1. FuzzerDefs contains constants, this is not a constant.
  2. As the code is cloned, it would be harder to maintain parity with the code in sanitizer_common if it's significantly changed.
morehouse accepted this revision.Oct 9 2018, 5:46 PM
morehouse added inline comments.
compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
221 ↗(On Diff #168874)

Ok, then let's add a comment saying where this code came from.

compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
221 ↗(On Diff #168874)

OK!

This revision was automatically updated to reflect the committed changes.