Refactor createBinaryContext and RewriteInstance/MachORewriteInstance
constructors to report an error in a library and fuzzer-friendly way instead of
returning a nullptr or exiting.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Instead of having Error as out parameter in constructors, what about refactoring these classes to put this complex constructor logic into a separate "initialize" member function?
This approach is sensible and pretty similar, but having an Error as out parameter looks like a more idiomatic solution. It's outlined in the Programmers Manual, the chapter about error handling in fallible constructors: https://llvm.org/docs/ProgrammersManual.html#fallible-constructors
Although I do see the "initialize" method used by COFFObjectFile. To note, even in this class, initialize is then used (only) by create method which wraps both constructor and initialize method:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Object/COFFObjectFile.cpp#L711
So the constructor is always wrapped, similar to what I do in this diff. I don't have a strong preference for fallible constructor over the initialize method, but the latter seems more idiomatic and widespread in the codebase. If you can list one specific reason for initialize method, I'll adjust this diff.
Sounds good. There is one nit to fix.
bolt/include/bolt/Rewrite/RewriteInstance.h | ||
---|---|---|
48–52 | Insert a newline after this line to mirror MachORewriteInstance.h |
Insert a newline after this line to mirror MachORewriteInstance.h