[LLVMdev] Questions about llvm/Object/COFF.h
Marshall Clow
mclow.lists at gmail.com
Mon Jun 11 17:41:21 PDT 2012
So, I'm trying to use this file to look inside COFF files.
Got the header. OK.
Now I want to look at the sections.
Look, there's a section iterator. I can use that!
So, I write:
for (llvm::object::section_iterator iter = Obj.begin_sections (); iter != Obj.end_sections(); ++iter )
and it doesn't compile. There's no ++ for section iterators.
Apparently, you're supposed to write.
for (llvm::object::section_iterator iter = Obj.begin_sections (); iter != Obj.end_sections(); iter.increment(ec))
Srsly?
[ And - how do I go from a section_iterator to a coff_section ? ]
While I'm puzzling over that, I look some more, and I see:
error_code getSection(int32_t index, const coff_section *&Res) const;
Cool. (A bit weird; why a signed index?, but whatever)
So I write:
const llvm::object::coff_section *sect;
for (std::size_t i = 0; i < NumSections; ++i)
Obj.getSection(i, sect);
And my program dies with a segmentation fault.
Turns out that sect == NULL.
More looking, I see that the sections are numbered 1 … N, not 0 ... N-1
Now I'm really really confused. Why?
BTW - patch attached to add pre-increment to llvm::content_iterator (which is the template base for section_iterator, etc)
-- Marshall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: section-iter.patch
Type: application/octet-stream
Size: 453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120611/5d4dea4b/attachment.obj>
-------------- next part --------------
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists at gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
More information about the llvm-dev
mailing list