This is for my GSoC project to librarify llvm-objcopy. See bug 41044
The current code is in a very rough state and is a work in progress (WIP). It will of course be different however this is just for a check in and giving an example of renaming sections. This approach does so by keeping a map of modified sections which allows sections to be immutable but also seemingly modified in place. For example, if we rename section at index 1, then the iterator (hypothetical at this point but see MutableObject::getSection() ) at 1 will expose the new one. This lets sections be both immutable and rewritten to the file in their original order. Also I like that in this way methods like renameSection aren't themselves virtual, of course relying on virtual methods but I think this is a good start for code reuse.
I have never been great at designing class hierarchies and would love tips on how to structure the relationship between the classes. Jake had previously suggested having a hierarchy based on semantic meaning not implementation details, clearly there is a lot of work to be done here, I'm not blind to the fact that this code is a very rough draft.
Of note, something like SectionBase::clone() feels really bad to me. I don't really know a better way to do this though.
I would also say to ignore access modifiers for now, and also that everything is in the header file, I know this isn't conformant with the coding standards but I figured this was easier to keep in one file for now.
Even though this is WIP, you should probably include the LLVM license at the top of the new files, as this is technically an LLVM contribution already.