This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Preserve original LSDA type encoding
ClosedPublic

Authored by treapster on Aug 23 2022, 9:59 AM.

Details

Summary

In non-pie binaries BOLT unconditionally converted type encoding from indirect to absptr, which broke std exceptions since pointers to their typeinfo were only assigned at runtime in .data section. In this patch we preserve original encoding so that indirect remains indirect and can be resolved at runtime, and absolute remains absolute.

Diff Detail

Event Timeline

treapster created this revision.Aug 23 2022, 9:59 AM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: ayermolo. · View Herald Transcript
treapster requested review of this revision.Aug 23 2022, 9:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2022, 9:59 AM
treapster added a reviewer: yota9.

clang-format

Interesting.. Thanks for presenting this testcase and providing a fix!

@maksfb Do you recall why were we hardcoding the encoding of types?

I'm taking a guess that we wanted to restrict the encoding to the ones we know how to emit in BinaryEmitter, but we do support emitting both pic/non-pic - meaning, indirect + pcrel, as well as absolute. Taking a look at BinaryEmitter.cpp:1024, which is responsible for actually encoding the type tables, what if we don't support outputting the format seen in the input? Will we crash with "unsupported TTypeEncoding"? Or are we covering every possible input type encoding?

bolt/include/bolt/Core/BinaryFunction.h
200

I think it makes more sense to move this line closer to "LSDAAddress" declaration in this same class, and define a getter member functions, since this will be used outside of this class (in binary emitter)

bolt/lib/Core/BinaryEmitter.cpp
973–974

This comment should be moved inside the if

bolt/lib/Core/Exceptions.cpp
123–124

The changes to this function will generate this->LSDATypeEncoding access all over the parser (accessing a heap object).

I guess we can keep the original code, which is a const variable, and just add a new line here setting LSDATypeEncoding to TTypeEncoding.

treapster updated this revision to Diff 455101.Aug 24 2022, 1:09 AM
treapster marked 3 inline comments as done.
treapster updated this revision to Diff 455102.Aug 24 2022, 1:19 AM

clang-format

treapster added inline comments.Aug 24 2022, 2:24 AM
bolt/lib/Core/BinaryContext.cpp
183

BTW, is this still relevant? What prevents us from using absptr on X86(at least for non-pie)?

maksfb accepted this revision.Sep 8 2022, 2:59 PM

This looks good to me. Thanks! I don't think there was any strong reason to enforce the type of encoding in the first place other than simplicity of the implementation.

This revision is now accepted and ready to land.Sep 8 2022, 2:59 PM