The file offset code is repeated in nearly identical form for every derivation of SectionEntry, so make it into a method in SectionEntry instead.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
125 | Generally best to pass primitive scalars like this by value when they are read-only | |
125 | As there are already virtual methods I don't think the cost of making this virtual is too high, and it is what I would expect. I'd be surprised if a call to SectionEntry::advanceFileOffset was just wrong if the object were a DwarfSectionEntry. Alternatively this method could make a call to a virtual method which returns the "RawSize" of the section, which appears to be different for DwarfSectionEntry (i.e. for every other section it is Size, for DwarfSectionEntry it is MemorySize) | |
193 | I'm not sure why DwarfSectionEntry doesn't have a reset override which also clears MemorySize? |
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
125 | Would it make more sense for this function to return the new RawPointer instead of using reference to the variable? | |
201 | I think this special treatment of Dwarf sections is unnecessary, but changing it probably needs a separate patch. Loadable sections (e.g., .text, .data) may need to be aligned. Other sections generally don't need any alignment, but if they're aligned, the RawPointer should be adjusted before writing the section. Then a dwarf-specific function wouldn't be needed. Also when compiling in 64-bit mode, the assert can never be triggered, because MaxRawDataSize is UINT64_MAX. |
LGTM, although I'm also fine with a more "functional" approach where RawPointer is returned rather than mutated via reference! I'll leave that between you and @stephenpeckham
Also, if you want to add a TODO for the cleanup @stephenpeckham suggests feel free to do so when landing! I'm at least happy that the function is now virtual, rather than just aliased in a subclass.
Generally best to pass primitive scalars like this by value when they are read-only