[llvm-commits] [llvm] r169438 - /llvm/trunk/tools/llvm-objdump/COFFDump.cpp
Kai
kai at redstar.de
Fri Dec 7 05:58:32 PST 2012
Hi Michael!
The attached patch removes the warning. I now use the memory address of
the member and the base address of the section to calculate the
distances. Please have a look at it. Thanks.
Regards
Kai
On 05.12.2012 23:55, Michael Spencer wrote:
>
> Kai,
>
> Please fix this in a less hacky way.
>
> The problem is that RuntimeFunction is not a POD type in c++03, and
> offsetof is only well defined for POD types. clang warns on this in
> c++03 mode.
>
> - Michael Spencer
>
-------------- next part --------------
diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp
index 30faecb..b44ac6e 100644
--- a/tools/llvm-objdump/COFFDump.cpp
+++ b/tools/llvm-objdump/COFFDump.cpp
@@ -30,6 +30,13 @@ using namespace llvm;
using namespace object;
using namespace llvm::Win64EH;
+// Calculates the offset of member using base as base address.
+// The implementation of Endian.h guaranties that the offsets are right.
+static uint64_t offsetOf(const RuntimeFunction *base,
+ const support::ulittle32_t *member) {
+ return reinterpret_cast<size_t>(member) - reinterpret_cast<size_t>(base);
+}
+
// Returns the name of the unwind code.
static StringRef getUnwindCodeTypeName(uint8_t Code) {
switch(Code) {
@@ -270,33 +277,30 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
reinterpret_cast<const RuntimeFunction *>(Contents.data()),
Contents.size() / sizeof(RuntimeFunction));
for (const RuntimeFunction *I = RFs.begin(), *E = RFs.end(); I < E; ++I) {
- const uint64_t SectionOffset = std::distance(RFs.begin(), I)
- * sizeof(RuntimeFunction);
-
outs() << "Function Table:\n";
outs() << " Start Address: ";
- printCOFFSymbolAddress(outs(), Rels, SectionOffset +
- /*offsetof(RuntimeFunction, StartAddress)*/ 0,
+ printCOFFSymbolAddress(outs(), Rels,
+ offsetOf(RFs.begin(), &I->StartAddress),
I->StartAddress);
outs() << "\n";
outs() << " End Address: ";
- printCOFFSymbolAddress(outs(), Rels, SectionOffset +
- /*offsetof(RuntimeFunction, EndAddress)*/ 4,
+ printCOFFSymbolAddress(outs(), Rels,
+ offsetOf(RFs.begin(), &I->EndAddress),
I->EndAddress);
outs() << "\n";
outs() << " Unwind Info Address: ";
- printCOFFSymbolAddress(outs(), Rels, SectionOffset +
- /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
+ printCOFFSymbolAddress(outs(), Rels,
+ offsetOf(RFs.begin(), &I->UnwindInfoOffset),
I->UnwindInfoOffset);
outs() << "\n";
ArrayRef<uint8_t> XContents;
uint64_t UnwindInfoOffset = 0;
- if (error(getSectionContents(Obj, Rels, SectionOffset +
- /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
+ if (error(getSectionContents(Obj, Rels,
+ offsetOf(RFs.begin(), &I->UnwindInfoOffset),
XContents, UnwindInfoOffset))) continue;
if (XContents.empty()) continue;
More information about the llvm-commits
mailing list