Patch removes one of OutputSectionFactory::addInputSec methods.
That allows to simplify reporting of discarded sections and
should help to D37561.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
The new code is hard to understand due to a pointer to a pointer to something. I think you can do this without two levels of pointer indirection.
After playing with code I "re-invented" nicest way: just leave everything as is and make one of addInputSec
to be static helper. That way public addInputSec becomes the only way to add input section and it is able to report
discarded sections early enough, what solves initial problem.
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) | Instead of mutating a given pointer through a reference, this function should take OutputSection * and returns OutputSection *. |
- Addressed comments.
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) | Ok, but personally I find such constructions a bit odd. |
LGTM
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) | Really? Then that's pretty different from my taste. Mutating an argument pointer through a reference is pretty tricky, and on the other hand, returning a pointer is very normal, straightforward and functional-ish. |
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) | Returning pointer itself - yes, but not in constructions when it is on both sides like |
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) | IMO there's a big difference. The expression Sec = addSection(IS, OutsecName, Sec) is easier to understand because within the narrow local context, we know that Sec is a reference to a pointer, so what that expression does is obvious: Sec is updated. On the other hand, if you implicitly mutate Sec through a reference, that is not obvious at all. You cannot assume that people who are reading this piece of code already know what exactly addSection does, so you want to make it easy to guess. One way of doing it is to make something explicitly. Generally, you want to avoid mutating variables implicitly through references unless there's other reason to do that. In addition to that, the previous code OutputSection *Out = nullptr; addSection(IS, OutsecName, Out); was ugly. I was tempted to remove Out variable, but I couldn't because it has to be an lvalue. Overall, I strongly believe that changing this function to return a pointer instead of mutating an argument via a reference is pretty much reasonable change which improves code quality. |
ELF/OutputSections.cpp | ||
---|---|---|
208–209 ↗ | (On Diff #115017) |
Issue is here for me. Such expression does not give guarantee that Sec is updated (I mean not variable itself, but instance). It can return new updated Sec but also may return the same one from right part unchanged. What is worse it may update Sec from argument and return different Sec at the same time. |