先来看看gcc官方手册吧
These ‘-m’ switches are supported in addition to the above on x86-64 processors in 64-bit
environments.
-m32
-m64
-mx32
-m16
-miamcu Generate code for a 16-bit, 32-bit or 64-bit environment.
The ‘-m32’ option
sets int, long, and pointer types to 32 bits, and generates code that runs on
any i386 system.
The ‘-m64’ option sets int to 32 bits and long and pointer types to 64 bits, and
generates code for the x86-64 architecture. For Darwin only the ‘-m64’ option
also turns off the ‘-fno-pic’ and ‘-mdynamic-no-pic’ options.
The ‘-mx32’ option sets int, long, and pointer types to 32 bits, and generates
code for the x86-64 architecture.
The ‘-m16’ option is the same as ‘-m32’, except for that it outputs the
.code16gcc assembly directive at the beginning of the assembly output so
that the binary can run in 16-bit mode.
The ‘-miamcu’ option generates code which conforms to Intel MCU psABI. It
requires the ‘-m32’ option to be turned on.
执行编译的程序需要安装32位lib:
$sudo apt-get install lib32ncurses5 lib32z1
编译时需安装multilib:
sudo apt-get install gcc-multilib g++-multilib
在我的电脑上-m32能够运行,-mx32需要内核支持,在编译内核时有mx32的选项,CentOS7内核和GCC都没开启支持mx32,Debian9内核没开启,但gcc支持
下面是elf读取出来的信息:
-mx32:在64位系统中,指针和long都是64位的(此处只讨论linux,Windows不是),因此程序可以使用的内存大小可以远远大于4GiB。但是很多程序并不需要4GiB以上内存,这样内存地址只使用了低4字节造成一定的浪费,而且对于x86的CPU(准确的说是amd64或x86-64,不含IA64),64位数据运算速度远远慢于32位数据,指针和long是32位既浪费了高4字节的空间,又拖累了运行速度,于是有人搞出了指针和long是32位的mx32:你同样可以使用INT64这样的8字节数据,但编译出的程序体积更小,运行速度更快。