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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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 | ||
---|---|---|
194 | 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 | ||
980–982 | This comment should be moved inside the if | |
bolt/lib/Core/Exceptions.cpp | ||
123 | 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. |
bolt/lib/Core/BinaryContext.cpp | ||
---|---|---|
183 | BTW, is this still relevant? What prevents us from using absptr on X86(at least for non-pie)? |
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.
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)