program:
#include <stdio.h>
#include <sstream>
int main()
{
std::stringstream ss;
ss << "hello world " << 1234 << "\n";
std::string str = ss.str();
printf(str.c_str());
return 0;
}
makefile:
CC=/usr/local/gcc-4.6.2/bin/g++
CFLAGS=-g -c -W -m32 -Wa,-mtune=pentiumiii
LINKFLAGS=-m32 -static-libgcc -static-libstdc++ -Wl,-rpath,./runtime,--dynamic-linker,./runtime/ld-linux.so.2
all:test
test: list_test.o
$(CC) $(LINKFLAGS) list_test.o -o test
list_test.o: list_test.cpp
$(CC) $(CFLAGS) list_test.cpp
clean:
rm *.o ./test -f
I build it in 64-bit linux. there is an illegal instruction when it run in 32-bit linux with pentinum(R) III cpu.
the illegal instruction is as follow:
(gdb) disas 0x0804f77a 0x0804f77b
Dump of assembler code from 0x804f77a to 0x804f77b:
0x0804f77a <std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::char_type*, std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::__size_type, std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::__size_type)+138>: movq %xmm0,0xc(%esp)
End of assembler dump.
How to resolve this problem?