The way we handle ONLY_IF_RO/OLY_IF_RW constraints in
processSectionCommands is a bit tricky. If input sections
does no satisfy given constraint we remove command from
commands list. It seems too complex, what we can do instead
is to make the OutputCommand empty. So that at later steps
LLD will remove it just like it deal with other empty output commands.
That allows to simplify the loop a bit.
Details
Diff Detail
Event Timeline
Your change to ELF/LinkerScript.cpp looks good, but the other change needs improving.
ELF/OutputSections.cpp | ||
---|---|---|
119–120 | This function is addSection, which is supposed to add a section to an output section, right? Adding this piece of code which is not related to adding sections to this function is not a good idea. This is how this function organically grown (and I took quite a long time to clean it up), so when you add code to some function, please stop and think if what you are about to do is semantically correct. |
ELF/OutputSections.cpp | ||
---|---|---|
119–120 | This function not only adds section, but also initializes and changes the Type. We can split this code (lines 97-120) to something like setSectionType, but that would be separate refactoring change. |
ELF/OutputSections.cpp | ||
---|---|---|
119–120 | George, I knew that was the reason why you added this piece of code to this function, but this is not right. If addSection mutates its class' Type based on a given argument, it is fine, but if it does something that is not related to a given section every time you pass a section to the function, something's not correct. |
This function is addSection, which is supposed to add a section to an output section, right? Adding this piece of code which is not related to adding sections to this function is not a good idea. This is how this function organically grown (and I took quite a long time to clean it up), so when you add code to some function, please stop and think if what you are about to do is semantically correct.