linux python转elf,为什么Python生成的ELF与原始源代码相比很大?

我不禁要问,为什么Python生成的ELF与原始源代码相比会很大。让我们看看最简单的代码helloworld。在user@linux:~/Python$ cat hello.py

print('Hello, World!')

user@linux:~/Python$

使用pyinstaller转换为ELF

^{pr2}$

新ELF格式user@linux:~/Python/dist$ ./hello

Hello, World!

user@linux:~/Python/dist$

user@linux:~/Python$ ls -lh hello.py

-rw-rw-r-- 1 user user 23 Dis 27 21:43 hello.py

user@linux:~/Python$

user@linux:~/Python/dist$ ls -lh hello

-rwxr-xr-x 1 user user 5.3M Dis 27 21:48 hello

user@linux:~/Python/dist$

如你所见,原始代码只有23个字节,而ELF要大得多。。。530万!!!在

让我们看另一个使用C的例子user@linux:~/C$ cat hello.c

#include

int main()

{

printf("Hello C World\n");

}

user@linux:~/C$

user@linux:~/C$ gcc hello.c -o helloC

user@linux:~/C$

user@linux:~/C$ ls -l helloC

-rwxrwxr-x 1 user user 8304 Dis 27 21:53 helloC

user@linux:~/C$

user@linux:~/C$ ./helloC

Hello C World

user@linux:~/C$

user@linux:~/C$ ls -l hello.c

-rw-rw-r-- 1 user user 65 Dis 27 21:52 hello.c

user@linux:~/C$

user@linux:~/C$ ls -lh helloC

-rwxrwxr-x 1 user user 8.2K Dis 27 21:53 helloC

user@linux:~/C$

比较Python code size = 27 bytes

Python ELF size = 5.3M

C code size = 65 bytes

C ELF size = 8.2K

有没有办法让尺寸变小?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值