This is an archive of the discontinued LLVM Phabricator instance.

[BTF] Fix BTFParserTest.cpp for unaligned access after D149058
ClosedPublic

Authored by eddyz87 on Jul 13 2023, 4:05 AM.

Details

Summary

Test bot reported an issue with unit tests for D149058 in [1]:

[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from BTFParserTest
[ RUN      ] BTFParserTest.simpleCorrectInput
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp:141:33:
runtime error: upcast of misaligned address 0x7facce60411f for type 'llvm::SmallString<0>', which requires 8 byte alignment
0x7facce60411f: note: pointer points here
 64 00 00 00 37  41 60 ce ac 7f 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp:141:33

The issue is caused by attribute "packed" used for too many things:

#pragma pack(push, 1)
struct MockData1 {
  struct B {
    ...
  } BTF;
  struct E {
    ...
  } Ext;

  int BTFSectionLen = sizeof(BTF);
  int ExtSectionLen = sizeof(Ext);

  SmallString<0> Storage;
  std::unique_ptr<ObjectFile> Obj;

}
#pragma pack(pop)

Access to unaligned pointers in Storage/Obj causes unaligned
access errors.

To fix this #pragma directives are pushed invards to apply only to B
and E definitions.

[1] https://lab.llvm.org/buildbot/#/builders/5/builds/35040

Diff Detail

Event Timeline

eddyz87 created this revision.Jul 13 2023, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 4:05 AM
Herald added a subscriber: pengfei. · View Herald Transcript
luporl added a subscriber: luporl.Jul 13 2023, 4:56 AM

I've tested this patch and it also fixes unit tests for this ARM bot:
https://lab.llvm.org/buildbot/#/builders/245/builds/10973

eddyz87 published this revision for review.Jul 13 2023, 5:45 AM
eddyz87 added reviewers: luporl, MaskRay.
eddyz87 added a subscriber: MaskRay.

Hi @luporl,

I've tested this patch and it also fixes unit tests for this ARM bot:
https://lab.llvm.org/buildbot/#/builders/245/builds/10973

Thank you for testing it, the pre-merge build also finished green. May I ask you to be a formal reviewer?
@MaskRay agreed with these changes here.

Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 5:45 AM
luporl accepted this revision.Jul 13 2023, 6:28 AM

LGTM, thanks for the fix.

This revision is now accepted and ready to land.Jul 13 2023, 6:28 AM