I have a binary object that was generated on an SGI 64bit machine using a MIPSpro compiler. I am trying to read this binary object on a 64bit x86_64 machine running RHEL 6.7. The structure of the object is something like like
class A {
public:
A(){
a_ = 1;
}
A(int a){
a_ = a;
}
virtual ~A();
protected:
int a_;
};
class B : public A {
public:
// Constructors, methods, etc
B(double b, int a){
b_ = b;
a_ = a;
}
virtual ~B();
private:
double b_;
};
A::~A(){}
B::~B(){}
After reading the binary file, a swapping the bytes (due to the endianness) I find that b
is correct but a
is misaligned, indicating the data is misaligned with my current build.
I have two question about this. Firstly, how does the MIPS Pro compiler align its fields and how is that different to the way gcc
does it. I am interested in the case of inherited classes. Secondly, is there an option in gcc
or C++ that can force the alignment to be the same as the way MIPS does it?
Update 1: For additional clarification, the code was compiled on MIPS ABI n64. I have access to the original C++ source code but I can't change it on the MIPS machine. I am constrained to reading the binary on x86_64.
Update 2:
I ran sizeof commands before and after adding a virtual
destructor to both my classes on both machines.
On MIPS and x86_64, the output before the virtual directive was
size of class A: 4
size of class B: 16
After adding the virtual
method, on SGI MIPS the output is
size of class A: 8
size of class B: 16
and on x86-64 Linux:
size of class A: 16
size of class B: 24
Looks like the way virtual method (or is it just methods in general?) is processed on these machines is different. Any ideas why or how to get around this problem?